refactor to babashka driven backup
This commit is contained in:
parent
67ec0f58eb
commit
03b0b85247
12 changed files with 62 additions and 109 deletions
infrastructure/backup/image
Dockerfile
resources
entrypoint-start-and-wait.shentrypoint.shinstall.bbinstall.shlist-snapshots.bbrestore.bbrestore.shwait.bb
resources2
src/main/resources/backup
|
@ -1,4 +1,4 @@
|
|||
FROM domaindrivenarchitecture/dda-backup:latest
|
||||
FROM domaindrivenarchitecture/dda-backup:5.1.0
|
||||
|
||||
# Prepare Entrypoint Script
|
||||
ADD resources /tmp
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -exo pipefail
|
||||
|
||||
function main() {
|
||||
file_env POSTGRES_DB
|
||||
file_env POSTGRES_PASSWORD
|
||||
file_env POSTGRES_USER
|
||||
|
||||
create-pg-pass
|
||||
|
||||
while true; do
|
||||
sleep 1m
|
||||
done
|
||||
}
|
||||
|
||||
source /usr/local/lib/functions.sh
|
||||
source /usr/local/lib/pg-functions.sh
|
||||
main
|
|
@ -1,17 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -Eexo pipefail
|
||||
|
||||
function main() {
|
||||
file_env POSTGRES_DB
|
||||
file_env POSTGRES_PASSWORD
|
||||
file_env POSTGRES_USER
|
||||
|
||||
create-pg-pass
|
||||
|
||||
/usr/local/bin/backup.sh
|
||||
}
|
||||
|
||||
source /usr/local/lib/functions.sh
|
||||
source /usr/local/lib/pg-functions.sh
|
||||
main
|
|
@ -5,19 +5,15 @@
|
|||
'[dda.image.install :as in])
|
||||
|
||||
(ub/upgrade-system!)
|
||||
(in/install! "entrypoint.sh")
|
||||
(in/install! "entrypoint-start-and-wait.sh")
|
||||
|
||||
(in/install! "bb-backup.edn" :target-name "bb.edn" :mod "0440")
|
||||
(in/install! "config.clj" :mod "0440")
|
||||
(in/install! "init.bb")
|
||||
(in/install! "backup.bb")
|
||||
(in/install! "restore.sh")
|
||||
(in/install! "restore.bb")
|
||||
(in/install! "list-snapshots.bb")
|
||||
(in/install! "start-maintenance.sh")
|
||||
(in/install! "end-maintenance.sh")
|
||||
|
||||
#(in/install! "restore.bb")
|
||||
#(in/install! "wait.bb")
|
||||
(in/install! "restore.bb")
|
||||
(in/install! "wait.bb")
|
||||
|
||||
(ub/cleanup-container!)
|
|
@ -1,21 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -exo pipefail
|
||||
|
||||
function main() {
|
||||
{
|
||||
install -m 0700 /tmp/entrypoint.sh /
|
||||
install -m 0700 /tmp/entrypoint-start-and-wait.sh /
|
||||
|
||||
install -m 0700 /tmp/init.sh /usr/local/bin/
|
||||
install -m 0700 /tmp/backup.sh /usr/local/bin/
|
||||
install -m 0700 /tmp/restore.sh /usr/local/bin/
|
||||
install -m 0700 /tmp/list-snapshots.sh /usr/local/bin/
|
||||
install -m 0700 /tmp/start-maintenance.sh /usr/local/bin/
|
||||
install -m 0700 /tmp/end-maintenance.sh /usr/local/bin/
|
||||
cleanupDocker
|
||||
} > /dev/null
|
||||
}
|
||||
|
||||
source /tmp/install_functions_debian.sh
|
||||
main
|
|
@ -1,15 +1,12 @@
|
|||
#!/usr/bin/env bb
|
||||
|
||||
(require
|
||||
'[babashka.fs :as fs])
|
||||
|
||||
(println (-> "/usr/local/bin/config.clj" fs/file load-file))
|
||||
(-> "/usr/local/bin/config.clj" fs/file load-file)
|
||||
|
||||
(require
|
||||
'[dda.backup.core :as bc]
|
||||
'[dda.backup.restic :as rc]
|
||||
'[config.clj :as cf])
|
||||
'[config :as cf])
|
||||
|
||||
(defn prepare!
|
||||
[]
|
||||
|
|
29
infrastructure/backup/image/resources/restore.bb
Executable file
29
infrastructure/backup/image/resources/restore.bb
Executable file
|
@ -0,0 +1,29 @@
|
|||
#!/usr/bin/env bb
|
||||
(require
|
||||
'[babashka.fs :as fs])
|
||||
(-> "/usr/local/bin/config.clj" fs/file load-file)
|
||||
|
||||
(require
|
||||
'[babashka.tasks :as t]
|
||||
'[dda.backup.core :as bc]
|
||||
'[dda.backup.postgresql :as pg]
|
||||
'[dda.backup.restore :as rs]
|
||||
'[config :as cf])
|
||||
|
||||
(defn prepare!
|
||||
[]
|
||||
(bc/create-aws-credentials! cf/aws-config)
|
||||
(pg/create-pg-pass! cf/db-config))
|
||||
|
||||
(defn restic-restore!
|
||||
[]
|
||||
(pg/drop-create-db! cf/db-config)
|
||||
(rs/restore-db-roles! cf/db-role-config)
|
||||
(rs/restore-db! cf/db-config)
|
||||
(rs/restore-file! cf/file-config)
|
||||
)
|
||||
|
||||
(t/shell "start-maintenance.sh")
|
||||
(prepare!)
|
||||
(restic-restore!)
|
||||
(t/shell "end-maintenance.sh")
|
|
@ -1,33 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -Eexo pipefail
|
||||
|
||||
function main() {
|
||||
local role_snapshot_id="${1:-latest}"
|
||||
local db_snapshot_id="${2:-latest}"
|
||||
local file_snapshot_id="${3:-latest}"
|
||||
|
||||
|
||||
start-maintenance.sh
|
||||
|
||||
file_env AWS_ACCESS_KEY_ID
|
||||
file_env AWS_SECRET_ACCESS_KEY
|
||||
|
||||
file_env POSTGRES_DB
|
||||
file_env POSTGRES_PASSWORD
|
||||
file_env POSTGRES_USER
|
||||
|
||||
drop-create-db
|
||||
|
||||
restore-roles ${role_snapshot_id}
|
||||
restore-db ${db_snapshot_id}
|
||||
restore-directory '/var/backups/' ${file_snapshot_id}
|
||||
|
||||
end-maintenance.sh
|
||||
}
|
||||
|
||||
source /usr/local/lib/functions.sh
|
||||
source /usr/local/lib/pg-functions.sh
|
||||
source /usr/local/lib/file-functions.sh
|
||||
|
||||
main "$@"
|
21
infrastructure/backup/image/resources/wait.bb
Executable file
21
infrastructure/backup/image/resources/wait.bb
Executable file
|
@ -0,0 +1,21 @@
|
|||
#!/usr/bin/env bb
|
||||
(require
|
||||
'[babashka.fs :as fs])
|
||||
(-> "/usr/local/bin/config.clj" fs/file load-file)
|
||||
|
||||
(require
|
||||
'[dda.backup.core :as bc]
|
||||
'[dda.backup.postgresql :as pg]
|
||||
'[config :as cf])
|
||||
|
||||
(defn prepare!
|
||||
[]
|
||||
(bc/create-aws-credentials! cf/aws-config)
|
||||
(pg/create-pg-pass! cf/db-config))
|
||||
|
||||
(defn wait! []
|
||||
(while true
|
||||
(Thread/sleep 1000)))
|
||||
|
||||
(prepare!)
|
||||
(wait!)
|
|
@ -22,8 +22,8 @@
|
|||
(defn restic-repo-init!
|
||||
[]
|
||||
(rc/init! cf/file-config)
|
||||
(rc/init! (merge cf/db-config cf/dry-run))
|
||||
(rc/init! (merge cf/db-role-config cf/dry-run)))
|
||||
(rc/init! (merge cf/db-config))
|
||||
(rc/init! (merge cf/db-role-config)))
|
||||
|
||||
(defn restic-backup!
|
||||
[]
|
||||
|
@ -37,12 +37,12 @@
|
|||
(rc/list-snapshots! (merge cf/db-role-config cf/dry-run))
|
||||
(rc/list-snapshots! (merge cf/db-config cf/dry-run)))
|
||||
|
||||
|
||||
(defn restic-restore!
|
||||
[]
|
||||
(rs/restore-file! (merge {:debug true} cf/file-restore-config))
|
||||
(println "huhu")
|
||||
(rs/restore-file! (merge cf/file-restore-config {:debug true}))
|
||||
(pg/drop-create-db! (merge cf/db-config cf/dry-run))
|
||||
;(rs/restore-db-roles! (merge cf/db-role-config cf/dry-run))
|
||||
(rs/restore-db-roles! (merge cf/db-role-config cf/dry-run))
|
||||
(rs/restore-db! (merge cf/db-config cf/dry-run)))
|
||||
|
||||
(prepare!)
|
||||
|
|
|
@ -21,7 +21,7 @@ spec:
|
|||
- name: backup-app
|
||||
image: domaindrivenarchitecture/c4k-cloud-backup
|
||||
imagePullPolicy: IfNotPresent
|
||||
command: ["/entrypoint-start-and-wait.sh"]
|
||||
command: ["wait.bb"]
|
||||
env:
|
||||
- name: POSTGRES_USER
|
||||
valueFrom:
|
||||
|
|
|
@ -17,7 +17,7 @@ spec:
|
|||
- name: backup-app
|
||||
image: domaindrivenarchitecture/c4k-cloud-backup
|
||||
imagePullPolicy: IfNotPresent
|
||||
command: ["/entrypoint.sh"]
|
||||
command: ["backup.bb"]
|
||||
env:
|
||||
- name: POSTGRES_USER
|
||||
valueFrom:
|
||||
|
|
Loading…
Reference in a new issue