fiddy/scripts/restore-drill-postgres.sh

35 lines
791 B
Bash

#!/usr/bin/env bash
set -euo pipefail
if [[ $# -lt 2 ]]; then
echo "Usage: $0 <backup.dump> <target_database_url>"
exit 1
fi
BACKUP_FILE="$1"
TARGET_DATABASE_URL="$2"
if [[ ! -f "$BACKUP_FILE" ]]; then
echo "Backup file not found: $BACKUP_FILE"
exit 1
fi
if ! command -v psql >/dev/null 2>&1; then
echo "psql command not found."
exit 1
fi
echo "Running restore drill..."
bash scripts/restore-postgres.sh "$BACKUP_FILE" "$TARGET_DATABASE_URL"
echo "Running post-restore validation queries..."
psql "$TARGET_DATABASE_URL" -v ON_ERROR_STOP=1 <<'SQL'
select now() as restore_checked_at_utc;
select count(*) as public_tables
from information_schema.tables
where table_schema='public';
select count(*) as users_count from users;
SQL
echo "Restore drill completed successfully."