#!/bin/sh # Restore a pg_dump (-Fc format) to a target Postgres database. # The target DB must already exist and be empty (or you accept overwriting data). # # Usage: # restore.sh # # Example (inside the backup container): # /scripts/restore.sh \ # /backups/famapp/daily/2024-06-01.dump \ # postgres://famapp:secret@famapp-db:5432/famapp # # Example (from the host via docker exec): # docker exec famapp-backup-1 /scripts/restore.sh \ # /backups/famapp/daily/2024-06-01.dump \ # postgres://famapp:secret@famapp-db:5432/famapp_restore set -eu DUMP_FILE="${1:?Usage: restore.sh }" TARGET_URL="${2:?Usage: restore.sh }" [ -f "$DUMP_FILE" ] || { echo "[restore] ERROR: $DUMP_FILE not found"; exit 1; } echo "[restore] $DUMP_FILE → $TARGET_URL" pg_restore -d "$TARGET_URL" --no-owner --no-acl --exit-on-error "$DUMP_FILE" echo "[restore] done"