c4k-forgejo/infrastructure/backup/image/resources/backup.bb
2024-08-23 15:44:40 +02:00

51 lines
1.7 KiB
Clojure
Executable file

#!/usr/bin/env bb
(require
'[babashka.tasks :as tasks]
'[dda.backup.core :as bc]
'[dda.backup.restic :as rc]
'[dda.backup.postgresql :as pg]
'[dda.backup.backup :as bak])
(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"
:execution-directory "/var/backups/"
:files ["gitea/" "git/repositories/"]}))
(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")}))
(def dry-run {:dry-run true :debug true})
(defn prepare!
[]
(tasks/shell ["mkdir" "/root/.aws"])
(spit "/root/.aws/credentials"
(str "[default]\n"
"aws_access_key_id=" (bc/env-or-file "AWS_ACCESS_KEY_ID") "\n"
"aws_secret_access_key=" (bc/env-or-file "AWS_SECRET_ACCESS_KEY")))
(tasks/shell ["chmod" "0600" "/root/.aws/credentials"])
(tasks/shell ["chmod" "0600" "/root/.pgpass"]
(pg/create-pg-pass! db-config)
(tasks/shell ["export" "TEST=hallo"]))
(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!)
(restic-backup!)