refactor: extract backup/restore into config scripts, trim comments
All checks were successful
cc-ci/testme cc-ci: success
All checks were successful
cc-ci/testme cc-ci: success
Move the postgres and clickhouse backup/restore hook logic out of inline compose labels into dedicated pg_backup.sh / clickhouse_backup.sh config scripts (the pattern other recipes use), and trim the verbose explanatory comments down to the essential rationale, now living in the scripts.
This commit is contained in:
29
pg_backup.sh
Normal file
29
pg_backup.sh
Normal file
@ -0,0 +1,29 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
# The dump lives at the db-data volume root: backup-bot-two v2 snapshots paths inside
|
||||
# named volumes (backupbot.backup.volumes.db-data.path), not the container root fs.
|
||||
DUMP=/var/lib/postgresql/data/postgres.dump
|
||||
|
||||
backup() {
|
||||
pg_dump -U "$POSTGRES_USER" -Fc "$POSTGRES_DB" | gzip > "$DUMP.gz"
|
||||
}
|
||||
|
||||
backup_cleanup() {
|
||||
rm -f "$DUMP.gz"
|
||||
}
|
||||
|
||||
restore() {
|
||||
gzip -d "$DUMP.gz"
|
||||
# --if-exists: otherwise DROPs on objects absent from the live db error out and
|
||||
# pg_restore exits 1, killing the chain and leaving the dump behind.
|
||||
pg_restore --clean --if-exists -U "$POSTGRES_USER" --dbname="$POSTGRES_DB" < "$DUMP"
|
||||
rm -f "$DUMP"
|
||||
# pg_restore --clean recreates objects under the live app, so its pooled connections
|
||||
# keep stale type-OID caches ('cache lookup failed for type ...' crash loops, e.g.
|
||||
# Oban). Terminate them so Ecto reconnects fresh.
|
||||
psql -U "$POSTGRES_USER" -d "$POSTGRES_DB" -c "SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = current_database() AND pid <> pg_backend_pid();"
|
||||
}
|
||||
|
||||
"$@"
|
||||
Reference in New Issue
Block a user