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

47 lines
1.4 KiB
BlitzBasic
Raw Permalink Normal View History

2024-08-23 06:45:43 +00:00
#!/usr/bin/env bb
2024-08-23 09:39:59 +00:00
(require
'[dda.backup.core :as bc]
'[dda.backup.restic :as rc]
'[dda.backup.postgresql :as pg]
'[dda.backup.backup :as bak])
2024-08-23 06:45:43 +00:00
(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"
2024-08-23 13:44:40 +00:00
:execution-directory "/var/backups/"
:files ["gitea/" "git/repositories/"]}))
2024-08-23 06:45:43 +00:00
(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")}))
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
(bc/create-aws-credentials! aws-config)
(pg/create-pg-pass! db-config))
2024-08-23 06:45:43 +00:00
(defn restic-repo-init!
[]
(rc/init! file-config)
(rc/init! db-config))
(defn restic-backup!
[]
(bak/backup-file! file-config)
(bak/backup-db! db-config))
(prepare!)
(restic-repo-init!)
2024-08-23 13:44:40 +00:00
(restic-backup!)