test the backup
This commit is contained in:
parent
90260b3ea4
commit
2416e26f70
6 changed files with 81 additions and 3 deletions
|
@ -3,6 +3,8 @@
|
||||||
set -Eexo pipefail
|
set -Eexo pipefail
|
||||||
|
|
||||||
function main() {
|
function main() {
|
||||||
|
local db_snapshot_id="${1:-latest}"
|
||||||
|
local file_snapshot_id="${2:-latest}"
|
||||||
|
|
||||||
file_env AWS_ACCESS_KEY_ID
|
file_env AWS_ACCESS_KEY_ID
|
||||||
file_env AWS_SECRET_ACCESS_KEY
|
file_env AWS_SECRET_ACCESS_KEY
|
||||||
|
@ -12,7 +14,7 @@ function main() {
|
||||||
file_env POSTGRES_USER
|
file_env POSTGRES_USER
|
||||||
|
|
||||||
# Restore latest snapshot into /var/backups/restore
|
# Restore latest snapshot into /var/backups/restore
|
||||||
restore-directory '/var/backups/restore'
|
restore-directory '/var/backups/restore' ${file_snapshot_id}
|
||||||
|
|
||||||
rm -rf /var/backups/gitea/*
|
rm -rf /var/backups/gitea/*
|
||||||
rm -rf /var/backups/git/repositories/*
|
rm -rf /var/backups/git/repositories/*
|
||||||
|
@ -27,11 +29,11 @@ function main() {
|
||||||
|
|
||||||
# Restore db
|
# Restore db
|
||||||
drop-create-db
|
drop-create-db
|
||||||
restore-db
|
restore-db ${db_snapshot_id}
|
||||||
}
|
}
|
||||||
|
|
||||||
source /usr/local/lib/functions.sh
|
source /usr/local/lib/functions.sh
|
||||||
source /usr/local/lib/pg-functions.sh
|
source /usr/local/lib/pg-functions.sh
|
||||||
source /usr/local/lib/file-functions.sh
|
source /usr/local/lib/file-functions.sh
|
||||||
|
|
||||||
main
|
main "$@"
|
||||||
|
|
7
infrastructure/backup/test/Dockerfile
Normal file
7
infrastructure/backup/test/Dockerfile
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
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
|
4
infrastructure/backup/test/resources/bb.edn
Normal file
4
infrastructure/backup/test/resources/bb.edn
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
{: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"}}}
|
||||||
|
|
32
infrastructure/backup/test/resources/install-test.bb
Executable file
32
infrastructure/backup/test/resources/install-test.bb
Executable file
|
@ -0,0 +1,32 @@
|
||||||
|
#!/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" )
|
7
infrastructure/backup/test/resources/spec.yml
Normal file
7
infrastructure/backup/test/resources/spec.yml
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
package:
|
||||||
|
- name: "restic"
|
||||||
|
|
||||||
|
command:
|
||||||
|
- command: "bb -h"
|
||||||
|
- command: "/tmp/test.bb"
|
||||||
|
|
26
infrastructure/backup/test/resources/test.bb
Executable file
26
infrastructure/backup/test/resources/test.bb
Executable file
|
@ -0,0 +1,26 @@
|
||||||
|
#!/usr/bin/env bb
|
||||||
|
|
||||||
|
(require '[babashka.tasks :as tasks]
|
||||||
|
'[dda.backup.management :as mgm])
|
||||||
|
|
||||||
|
(defn restic-repo-init!
|
||||||
|
[]
|
||||||
|
(spit "restic-pwd" "ThePassword")
|
||||||
|
(mgm/init! {:password-file "restic-pwd"
|
||||||
|
:restic-repository "restic-repo"}))
|
||||||
|
|
||||||
|
(defn restic-backup!
|
||||||
|
[]
|
||||||
|
(tasks/shell "mkdir" "-p" "test-backup")
|
||||||
|
(spit "test-backup/file" "I was here")
|
||||||
|
(tasks/shell "restic" "backup" "--password-file" "restic-pwd" "--repo" "restic-repo" "test-backup"))
|
||||||
|
|
||||||
|
(defn restic-restore!
|
||||||
|
[]
|
||||||
|
(tasks/shell "mkdir" "-p" "test-restore")
|
||||||
|
(tasks/shell "restic" "restore" "--password-file" "restic-pwd" "--repo" "restic-repo" "--target" "test-restore" "latest")
|
||||||
|
)
|
||||||
|
|
||||||
|
(restic-repo-init!)
|
||||||
|
(restic-backup!)
|
||||||
|
(restic-restore!)
|
Loading…
Reference in a new issue