feat: add production operations scripts and monitoring guide
Add comprehensive tooling for production deployment: Scripts (scripts/): - backup-db.sh: Automated database backups with 7-day retention - restore-db.sh: Safe database restore with confirmation prompts - health-check.sh: Complete service health monitoring - README.md: Operational scripts documentation Monitoring (docs/MONITORING.md): - Application health monitoring - Docker container monitoring - External monitoring setup (UptimeRobot, Pingdom) - Log monitoring and rotation - Alerting configuration - Incident response procedures - SLA targets and metrics All scripts include: - Environment support (dev/prod) - Error handling and validation - Detailed status reporting - Safety confirmations where needed
This commit is contained in:
65
scripts/restore-db.sh
Normal file
65
scripts/restore-db.sh
Normal file
@@ -0,0 +1,65 @@
|
||||
#!/bin/bash
|
||||
# Database restore script for spotlight.cam
|
||||
# Usage: ./scripts/restore-db.sh <backup-file> [dev|prod]
|
||||
|
||||
set -e
|
||||
|
||||
# Check if backup file is provided
|
||||
if [ -z "$1" ]; then
|
||||
echo "❌ Error: Backup file not specified"
|
||||
echo "Usage: ./scripts/restore-db.sh <backup-file> [dev|prod]"
|
||||
echo "Example: ./scripts/restore-db.sh ./backups/backup_dev_20251120_120000.sql dev"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
BACKUP_FILE=$1
|
||||
ENV=${2:-dev}
|
||||
|
||||
# Check if backup file exists
|
||||
if [ ! -f "$BACKUP_FILE" ]; then
|
||||
echo "❌ Error: Backup file not found: $BACKUP_FILE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Set container name based on environment
|
||||
if [ "$ENV" = "prod" ]; then
|
||||
DB_CONTAINER="slc-db-prod"
|
||||
DB_NAME="spotlightcam"
|
||||
else
|
||||
DB_CONTAINER="slc-db"
|
||||
DB_NAME="spotlightcam"
|
||||
fi
|
||||
|
||||
echo "⚠️ WARNING: This will REPLACE the current database!"
|
||||
echo "📦 Environment: $ENV"
|
||||
echo "🗄️ Container: $DB_CONTAINER"
|
||||
echo "💾 Backup file: $BACKUP_FILE"
|
||||
echo ""
|
||||
read -p "Are you sure you want to continue? (yes/no): " -r
|
||||
echo
|
||||
|
||||
if [[ ! $REPLY =~ ^[Yy][Ee][Ss]$ ]]; then
|
||||
echo "❌ Restore cancelled"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Check if container is running
|
||||
if ! docker ps --format '{{.Names}}' | grep -q "^${DB_CONTAINER}$"; then
|
||||
echo "❌ Error: Container $DB_CONTAINER is not running"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "🔄 Starting database restore..."
|
||||
|
||||
# Restore backup
|
||||
cat "$BACKUP_FILE" | docker exec -i "$DB_CONTAINER" psql -U spotlightcam "$DB_NAME"
|
||||
|
||||
# Check if restore was successful
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "✅ Restore completed successfully!"
|
||||
else
|
||||
echo "❌ Restore failed!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "✨ Done!"
|
||||
Reference in New Issue
Block a user