88 lines
2.3 KiB
Clojure
Executable file
88 lines
2.3 KiB
Clojure
Executable file
#!/usr/bin/env bb
|
|
|
|
(require '[babashka.tasks :as tasks]
|
|
'[dda.backup.core :as bc]
|
|
'[dda.backup.cred-rot :as cr]
|
|
'[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 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"}}))
|
|
|
|
|
|
(def dry-run {:dry-run true :debug true})
|
|
|
|
(defn prepare!
|
|
[]
|
|
(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")))
|
|
|
|
(defn restic-repo-init!
|
|
[]
|
|
(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))
|
|
|
|
|
|
(prepare!)
|
|
(check-env-or-file)
|
|
(restic-repo-init!)
|
|
(restic-backup!)
|
|
(list-snapshots!)
|
|
(restic-restore!)
|
|
(change-password!)
|