c4k-forgejo/infrastructure/backup/image/resources/restore.bb

41 lines
1.2 KiB
BlitzBasic
Raw Normal View History

2024-08-23 06:45:43 +00:00
#!/usr/bin/env bb
(require '[babashka.tasks :as tasks]
'[dda.backup.core :as bc]
2025-01-13 15:04:12 +00:00
'[dda.backup.config :as cfg]
2024-08-23 06:45:43 +00:00
'[dda.backup.postgresql :as pg]
'[dda.backup.restore :as rs])
2025-01-13 15:04:12 +00:00
(def config (cfg/read-config "/usr/local/bin/config.edn"))
2024-08-23 06:45:43 +00:00
2025-01-13 15:04:12 +00:00
(def file-config (merge
(:restic-repo config)
{:backup-path "files"
:restore-target-directory "/var/backups/restore"
:snapshot-id "latest"}))
2024-08-23 06:45:43 +00:00
2025-01-13 15:04:12 +00:00
(def db-config (merge (:db-config config)
{:snapshot-id "latest"}))
2024-08-23 06:45:43 +00:00
2024-08-23 10:10:07 +00:00
2024-08-23 06:45:43 +00:00
(def dry-run {:dry-run true :debug true})
(defn prepare!
[]
2025-01-13 15:04:12 +00:00
(bc/create-aws-credentials! (:aws-config config))
(pg/create-pg-pass! db-config))
2024-08-23 06:45:43 +00:00
(defn restic-restore!
[]
(rs/restore-file! file-config)
2024-08-23 15:47:52 +00:00
(tasks/shell ["bash" "-c" "rm -rf /var/backups/gitea/*"])
(tasks/shell ["bash" "-c" "rm -rf /var/backups/git/repositories/*"])
(tasks/shell ["mv" "/var/backups/restore/gitea" "/var/backups/"])
(tasks/shell ["mv" "/var/backups/restore/git/repositories" "/var/backups/git/"])
(tasks/shell ["chown" "-R" "1000:1000" "/var/backups"])
2025-01-13 15:04:12 +00:00
(pg/drop-create-db! db-config)
(rs/restore-db! db-config))
2024-08-23 06:45:43 +00:00
(prepare!)
(restic-restore!)