diff --git a/infrastructure/backup/image/Dockerfile b/infrastructure/backup/image/Dockerfile index 2c60369..47e2d41 100644 --- a/infrastructure/backup/image/Dockerfile +++ b/infrastructure/backup/image/Dockerfile @@ -1,5 +1,4 @@ FROM domaindrivenarchitecture/dda-backup:latest -# Prepare Entrypoint Script ADD resources /tmp RUN /tmp/install.bb diff --git a/infrastructure/backup/test/Dockerfile b/infrastructure/backup/test/Dockerfile index c67e37c..91b7719 100644 --- a/infrastructure/backup/test/Dockerfile +++ b/infrastructure/backup/test/Dockerfile @@ -1,7 +1,4 @@ FROM c4k-forgejo-backup:latest -# install it -RUN apt update && apt install -qqy openjdk-17-jre-headless ADD resources /tmp/ -RUN rm -rf /root/.m2 -RUN /tmp/install-test.bb +RUN ENV_PASSWORD=env-password FILE_PASSWORD_FILE=/tmp/file_password /tmp/test.bb diff --git a/infrastructure/backup/test/resources/bb.edn b/infrastructure/backup/test/resources/bb.edn index acb67e5..1a7297a 100644 --- a/infrastructure/backup/test/resources/bb.edn +++ b/infrastructure/backup/test/resources/bb.edn @@ -1,4 +1,3 @@ {:deps {org.clojure/spec.alpha {:mvn/version "0.4.233"} orchestra/orchestra {:mvn/version "2021.01.01-1"} - org.domaindrivenarchitecture/dda-backup {:mvn/version "0.1.1-SNAPSHOT"}}} - + org.domaindrivenarchitecture/dda-backup {:local/root "/usr/local/lib/dda-backup"}}} diff --git a/infrastructure/backup/test/resources/install-test.bb b/infrastructure/backup/test/resources/install-test.bb deleted file mode 100755 index 357e4d6..0000000 --- a/infrastructure/backup/test/resources/install-test.bb +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env bb - -(require '[babashka.tasks :as tasks]) - -(defn curl-and-check! - [filename artifact-url sha256-url] - (let [filepath (str "/tmp/" filename)] - (tasks/shell "curl" "-SsLo" filepath artifact-url) - (tasks/shell "curl" "-SsLo" "/tmp/checksum" sha256-url) - (tasks/shell "bash" "-c" (str "echo \" " filepath "\"|tee -a /tmp/checksum")) - ;(tasks/shell "sha256sum" "-c" "--status" "/tmp/checksum") - )) - -(defn tar-install! - [filename binname] - (let [filepath (str "/tmp/" filename)] - (tasks/shell "tar" "-C" "/tmp" "-xzf" filepath) - (tasks/shell "install" "-m" "0700" "-o" "root" "-g" "root" (str "/tmp/" binname) "/usr/local/bin/"))) - -(defn install! - [filename] - (tasks/shell "install" "-m" "0700" "-o" "root" "-g" "root" (str "/tmp/" filename) "/usr/local/bin/")) - -(tasks/shell "bb" "/tmp/test.bb") -(curl-and-check! - "provs-syspec.jar" - "https://repo.prod.meissa.de/attachments/0a1da41e-aa5b-4a3e-a3b1-215cf2d5b021" - "https://repo.prod.meissa.de/attachments/f227cf65-cb0f-46a7-a6cd-28f46917412a") -(install! "provs-syspec.jar") -(tasks/shell "apt" "update") -(tasks/shell "apt" "install" "-qqy" "openjdk-17-jre-headless") -(tasks/shell "java" "-jar" "/usr/local/bin/provs-syspec.jar" "local" "-c" "/tmp/spec.yml" ) diff --git a/infrastructure/backup/test/resources/spec.yml b/infrastructure/backup/test/resources/spec.yml deleted file mode 100644 index 19d0edf..0000000 --- a/infrastructure/backup/test/resources/spec.yml +++ /dev/null @@ -1,7 +0,0 @@ -package: - - name: "restic" - -command: - - command: "bb -h" - - command: "/tmp/test.bb" - \ No newline at end of file diff --git a/infrastructure/backup/test/resources/test.bb b/infrastructure/backup/test/resources/test.bb index ae50704..5ac0474 100755 --- a/infrastructure/backup/test/resources/test.bb +++ b/infrastructure/backup/test/resources/test.bb @@ -1,31 +1,62 @@ #!/usr/bin/env bb (require '[babashka.tasks :as tasks] - '[dda.backup.management :as mgm] + '[dda.backup.core :as bc] + '[dda.backup.restic :as rc] + '[dda.backup.postgresql :as pg] '[dda.backup.backup :as bak] '[dda.backup.restore :as rs]) +(def restic-repo {:password-file "restic-pwd" + :restic-repository "restic-repo"}) + +(def file-config (merge restic-repo {:backup-path "files" + :files ["test-backup"] + :restore-target-directory "test-restore"})) + + +(def db-config (merge restic-repo {:backup-path "db" + :pg-db "mydb" + :pg-user "user" + :pg-password "password"})) + +(def dry-run {:dry-run true :debug true}) + +(defn prepare! + [] + (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") + (tasks/shell "mkdir" "-p" "test-restore") + (pg/create-pg-pass! db-config)) + (defn restic-repo-init! [] - (spit "restic-pwd" "ThePassword") - (mgm/init! {:password-file "restic-pwd" - :restic-repository "restic-repo"})) + (rc/init! file-config) + (rc/init! (merge db-config dry-run))) (defn restic-backup! [] - (tasks/shell "mkdir" "-p" "test-backup") - (spit "test-backup/file" "I was here") - (bak/backup! {:password-file "restic-pwd" - :restic-repository "restic-repo" - :files ["test-backup"]})) + (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! [] - (tasks/shell "mkdir" "-p" "test-restore") - (rs/restore! {:password-file "restic-pwd" - :restic-repository "restic-repo" - :target-directory "test-restore"})) + (rs/restore-file! file-config) + (pg/drop-create-db! (merge db-config dry-run)) + (rs/restore-db! (merge db-config dry-run))) +(prepare!) (restic-repo-init!) (restic-backup!) +(list-snapshots!) (restic-restore!)