#!/usr/bin/env bash # Dumps the Postgres database from the running "postgres" container into ./backups/, # in pg_dump's custom format (compressed, restorable with pg_restore — see restore-db.sh). # # Usage: scripts/backup-db.sh set -euo pipefail cd "$(dirname "$0")/.." mkdir -p backups timestamp="$(date +%Y%m%d_%H%M%S)" out="backups/dnd_backup_${timestamp}.dump" trap 'rm -f "${out}"' ERR echo "Dumping database into ${out} ..." docker compose exec -T postgres sh -c 'pg_dump -U "$POSTGRES_USER" -d "$POSTGRES_DB" -F c' > "${out}" size="$(du -h "${out}" | cut -f1)" echo "Done: ${out} (${size})"