Files
transcription/deploy/backup/restore_postgres_backup.sh
T
Jim Lancaster c85cc6be20
Quality Gate / gate (push) Failing after 49s
V6 Phase 4 - Postgres backup to Synology
2026-08-25 13:09:14 -05:00

28 lines
1.0 KiB
Bash

#!/usr/bin/env sh
set -eu
if [ "$#" -lt 1 ]; then
echo "Usage: $0 <path-to-postgres-dump>"
exit 1
fi
dump_file="$1"
COMPOSE_FILE="${COMPOSE_FILE:-docker-compose.production.yml}"
ENV_FILE="${ENV_FILE:-.env.production}"
if [ ! -f "${dump_file}" ]; then
echo "Backup file not found: ${dump_file}"
exit 1
fi
docker compose --env-file "${ENV_FILE}" -f "${COMPOSE_FILE}" exec -T postgres sh -lc \
"PGPASSWORD=\"\$POSTGRES_PASSWORD\" psql -U \"\$POSTGRES_USER\" -d postgres -c \"DROP DATABASE IF EXISTS \\\"\$POSTGRES_DB\\\";\""
docker compose --env-file "${ENV_FILE}" -f "${COMPOSE_FILE}" exec -T postgres sh -lc \
"PGPASSWORD=\"\$POSTGRES_PASSWORD\" psql -U \"\$POSTGRES_USER\" -d postgres -c \"CREATE DATABASE \\\"\$POSTGRES_DB\\\";\""
cat "${dump_file}" | docker compose --env-file "${ENV_FILE}" -f "${COMPOSE_FILE}" exec -T postgres sh -lc \
"PGPASSWORD=\"\$POSTGRES_PASSWORD\" pg_restore -U \"\$POSTGRES_USER\" -d \"\$POSTGRES_DB\" --clean --if-exists --no-owner --no-privileges"
echo "Restore complete from: ${dump_file}"