freshyo-deploy/restore/restore_dump.sh
2026-01-26 12:46:49 +00:00

45 lines
922 B
Bash
Executable file

#!/bin/bash
set -e
# -----------------------------
# INPUTS
# -----------------------------
CONTAINER_NAME="$1"
DB_PORT="$2"
DUMP_FILE="$3"
# -----------------------------
# VALIDATION
# -----------------------------
if [ -z "$CONTAINER_NAME" ] || [ -z "$DB_PORT" ] || [ -z "$DUMP_FILE" ]; then
echo "Usage: $0 <container_name> <port> <dump_file>"
exit 1
fi
if [ ! -f "$DUMP_FILE" ]; then
echo "Dump file not found: $DUMP_FILE"
exit 1
fi
# -----------------------------
# CONFIG
# -----------------------------
PG_USER="postgres"
# -----------------------------
# RESTORE
# -----------------------------
echo "Restoring dump '$DUMP_FILE' into container '$CONTAINER_NAME'..."
docker exec -i "$CONTAINER_NAME" \
pg_restore \
-U "$PG_USER" \
-p "$DB_PORT" \
--clean \
--if-exists \
--no-owner \
--no-privileges \
-d postgres < "$DUMP_FILE"
echo "Restore completed successfully."