dda-backup/infrastructure/backup/image/resources2/test.bb

88 lines
2.3 KiB
BlitzBasic
Raw Normal View History

2024-11-29 14:14:01 +00:00
#!/usr/bin/env bb
(require '[babashka.tasks :as tasks]
2024-12-11 18:48:23 +00:00
'[dda.backup.core :as bc]
2024-11-29 14:14:01 +00:00
'[dda.backup.cred-rot :as cr]
'[dda.backup.restic :as rc]
2024-12-11 18:48:23 +00:00
'[dda.backup.postgresql :as pg]
'[dda.backup.backup :as bak]
'[dda.backup.restore :as rs])
2024-11-29 14:14:01 +00:00
(def restic-repo {:password-file "restic-pwd"
2024-12-11 18:48:23 +00:00
:restic-repository "/restic-repo"})
2024-11-29 14:14:01 +00:00
(def file-config (merge restic-repo {:backup-path "files"
2024-12-11 18:48:23 +00:00
:files ["/test-backup"]
:restore-target-directory "/test-restore"}))
2024-11-29 14:14:01 +00:00
2024-12-11 18:48:23 +00:00
(def db-config (merge restic-repo {:backup-path "db"
:pg-db "mydb"
:pg-user "user"
:pg-password "password"}))
(def cred-config (merge file-config
{:restic-repository "/restic-repo/files"
:new-password-config {:new-password-file "new-pw"
2024-12-11 09:43:44 +00:00
:valid-from "2024-12-12 00:00:00"}}))
2024-11-29 14:14:01 +00:00
2024-12-11 18:48:23 +00:00
2024-11-29 14:14:01 +00:00
(def dry-run {:dry-run true :debug true})
(defn prepare!
[]
2024-12-11 18:48:23 +00:00
(spit "/tmp/file_password" "file-password")
(spit "/restic-pwd" "ThePassword")
(spit "/new-pw" "newPassword")
(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 check-env-or-file
[]
(println "check-env-or-file")
(println (bc/env-or-file "FILE_PASSWORD"))
(println (bc/env-or-file "ENV_PASSWORD")))
2024-11-29 14:14:01 +00:00
(defn restic-repo-init!
[]
2024-12-11 18:48:23 +00:00
(println "restic-repo-init!")
(rc/init! file-config)
(rc/init! (merge db-config dry-run)))
(defn restic-backup!
[]
(println "restic-backup!")
(bak/backup-file! file-config)
(bak/backup-db! (merge db-config dry-run)))
(defn list-snapshots!
[]
(println "list-snapshots!")
(rc/list-snapshots! file-config)
(rc/list-snapshots! (merge db-config dry-run)))
(defn restic-restore!
[]
(println "restic-restore!")
(rs/restore-file! file-config)
(pg/drop-create-db! (merge db-config dry-run))
(rs/restore-db! (merge db-config dry-run)))
(defn change-password!
[]
(println "change-password!")
(cr/change-password! cred-config))
2024-11-29 14:14:01 +00:00
(prepare!)
(restic-repo-init!)
2024-12-11 18:48:23 +00:00
(restic-backup!)
(list-snapshots!)
(restic-restore!)
(change-password!)