Fix repo check in combination with execution dir
This commit is contained in:
parent
a7310f94b5
commit
d711d5484e
7 changed files with 48 additions and 26 deletions
|
@ -17,7 +17,7 @@
|
||||||
(defn-spec backup-files-command ::cd/commands
|
(defn-spec backup-files-command ::cd/commands
|
||||||
[config ::backup-file-config]
|
[config ::backup-file-config]
|
||||||
(let [{:keys [files]} config]
|
(let [{:keys [files]} config]
|
||||||
[(rd/repo-command config (into ["backup"] files))]))
|
[(rd/repo-command config (into ["backup"] files) false)]))
|
||||||
|
|
||||||
(defn-spec backup-role-command ::cd/commands
|
(defn-spec backup-role-command ::cd/commands
|
||||||
[config ::pd/pg-role-dump-config]
|
[config ::pd/pg-role-dump-config]
|
||||||
|
|
|
@ -28,4 +28,4 @@
|
||||||
(let [{:keys [dry-run debug]} config]
|
(let [{:keys [dry-run debug]} config]
|
||||||
(doseq [c commands]
|
(doseq [c commands]
|
||||||
(when-not dry-run
|
(when-not dry-run
|
||||||
(execute-single! c config)))))
|
(apply t/shell c)))))
|
|
@ -50,7 +50,7 @@
|
||||||
"--no-password"]
|
"--no-password"]
|
||||||
command
|
command
|
||||||
["|" "grep" pg-role-prefix "|"]
|
["|" "grep" pg-role-prefix "|"]
|
||||||
(rd/repo-command config ["backup" "--stdin"])))))
|
(rd/repo-command config ["backup" "--stdin"] false)))))
|
||||||
|
|
||||||
(defn-spec pgdump-command ::cd/command
|
(defn-spec pgdump-command ::cd/command
|
||||||
[config ::pg-db-dump-config
|
[config ::pg-db-dump-config
|
||||||
|
@ -63,7 +63,7 @@
|
||||||
"--no-password"]
|
"--no-password"]
|
||||||
command
|
command
|
||||||
["|"]
|
["|"]
|
||||||
(rd/repo-command config ["backup" "--stdin"])))))
|
(rd/repo-command config ["backup" "--stdin"] false)))))
|
||||||
|
|
||||||
(defn-spec pgpass string?
|
(defn-spec pgpass string?
|
||||||
[config ::pg-config]
|
[config ::pg-config]
|
||||||
|
|
|
@ -38,7 +38,6 @@
|
||||||
:default :error))))))
|
:default :error))))))
|
||||||
|
|
||||||
(defn-spec use-new-password? boolean?
|
(defn-spec use-new-password? boolean?
|
||||||
"deprecated"
|
|
||||||
[restic-config ::restic-config]
|
[restic-config ::restic-config]
|
||||||
(if (contains? restic-config :new-password-file)
|
(if (contains? restic-config :new-password-file)
|
||||||
(= :initialized (check (merge restic-config {:password-file (:new-password-file restic-config)})))
|
(= :initialized (check (merge restic-config {:password-file (:new-password-file restic-config)})))
|
||||||
|
|
|
@ -26,15 +26,20 @@
|
||||||
|
|
||||||
(defn-spec repo-command ::cd/command
|
(defn-spec repo-command ::cd/command
|
||||||
[config ::restic-config
|
[config ::restic-config
|
||||||
command ::cd/command]
|
command ::cd/command
|
||||||
|
read-error-stream boolean?]
|
||||||
(let [{:keys [certificate-file password-file execution-directory
|
(let [{:keys [certificate-file password-file execution-directory
|
||||||
restic-repository backup-path]} config]
|
restic-repository backup-path]} config
|
||||||
|
shell-option (if read-error-stream {:err :string} {})]
|
||||||
(into
|
(into
|
||||||
[]
|
[]
|
||||||
(concat
|
(concat
|
||||||
(if (some? execution-directory)
|
(cond
|
||||||
[{:dir execution-directory}]
|
(some? execution-directory)
|
||||||
[])
|
[(merge shell-option {:dir execution-directory})]
|
||||||
|
read-error-stream
|
||||||
|
[shell-option]
|
||||||
|
:default [])
|
||||||
["restic" "-r" (str restic-repository "/" backup-path) "-v"]
|
["restic" "-r" (str restic-repository "/" backup-path) "-v"]
|
||||||
(cond
|
(cond
|
||||||
(some? certificate-file)
|
(some? certificate-file)
|
||||||
|
@ -47,19 +52,19 @@
|
||||||
|
|
||||||
(defn-spec check-repo-command ::cd/commands
|
(defn-spec check-repo-command ::cd/commands
|
||||||
[config ::restic-config]
|
[config ::restic-config]
|
||||||
[(repo-command config ["check"])])
|
[(repo-command config ["check"] true)])
|
||||||
|
|
||||||
(defn-spec init-repo-command ::cd/commands
|
(defn-spec init-repo-command ::cd/commands
|
||||||
[config ::restic-config]
|
[config ::restic-config]
|
||||||
[(repo-command config ["init"])])
|
[(repo-command config ["init"] false)])
|
||||||
|
|
||||||
(defn-spec unlock-repo-command ::cd/commands
|
(defn-spec unlock-repo-command ::cd/commands
|
||||||
[config ::restic-config]
|
[config ::restic-config]
|
||||||
[(repo-command config ["--cleanup-cache" "unlock"])])
|
[(repo-command config ["--cleanup-cache" "unlock"] false)])
|
||||||
|
|
||||||
(defn-spec list-snapshot-command ::cd/commands
|
(defn-spec list-snapshot-command ::cd/commands
|
||||||
[config ::restic-config]
|
[config ::restic-config]
|
||||||
[(repo-command config ["snapshots"])])
|
[(repo-command config ["snapshots"] false)])
|
||||||
|
|
||||||
(defn-spec forget-command ::cd/commands
|
(defn-spec forget-command ::cd/commands
|
||||||
[config ::restic-config]
|
[config ::restic-config]
|
||||||
|
@ -67,19 +72,19 @@
|
||||||
[(repo-command config ["forget" "--group-by" "''"
|
[(repo-command config ["forget" "--group-by" "''"
|
||||||
"--keep-last" "1"
|
"--keep-last" "1"
|
||||||
"--keep-daily" (str days-to-keep)
|
"--keep-daily" (str days-to-keep)
|
||||||
"--keep-monthly" (str months-to-keep) "--prune"])]))
|
"--keep-monthly" (str months-to-keep) "--prune"] false)]))
|
||||||
|
|
||||||
(defn-spec change-password-command ::cd/command
|
(defn-spec change-password-command ::cd/command
|
||||||
[config ::restic-config]
|
[config ::restic-config]
|
||||||
(if (contains? config :new-password-file)
|
(if (contains? config :new-password-file)
|
||||||
(let [{:keys [new-password-file]} config]
|
(let [{:keys [new-password-file]} config]
|
||||||
[(repo-command config ["--new-password-file" new-password-file
|
[(repo-command config ["--new-password-file" new-password-file
|
||||||
"key" "passwd"])])
|
"key" "passwd"] false)])
|
||||||
(throw (Exception. "change-password: new password required"))))
|
(throw (Exception. "change-password: new password required"))))
|
||||||
|
|
||||||
(defn-spec parse-check-error ::check-error
|
(defn-spec parse-check-error ::check-error
|
||||||
[error string?]
|
[error string?]
|
||||||
(cond
|
(cond
|
||||||
(clojure.string/includes? error "Fatal: unable to open config file") :not-initialized
|
(clojure.string/includes? error "Fatal: unable to open config file") :not-initialized
|
||||||
(clojure.string/includes? error "Fatal: wrong password or no key found") :wrong-password
|
(clojure.string/includes? error "Fatal: wrong password or no key found") :wrong-password
|
||||||
(clojure.string/includes? error "Resolving password failed") :no-password
|
(clojure.string/includes? error "Resolving password failed") :no-password
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
[config ::restore-file-config]
|
[config ::restore-file-config]
|
||||||
(let [{:keys [restore-target-directory snapshot-id]} config]
|
(let [{:keys [restore-target-directory snapshot-id]} config]
|
||||||
[["rm" "-rf" restore-target-directory]
|
[["rm" "-rf" restore-target-directory]
|
||||||
(rd/repo-command config ["restore" snapshot-id "--target" restore-target-directory])]))
|
(rd/repo-command config ["restore" snapshot-id "--target" restore-target-directory] false)]))
|
||||||
|
|
||||||
(defn-spec restore-db-command ::cd/commands
|
(defn-spec restore-db-command ::cd/commands
|
||||||
[config ::restore-db-config]
|
[config ::restore-db-config]
|
||||||
|
@ -35,7 +35,7 @@
|
||||||
(into
|
(into
|
||||||
[]
|
[]
|
||||||
(concat
|
(concat
|
||||||
(rd/repo-command config ["dump" snapshot-id "stdin"])
|
(rd/repo-command config ["dump" snapshot-id "stdin"] false)
|
||||||
["|"]
|
["|"]
|
||||||
(pd/psql-command config []))))]]))
|
(pd/psql-command config []))))]]))
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
(st/instrument `cut/forget-command)
|
(st/instrument `cut/forget-command)
|
||||||
|
|
||||||
(deftest should-calculate-repo-command
|
(deftest should-calculate-repo-command
|
||||||
(is (= [{:dir "dir"}
|
(is (= [{:dir "dir" :err :string}
|
||||||
"restic"
|
"restic"
|
||||||
"-r"
|
"-r"
|
||||||
"repo/dir"
|
"repo/dir"
|
||||||
|
@ -26,27 +26,45 @@
|
||||||
:backup-path "dir"
|
:backup-path "dir"
|
||||||
:days-to-keep 39
|
:days-to-keep 39
|
||||||
:months-to-keep 3}
|
:months-to-keep 3}
|
||||||
["backup" "file1" "file2"])))
|
["backup" "file1" "file2"]
|
||||||
(is (= ["restic" "-r" "repo/dir" "-v" "--cacert" "ca" "snapshots"]
|
true)))
|
||||||
|
(is (= [{:dir "dir"}
|
||||||
|
"restic"
|
||||||
|
"-r"
|
||||||
|
"repo/dir"
|
||||||
|
"-v"
|
||||||
|
"--cacert"
|
||||||
|
"ca"
|
||||||
|
"backup"
|
||||||
|
"file1"
|
||||||
|
"file2"]
|
||||||
|
(cut/repo-command {:certificate-file "ca"
|
||||||
|
:execution-directory "dir"
|
||||||
|
:restic-repository "repo"
|
||||||
|
:backup-path "dir"
|
||||||
|
:days-to-keep 39
|
||||||
|
:months-to-keep 3}
|
||||||
|
["backup" "file1" "file2"] false)))
|
||||||
|
(is (= [{:err :string} "restic" "-r" "repo/dir" "-v" "--cacert" "ca" "snapshots"]
|
||||||
(cut/repo-command {:certificate-file "ca"
|
(cut/repo-command {:certificate-file "ca"
|
||||||
:restic-repository "repo"
|
:restic-repository "repo"
|
||||||
:backup-path "dir"
|
:backup-path "dir"
|
||||||
:days-to-keep 39
|
:days-to-keep 39
|
||||||
:months-to-keep 3}
|
:months-to-keep 3}
|
||||||
["snapshots"])))
|
["snapshots"] true)))
|
||||||
(is (= ["restic" "-r" "repo/dir" "-v" "--password-file" "password" "snapshots"]
|
(is (= ["restic" "-r" "repo/dir" "-v" "--password-file" "password" "snapshots"]
|
||||||
(cut/repo-command {:password-file "password"
|
(cut/repo-command {:password-file "password"
|
||||||
:restic-repository "repo"
|
:restic-repository "repo"
|
||||||
:backup-path "dir"
|
:backup-path "dir"
|
||||||
:days-to-keep 39
|
:days-to-keep 39
|
||||||
:months-to-keep 3}
|
:months-to-keep 3}
|
||||||
["snapshots"])))
|
["snapshots"] false)))
|
||||||
(is (= ["restic" "-r" "repo/dir" "-v" "snapshots"]
|
(is (= ["restic" "-r" "repo/dir" "-v" "snapshots"]
|
||||||
(cut/repo-command {:restic-repository "repo"
|
(cut/repo-command {:restic-repository "repo"
|
||||||
:backup-path "dir"
|
:backup-path "dir"
|
||||||
:days-to-keep 39
|
:days-to-keep 39
|
||||||
:months-to-keep 3}
|
:months-to-keep 3}
|
||||||
["snapshots"]))))
|
["snapshots"] false))))
|
||||||
|
|
||||||
(deftest should-calculate-init-repo-command
|
(deftest should-calculate-init-repo-command
|
||||||
(is (= [["restic" "-r" "repo/dir" "-v" "init"]]
|
(is (= [["restic" "-r" "repo/dir" "-v" "init"]]
|
||||||
|
|
Loading…
Reference in a new issue