Files
mintel.me/apps/web/scripts/restore-db.sh
Marc Mintel 6174b44570
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 6s
Build & Deploy / 🧪 QA (push) Successful in 4m25s
Build & Deploy / 🏗️ Build (push) Failing after 17s
Build & Deploy / 🚀 Deploy (push) Has been skipped
Build & Deploy / 🧪 Post-Deploy Verification (push) Has been skipped
Build & Deploy / 🔔 Notify (push) Successful in 1s
fix: bump @mintel/payload-ai to 1.9.13 and apply CSS loader shim for Next.js dev server
2026-03-03 14:58:14 +01:00

62 lines
2.1 KiB
Bash

#!/usr/bin/env bash
# ────────────────────────────────────────────────────────────────────────────
# Payload CMS Database Restore
# Restores a backup created by backup-db.sh
# Usage: pnpm run db:restore <backup-file>
# ────────────────────────────────────────────────────────────────────────────
set -euo pipefail
# Load environment variables
if [ -f ../../.env ]; then
set -a; source ../../.env; set +a
fi
if [ -f .env ]; then
set -a; source .env; set +a
fi
DB_NAME="${postgres_DB_NAME:-payload}"
DB_USER="${postgres_DB_USER:-payload}"
DB_CONTAINER="mintel-me-postgres-db-1"
BACKUP_FILE="${1:-}"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
BACKUP_DIR="${SCRIPT_DIR}/../../../../backups"
if [ -z "$BACKUP_FILE" ]; then
echo "❌ Usage: pnpm run db:restore <backup-file>"
echo ""
echo "📋 Available backups in $BACKUP_DIR:"
ls -lh "$BACKUP_DIR"/*.dump 2>/dev/null | awk '{print " " $NF " (" $5 ")"}' || echo " No backups found."
exit 1
fi
if [ ! -f "$BACKUP_FILE" ]; then
echo "❌ Backup file not found: $BACKUP_FILE"
exit 1
fi
# Check if container is running
if ! docker ps --format '{{.Names}}' | grep -q "$DB_CONTAINER"; then
echo "❌ Database container '$DB_CONTAINER' is not running."
echo " Start it with: pnpm dev:docker"
exit 1
fi
echo "⚠️ WARNING: This will REPLACE ALL DATA in the '$DB_NAME' database!"
echo " Backup file: $BACKUP_FILE"
echo ""
read -p "Are you sure? (y/N) " -n 1 -r
echo ""
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "Cancelled."
exit 0
fi
echo "🔄 Restoring database from $BACKUP_FILE..."
# Uses pg_restore for custom format dumps (-F c) produced by backup-db.sh
cat "$BACKUP_FILE" | docker exec -i "$DB_CONTAINER" pg_restore -U "$DB_USER" -d "$DB_NAME" --clean --if-exists
echo "✅ Database restored successfully!"