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.
30 lines
1.0 KiB
Bash
30 lines
1.0 KiB
Bash
#!/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();"
|
|
}
|
|
|
|
"$@"
|