diff --git a/infrastructure/backup/image/Dockerfile b/infrastructure/backup/image/Dockerfile index 6952f39..92da715 100644 --- a/infrastructure/backup/image/Dockerfile +++ b/infrastructure/backup/image/Dockerfile @@ -2,5 +2,5 @@ FROM ubuntu:24.04 # install it ADD resources /tmp/ -RUN /tmp/install.sh ADD local/ /usr/local/lib/dda-backup +RUN /tmp/install.sh diff --git a/infrastructure/backup/image/resources/bb.edn b/infrastructure/backup/image/resources/bb.edn new file mode 100644 index 0000000..1a7297a --- /dev/null +++ b/infrastructure/backup/image/resources/bb.edn @@ -0,0 +1,3 @@ +{:deps {org.clojure/spec.alpha {:mvn/version "0.4.233"} + orchestra/orchestra {:mvn/version "2021.01.01-1"} + org.domaindrivenarchitecture/dda-backup {:local/root "/usr/local/lib/dda-backup"}}} diff --git a/infrastructure/backup/image/resources/init.bb b/infrastructure/backup/image/resources/init.bb new file mode 100755 index 0000000..af0856c --- /dev/null +++ b/infrastructure/backup/image/resources/init.bb @@ -0,0 +1,3 @@ +#!/usr/bin/env bb + +(println "initialized") diff --git a/infrastructure/backup/image/resources/install.sh b/infrastructure/backup/image/resources/install.sh index f51ee2e..b03c4cd 100755 --- a/infrastructure/backup/image/resources/install.sh +++ b/infrastructure/backup/image/resources/install.sh @@ -23,7 +23,8 @@ function main() { } > /dev/null update-ca-certificates - + /tmp/init.bb + cleanupDocker } diff --git a/infrastructure/backup/test/Dockerfile b/infrastructure/backup/test/Dockerfile index 24d00ac..0a66d92 100644 --- a/infrastructure/backup/test/Dockerfile +++ b/infrastructure/backup/test/Dockerfile @@ -3,4 +3,4 @@ FROM dda-backup:latest # install it #ADD local/ /usr/local/lib/dda-backup ADD resources /tmp/ -RUN ENV_PASSWORD=env-password /tmp/test.bb +RUN ENV_PASSWORD=env-password FILE_PASSWORD_FILE=/tmp/file_password /tmp/test.bb diff --git a/infrastructure/backup/test/resources/test.bb b/infrastructure/backup/test/resources/test.bb index b7f4754..7883125 100755 --- a/infrastructure/backup/test/resources/test.bb +++ b/infrastructure/backup/test/resources/test.bb @@ -24,9 +24,9 @@ (defn prepare! [] - (spit "file_password" "file-password") - (println (bc/env-or-file "file_password")) - (println (bc/env-or-file "env_password")) + (spit "/tmp/file_password" "file-password") + (println (bc/env-or-file "FILE_PASSWORD")) + (println (bc/env-or-file "ENV_PASSWORD")) (spit "restic-pwd" "ThePassword") (tasks/shell "mkdir" "-p" "test-backup") (spit "test-backup/file" "I was here") @@ -43,6 +43,12 @@ (bak/backup-file! file-config) (bak/backup-db! (merge db-config dry-run))) +(defn list-snapshots! + [] + (rc/list-snapshots! file-config) + (rc/list-snapshots! (merge db-config dry-run))) + + (defn restic-restore! [] (rs/restore-file! file-config) @@ -52,4 +58,5 @@ (prepare!) (restic-repo-init!) (restic-backup!) +(list-snapshots!) (restic-restore!) diff --git a/src/dda/backup/core.clj b/src/dda/backup/core.clj index 9eb552a..f21a3d3 100644 --- a/src/dda/backup/core.clj +++ b/src/dda/backup/core.clj @@ -15,9 +15,10 @@ (defn-spec env-or-file string? [name string?] - (let [name-upper (st/upper-case name) - name-lower (st/lower-case name) - from-env (System/getenv name-upper)] - (if (some? from-env) - from-env - (slurp name-lower)))) + (let [from-env (System/getenv name) + name-from-file (System/getenv (str name "_FILE"))] + (cond + (some? from-env) from-env + (some? name-from-file) (slurp name-from-file) + :else (throw ( RuntimeException. + (str "Environment: [" name "," name-from-file "] was missing." )))))) diff --git a/src/dda/backup/restic.clj b/src/dda/backup/restic.clj index 5be66a4..419a7ce 100644 --- a/src/dda/backup/restic.clj +++ b/src/dda/backup/restic.clj @@ -42,4 +42,9 @@ (defn-spec forget! nil? [restic-config ::restic-config] (let [config-w-defaults (merge core/default restic-config)] - (i/execute! (domain/forget-command config-w-defaults) config-w-defaults))) \ No newline at end of file + (i/execute! (domain/forget-command config-w-defaults) config-w-defaults))) + +(defn-spec list-snapshots! nil? + [restic-config ::restic-config] + (let [config-w-defaults (merge core/default restic-config)] + (i/execute! (domain/list-snapshot-command config-w-defaults) config-w-defaults)))