Fix repo check in combination with execution dir

This commit is contained in:
Michael Jerger 2024-12-28 15:58:17 +01:00
parent a7310f94b5
commit d711d5484e
7 changed files with 48 additions and 26 deletions

View file

@ -17,7 +17,7 @@
(defn-spec backup-files-command ::cd/commands
[config ::backup-file-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
[config ::pd/pg-role-dump-config]

View file

@ -28,4 +28,4 @@
(let [{:keys [dry-run debug]} config]
(doseq [c commands]
(when-not dry-run
(execute-single! c config)))))
(apply t/shell c)))))

View file

@ -50,7 +50,7 @@
"--no-password"]
command
["|" "grep" pg-role-prefix "|"]
(rd/repo-command config ["backup" "--stdin"])))))
(rd/repo-command config ["backup" "--stdin"] false)))))
(defn-spec pgdump-command ::cd/command
[config ::pg-db-dump-config
@ -63,7 +63,7 @@
"--no-password"]
command
["|"]
(rd/repo-command config ["backup" "--stdin"])))))
(rd/repo-command config ["backup" "--stdin"] false)))))
(defn-spec pgpass string?
[config ::pg-config]

View file

@ -38,7 +38,6 @@
:default :error))))))
(defn-spec use-new-password? boolean?
"deprecated"
[restic-config ::restic-config]
(if (contains? restic-config :new-password-file)
(= :initialized (check (merge restic-config {:password-file (:new-password-file restic-config)})))

View file

@ -26,15 +26,20 @@
(defn-spec repo-command ::cd/command
[config ::restic-config
command ::cd/command]
command ::cd/command
read-error-stream boolean?]
(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
[]
(concat
(if (some? execution-directory)
[{:dir execution-directory}]
[])
(cond
(some? execution-directory)
[(merge shell-option {:dir execution-directory})]
read-error-stream
[shell-option]
:default [])
["restic" "-r" (str restic-repository "/" backup-path) "-v"]
(cond
(some? certificate-file)
@ -47,19 +52,19 @@
(defn-spec check-repo-command ::cd/commands
[config ::restic-config]
[(repo-command config ["check"])])
[(repo-command config ["check"] true)])
(defn-spec init-repo-command ::cd/commands
[config ::restic-config]
[(repo-command config ["init"])])
[(repo-command config ["init"] false)])
(defn-spec unlock-repo-command ::cd/commands
[config ::restic-config]
[(repo-command config ["--cleanup-cache" "unlock"])])
[(repo-command config ["--cleanup-cache" "unlock"] false)])
(defn-spec list-snapshot-command ::cd/commands
[config ::restic-config]
[(repo-command config ["snapshots"])])
[(repo-command config ["snapshots"] false)])
(defn-spec forget-command ::cd/commands
[config ::restic-config]
@ -67,19 +72,19 @@
[(repo-command config ["forget" "--group-by" "''"
"--keep-last" "1"
"--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
[config ::restic-config]
(if (contains? config :new-password-file)
(let [{:keys [new-password-file]} config]
[(repo-command config ["--new-password-file" new-password-file
"key" "passwd"])])
[(repo-command config ["--new-password-file" new-password-file
"key" "passwd"] false)])
(throw (Exception. "change-password: new password required"))))
(defn-spec parse-check-error ::check-error
[error string?]
(cond
(cond
(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 "Resolving password failed") :no-password

View file

@ -24,7 +24,7 @@
[config ::restore-file-config]
(let [{:keys [restore-target-directory snapshot-id]} config]
[["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
[config ::restore-db-config]
@ -35,7 +35,7 @@
(into
[]
(concat
(rd/repo-command config ["dump" snapshot-id "stdin"])
(rd/repo-command config ["dump" snapshot-id "stdin"] false)
["|"]
(pd/psql-command config []))))]]))

View file

@ -10,7 +10,7 @@
(st/instrument `cut/forget-command)
(deftest should-calculate-repo-command
(is (= [{:dir "dir"}
(is (= [{:dir "dir" :err :string}
"restic"
"-r"
"repo/dir"
@ -26,27 +26,45 @@
:backup-path "dir"
:days-to-keep 39
:months-to-keep 3}
["backup" "file1" "file2"])))
(is (= ["restic" "-r" "repo/dir" "-v" "--cacert" "ca" "snapshots"]
["backup" "file1" "file2"]
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"
:restic-repository "repo"
:backup-path "dir"
:days-to-keep 39
:months-to-keep 3}
["snapshots"])))
["snapshots"] true)))
(is (= ["restic" "-r" "repo/dir" "-v" "--password-file" "password" "snapshots"]
(cut/repo-command {:password-file "password"
:restic-repository "repo"
:backup-path "dir"
:days-to-keep 39
:months-to-keep 3}
["snapshots"])))
["snapshots"] false)))
(is (= ["restic" "-r" "repo/dir" "-v" "snapshots"]
(cut/repo-command {:restic-repository "repo"
:backup-path "dir"
:days-to-keep 39
:months-to-keep 3}
["snapshots"]))))
["snapshots"] false))))
(deftest should-calculate-init-repo-command
(is (= [["restic" "-r" "repo/dir" "-v" "init"]]