dda-backup/infrastructure/backup/test/resources/test.bb

89 lines
2.3 KiB
BlitzBasic
Raw Normal View History

2024-08-19 06:55:14 +00:00
#!/usr/bin/env bb
(require '[babashka.tasks :as tasks]
2024-08-21 14:55:59 +00:00
'[dda.backup.core :as bc]
2024-12-11 18:48:23 +00:00
'[dda.backup.cred-rot :as cr]
2024-08-20 15:15:27 +00:00
'[dda.backup.restic :as rc]
2024-08-20 06:17:51 +00:00
'[dda.backup.postgresql :as pg]
2024-08-19 06:55:14 +00:00
'[dda.backup.backup :as bak]
'[dda.backup.restore :as rs])
2024-08-20 05:56:13 +00:00
(def restic-repo {:password-file "restic-pwd"
2024-12-11 18:48:23 +00:00
:restic-repository "/restic-repo"})
2024-08-20 05:56:13 +00:00
2024-08-20 06:17:51 +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-08-20 06:17:51 +00:00
(def db-config (merge restic-repo {:backup-path "db"
:pg-db "mydb"
:pg-user "user"
:pg-password "password"}))
2024-12-11 18:48:23 +00:00
(def cred-config (merge file-config
{:restic-repository "/restic-repo/files"
:new-password-config {:new-password-file "new-pw"
:valid-from "2024-12-12 00:00:00"}}))
2024-08-20 06:17:51 +00:00
(def dry-run {:dry-run true :debug true})
2024-08-20 05:56:13 +00:00
(defn prepare!
[]
2024-08-22 16:06:30 +00:00
(spit "/tmp/file_password" "file-password")
2024-12-11 18:48:23 +00:00
(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")
2024-08-20 06:17:51 +00:00
(pg/create-pg-pass! db-config))
2024-08-20 05:56:13 +00:00
2024-12-11 18:48:23 +00:00
(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-08-19 06:55:14 +00:00
(defn restic-repo-init!
2024-12-11 18:48:23 +00:00
[]
(println "restic-repo-init!")
2024-08-20 15:15:27 +00:00
(rc/init! file-config)
(rc/init! (merge db-config dry-run)))
2024-08-19 06:55:14 +00:00
(defn restic-backup!
2024-12-11 18:48:23 +00:00
[]
(println "restic-backup!")
2024-08-21 06:57:08 +00:00
(bak/backup-file! file-config)
(bak/backup-db! (merge db-config dry-run)))
2024-08-19 06:55:14 +00:00
2024-08-22 16:06:30 +00:00
(defn list-snapshots!
[]
2024-12-11 18:48:23 +00:00
(println "list-snapshots!")
2024-08-22 16:06:30 +00:00
(rc/list-snapshots! file-config)
(rc/list-snapshots! (merge db-config dry-run)))
2024-08-19 06:55:14 +00:00
(defn restic-restore!
2024-12-11 18:48:23 +00:00
[]
(println "restic-restore!")
2024-08-20 16:06:24 +00:00
(rs/restore-file! file-config)
2024-08-21 06:57:08 +00:00
(pg/drop-create-db! (merge db-config dry-run))
(rs/restore-db! (merge db-config dry-run)))
2024-08-19 06:55:14 +00:00
2024-12-11 18:48:23 +00:00
(defn change-password!
[]
(println "change-password!")
(cr/change-password! cred-config))
2024-08-20 05:56:13 +00:00
(prepare!)
2024-12-11 18:48:23 +00:00
(check-env-or-file)
2024-08-19 06:55:14 +00:00
(restic-repo-init!)
(restic-backup!)
2024-08-22 16:06:30 +00:00
(list-snapshots!)
2024-08-19 06:55:14 +00:00
(restic-restore!)
2024-12-11 18:48:23 +00:00
(change-password!)