Files
quality_app/restore_database.sh
Quality App Developer a8824d6f69 updated code
2025-12-25 22:45:22 +02:00

50 lines
1.3 KiB
Bash
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# Safe Database Restore Script
set -e
if [ -z "$1" ]; then
echo "Usage: $0 <backup_file.sql>"
echo "Example: $0 backups/backup_20251113.sql"
exit 1
fi
BACKUP_FILE="$1"
if [ ! -f "$BACKUP_FILE" ]; then
echo "❌ Error: Backup file not found: $BACKUP_FILE"
exit 1
fi
echo "============================================"
echo "🔄 Database Restore Process"
echo "============================================"
echo "Backup file: $BACKUP_FILE"
echo ""
# Step 1: Stop web application
echo "1⃣ Stopping web application..."
docker compose stop web
echo "✅ Web application stopped"
echo ""
# Step 2: Restore database
echo "2⃣ Restoring database..."
# Use sed to skip the problematic first line with sandbox mode comment
sed '1{/^\/\*M!999999/d;}' "$BACKUP_FILE" | docker compose exec -T db bash -c "mariadb -u trasabilitate -pInitial01! trasabilitate"
echo "✅ Database restored"
echo ""
# Step 3: Start web application
echo "3⃣ Starting web application..."
docker compose start web
sleep 5
echo "✅ Web application started"
echo ""
echo "============================================"
echo "✅ Database restore completed successfully!"
echo "============================================"
echo ""
echo "Application URL: http://localhost:8781"