c4k-forgejo/infrastructure/backup/test/resources/test.bb

63 lines
1.7 KiB
BlitzBasic
Raw Normal View History

2024-08-16 14:29:34 +00:00
#!/usr/bin/env bb
(require '[babashka.tasks :as tasks]
2024-08-23 11:25:13 +00:00
'[dda.backup.core :as bc]
'[dda.backup.restic :as rc]
'[dda.backup.postgresql :as pg]
2024-08-16 17:13:58 +00:00
'[dda.backup.backup :as bak]
'[dda.backup.restore :as rs])
2024-08-16 14:29:34 +00:00
2024-08-23 11:25:13 +00:00
(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!
2024-08-16 14:29:34 +00:00
[]
2024-08-23 11:25:13 +00:00
(spit "/tmp/file_password" "file-password")
(println (bc/env-or-file "FILE_PASSWORD"))
(println (bc/env-or-file "ENV_PASSWORD"))
2024-08-16 14:29:34 +00:00
(spit "restic-pwd" "ThePassword")
2024-08-23 11:25:13 +00:00
(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!
[]
(rc/init! file-config)
(rc/init! (merge db-config dry-run)))
2024-08-16 14:29:34 +00:00
(defn restic-backup!
[]
2024-08-23 11:25:13 +00:00
(bak/backup-file! file-config)
(bak/backup-db! (merge db-config dry-run)))
(defn list-snapshots!
[]
(rc/list-snapshots! file-config)
(rc/list-snapshots! (merge db-config dry-run)))
2024-08-16 14:29:34 +00:00
(defn restic-restore!
[]
2024-08-23 11:25:13 +00:00
(rs/restore-file! file-config)
(pg/drop-create-db! (merge db-config dry-run))
(rs/restore-db! (merge db-config dry-run)))
2024-08-16 14:29:34 +00:00
2024-08-23 11:25:13 +00:00
(prepare!)
2024-08-16 14:29:34 +00:00
(restic-repo-init!)
(restic-backup!)
2024-08-23 11:25:13 +00:00
(list-snapshots!)
2024-08-16 14:29:34 +00:00
(restic-restore!)