Files
spotlightcam/scripts/backup-db.sh
Radosław Gierwiało 642c8f6d6f 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
2025-11-20 22:22:22 +01:00

62 lines
1.6 KiB
Bash

#!/bin/bash
# Database backup script for spotlight.cam
# Usage: ./scripts/backup-db.sh [dev|prod]
set -e
# Default to development if no argument provided
ENV=${1:-dev}
# Configuration
DATE=$(date +%Y%m%d_%H%M%S)
BACKUP_DIR="./backups"
# Create backup directory if it doesn't exist
mkdir -p "$BACKUP_DIR"
# Set container name based on environment
if [ "$ENV" = "prod" ]; then
DB_CONTAINER="slc-db-prod"
DB_NAME="spotlightcam"
BACKUP_FILE="$BACKUP_DIR/backup_prod_$DATE.sql"
else
DB_CONTAINER="slc-db"
DB_NAME="spotlightcam"
BACKUP_FILE="$BACKUP_DIR/backup_dev_$DATE.sql"
fi
echo "🔄 Starting database backup..."
echo "📦 Environment: $ENV"
echo "🗄️ Container: $DB_CONTAINER"
echo "💾 Backup file: $BACKUP_FILE"
# 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
# Create backup
docker exec "$DB_CONTAINER" pg_dump -U spotlightcam "$DB_NAME" > "$BACKUP_FILE"
# Check if backup was successful
if [ $? -eq 0 ]; then
BACKUP_SIZE=$(du -h "$BACKUP_FILE" | cut -f1)
echo "✅ Backup completed successfully!"
echo "📊 Backup size: $BACKUP_SIZE"
echo "📁 Location: $BACKUP_FILE"
else
echo "❌ Backup failed!"
exit 1
fi
# Keep only last 7 days of backups
echo "🧹 Cleaning old backups (keeping last 7 days)..."
find "$BACKUP_DIR" -name "backup_*.sql" -mtime +7 -delete
# Count remaining backups
BACKUP_COUNT=$(find "$BACKUP_DIR" -name "backup_*.sql" | wc -l)
echo "📚 Total backups: $BACKUP_COUNT"
echo "✨ Done!"