test more stright forward

This commit is contained in:
Michael Jerger 2024-08-23 13:25:13 +02:00
parent 23ec2c6106
commit 2f46d330e1
6 changed files with 46 additions and 59 deletions

View file

@ -1,5 +1,4 @@
FROM domaindrivenarchitecture/dda-backup:latest FROM domaindrivenarchitecture/dda-backup:latest
# Prepare Entrypoint Script
ADD resources /tmp ADD resources /tmp
RUN /tmp/install.bb RUN /tmp/install.bb

View file

@ -1,7 +1,4 @@
FROM c4k-forgejo-backup:latest FROM c4k-forgejo-backup:latest
# install it
RUN apt update && apt install -qqy openjdk-17-jre-headless
ADD resources /tmp/ ADD resources /tmp/
RUN rm -rf /root/.m2 RUN ENV_PASSWORD=env-password FILE_PASSWORD_FILE=/tmp/file_password /tmp/test.bb
RUN /tmp/install-test.bb

View file

@ -1,4 +1,3 @@
{:deps {org.clojure/spec.alpha {:mvn/version "0.4.233"} {:deps {org.clojure/spec.alpha {:mvn/version "0.4.233"}
orchestra/orchestra {:mvn/version "2021.01.01-1"} 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"}}}

View file

@ -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" )

View file

@ -1,7 +0,0 @@
package:
- name: "restic"
command:
- command: "bb -h"
- command: "/tmp/test.bb"

View file

@ -1,31 +1,62 @@
#!/usr/bin/env bb #!/usr/bin/env bb
(require '[babashka.tasks :as tasks] (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.backup :as bak]
'[dda.backup.restore :as rs]) '[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! (defn restic-repo-init!
[] []
(spit "restic-pwd" "ThePassword") (rc/init! file-config)
(mgm/init! {:password-file "restic-pwd" (rc/init! (merge db-config dry-run)))
:restic-repository "restic-repo"}))
(defn restic-backup! (defn restic-backup!
[] []
(tasks/shell "mkdir" "-p" "test-backup") (bak/backup-file! file-config)
(spit "test-backup/file" "I was here") (bak/backup-db! (merge db-config dry-run)))
(bak/backup! {:password-file "restic-pwd"
:restic-repository "restic-repo" (defn list-snapshots!
:files ["test-backup"]})) []
(rc/list-snapshots! file-config)
(rc/list-snapshots! (merge db-config dry-run)))
(defn restic-restore! (defn restic-restore!
[] []
(tasks/shell "mkdir" "-p" "test-restore") (rs/restore-file! file-config)
(rs/restore! {:password-file "restic-pwd" (pg/drop-create-db! (merge db-config dry-run))
:restic-repository "restic-repo" (rs/restore-db! (merge db-config dry-run)))
:target-directory "test-restore"}))
(prepare!)
(restic-repo-init!) (restic-repo-init!)
(restic-backup!) (restic-backup!)
(list-snapshots!)
(restic-restore!) (restic-restore!)