Initial project commit
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
#!/bin/bash
|
||||
# Database restore script
|
||||
# Usage: ./scripts/restore_db.sh <backup_file.sql.gz>
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
if [ $# -lt 1 ]; then
|
||||
echo "Usage: $0 <backup_file.sql.gz>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
BACKUP_FILE="$1"
|
||||
|
||||
if [ ! -f "$BACKUP_FILE" ]; then
|
||||
echo "Error: File not found: $BACKUP_FILE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
SERVER_DIR="$(dirname "$SCRIPT_DIR")"
|
||||
|
||||
if [ -f "$SERVER_DIR/.env" ]; then
|
||||
export $(grep -v '^#' "$SERVER_DIR/.env" | xargs)
|
||||
fi
|
||||
|
||||
DB_HOST="${DB_HOST:-10.0.10.11}"
|
||||
DB_PORT="${DB_PORT:-5432}"
|
||||
DB_NAME="${DB_NAME:-ciyuan_viewfinder}"
|
||||
DB_USER="${DB_USER:-shiran}"
|
||||
|
||||
echo "[$(date)] WARNING: This will overwrite the current database '$DB_NAME'."
|
||||
read -p "Are you sure? (yes/no): " confirm
|
||||
if [ "$confirm" != "yes" ]; then
|
||||
echo "Aborted."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "[$(date)] Restoring from $BACKUP_FILE..."
|
||||
|
||||
gunzip -c "$BACKUP_FILE" | psql -h "$DB_HOST" -p "$DB_PORT" -U "$DB_USER" -d "$DB_NAME"
|
||||
|
||||
echo "[$(date)] Restore complete."
|
||||
Reference in New Issue
Block a user