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

47 lines
1.8 KiB
BlitzBasic
Raw Permalink 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]
'[dda.backup.postgresql :as pg]
'[dda.backup.restore :as rs])
(def restic-repo {:password-file (bc/env-or-file "RESTIC_PASSWORD_FILE")
:restic-repository (bc/env-or-file "RESTIC_REPOSITORY")})
(def file-config (merge restic-repo {:backup-path "files"
:restore-target-directory "/var/backups/restore"
:snapshot-id "latest"}))
(def db-config (merge restic-repo {:backup-path "pg-database"
:pg-host (bc/env-or-file "POSTGRES_SERVICE")
:pg-port (bc/env-or-file "POSTGRES_PORT")
:pg-db (bc/env-or-file "POSTGRES_DB")
:pg-user (bc/env-or-file "POSTGRES_USER")
:pg-password (bc/env-or-file "POSTGRES_PASSWORD")
:snapshot-id "latest"}))
2024-08-23 10:10:07 +00:00
(def aws-config {:aws-access-key-id (bc/env-or-file "AWS_ACCESS_KEY_ID")
:aws-secret-access-key (bc/env-or-file "AWS_SECRET_ACCESS_KEY")})
2024-08-23 06:45:43 +00:00
(def dry-run {:dry-run true :debug true})
(defn prepare!
[]
2024-08-23 10:10:07 +00:00
(pg/create-pg-pass! db-config)
(bc/create-aws-credentials! aws-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"])
(pg/drop-create-db! (merge db-config {:debug true}))
(rs/restore-db! (merge db-config {:debug true})))
2024-08-23 06:45:43 +00:00
(prepare!)
(restic-restore!)