#!/bin/bash # Restore script for Delphi Database System set -e BACKUP_DIR="/app/backups" DB_FILE="/app/data/delphi_database.db" echo "🔄 Starting database restore..." # Check if backup file is provided if [ -z "$1" ]; then echo "📋 Available backups:" ls -la "$BACKUP_DIR"/delphi_backup_*.db 2>/dev/null || echo " No backups found" echo "" echo "Usage: $0 " echo "Example: $0 delphi_backup_20241207_143000.db" exit 1 fi BACKUP_FILE="$BACKUP_DIR/$1" # Check if backup file exists if [ ! -f "$BACKUP_FILE" ]; then echo "❌ Backup file not found: $BACKUP_FILE" echo "📋 Available backups:" ls -la "$BACKUP_DIR"/delphi_backup_*.db 2>/dev/null || echo " No backups found" exit 1 fi # Create backup of current database before restore if [ -f "$DB_FILE" ]; then TIMESTAMP=$(date +"%Y%m%d_%H%M%S") CURRENT_BACKUP="${BACKUP_DIR}/delphi_backup_before_restore_${TIMESTAMP}.db" echo "💾 Creating backup of current database..." cp "$DB_FILE" "$CURRENT_BACKUP" echo "✅ Current database backed up to: $CURRENT_BACKUP" fi # Restore database echo "🔄 Restoring database from: $BACKUP_FILE" cp "$BACKUP_FILE" "$DB_FILE" # Verify restore if [ -f "$DB_FILE" ]; then DB_SIZE=$(stat -f%z "$DB_FILE" 2>/dev/null || stat -c%s "$DB_FILE" 2>/dev/null) echo "✅ Database restored successfully" echo " File: $DB_FILE" echo " Size: $DB_SIZE bytes" else echo "❌ Restore failed" exit 1 fi echo "🎉 Restore process completed!" echo "⚠️ Please restart the application to ensure proper database connection."