From 88b7c8eb8400ccb022517872b8d023d553c0ebb6 Mon Sep 17 00:00:00 2001 From: uprightbass360 Date: Tue, 30 Sep 2025 14:24:12 -0400 Subject: [PATCH] update backup process --- docker-compose-azerothcore-database.env | 2 +- docker-compose-azerothcore-database.yml | 58 ++------ readme.md | 190 +++++++++++++++++++++++- {backup-scripts => scripts}/backup.sh | 0 {backup-scripts => scripts}/restore.sh | 0 5 files changed, 199 insertions(+), 51 deletions(-) rename {backup-scripts => scripts}/backup.sh (100%) rename {backup-scripts => scripts}/restore.sh (100%) diff --git a/docker-compose-azerothcore-database.env b/docker-compose-azerothcore-database.env index 1e5ba1d..901b1b0 100644 --- a/docker-compose-azerothcore-database.env +++ b/docker-compose-azerothcore-database.env @@ -69,7 +69,7 @@ NETWORK_GATEWAY=172.20.0.1 # BACKUP CONFIGURATION # Host volume paths for backup HOST_BACKUP_PATH=./backups -HOST_BACKUP_SCRIPTS_PATH=./backup-scripts +HOST_BACKUP_SCRIPTS_PATH=./scripts # Backup settings BACKUP_CRON_SCHEDULE=0 3 * * * diff --git a/docker-compose-azerothcore-database.yml b/docker-compose-azerothcore-database.yml index a60ca8e..aed5d0c 100644 --- a/docker-compose-azerothcore-database.yml +++ b/docker-compose-azerothcore-database.yml @@ -77,61 +77,31 @@ services: - /bin/bash - -c - | - echo "๐Ÿ”ง Starting simple backup service..." + echo "๐Ÿ”ง Starting backup service using external script..." - # Create backup function - run_backup() { - echo "๐Ÿ’พ [$(date)] Starting database backup..." + # Make sure backup script is executable + chmod +x /scripts/backup.sh - # Wait for MySQL to be available - for i in $(seq 1 10); do - if mysqldump -h ${CONTAINER_MYSQL} -u ${MYSQL_USER} -p${MYSQL_PASSWORD} --version >/dev/null 2>&1; then - echo "โœ… MySQL connection available" - break - fi - echo "โณ Waiting for MySQL... attempt $$i/10" - sleep 5 - done - - # Create backup directory - BACKUP_DIR="/backups/$(date +%Y%m%d_%H%M%S)" - mkdir -p "$$BACKUP_DIR" - - # Backup all databases - echo "๐Ÿ“ฆ Backing up databases to $$BACKUP_DIR" - mysqldump -h ${CONTAINER_MYSQL} -u ${MYSQL_USER} -p${MYSQL_PASSWORD} \ - --all-databases --single-transaction --routines --triggers \ - > "$$BACKUP_DIR/full_backup.sql" 2>/dev/null - - if [ -f "$$BACKUP_DIR/full_backup.sql" ]; then - echo "โœ… [$(date)] Backup completed: $$BACKUP_DIR/full_backup.sql" - - # Cleanup old backups - echo "๐Ÿงน Cleaning up backups older than ${BACKUP_RETENTION_DAYS} days..." - find /backups -type d -name "????????_??????" -mtime +${BACKUP_RETENTION_DAYS} -exec rm -rf {} + 2>/dev/null || true - - echo "๐Ÿ“Š Current backup status:" - ls -la /backups/ 2>/dev/null || echo "No backups directory" - else - echo "โŒ [$(date)] Backup failed" - fi - } - - echo "Starting backup service with schedule: ${BACKUP_CRON_SCHEDULE}" - echo "Backup retention: ${BACKUP_RETENTION_DAYS} days" - - # Wait for MySQL to be ready, then run initial backup + # Wait for MySQL to be ready before starting backup service + echo "โณ Waiting for MySQL to be ready..." sleep 30 - run_backup + + # Run initial backup + echo "๐Ÿš€ Running initial backup..." + /scripts/backup.sh # Simple cron-like scheduler (runs backup at 3 AM daily) + echo "โฐ Starting backup scheduler with schedule: ${BACKUP_CRON_SCHEDULE}" + echo "๐Ÿ“… Backup retention: ${BACKUP_RETENTION_DAYS} days" + while true; do current_hour=$(date +%H) current_minute=$(date +%M) # Check if it's 3:00 AM (matching default cron schedule) if [ "$$current_hour" = "03" ] && [ "$$current_minute" = "00" ]; then - run_backup + echo "โฐ [$(date)] Scheduled backup time reached, running backup..." + /scripts/backup.sh # Sleep for 2 minutes to avoid running multiple times sleep 120 else diff --git a/readme.md b/readme.md index 499b450..8001272 100644 --- a/readme.md +++ b/readme.md @@ -31,6 +31,8 @@ This project is a Docker/Podman implementation based on: - [Configuration](#configuration) - [Volume Management](#volume-management) - [Maintenance](#maintenance) +- [Backup System](#backup-system) +- [Deployment Scripts](#deployment-scripts) - [Troubleshooting](#troubleshooting) - [Security Considerations](#security-considerations) @@ -104,7 +106,7 @@ acore-compose/ โ”œโ”€โ”€ docker-compose-azerothcore-services.env # Services configuration โ”œโ”€โ”€ docker-compose-azerothcore-tools.env # Tools configuration โ”œโ”€โ”€ docker-compose-azerothcore-optional.env # Optional services config -โ”œโ”€โ”€ backup-scripts/ # Database backup automation +โ”œโ”€โ”€ scripts/ # Deployment, cleanup, and backup automation โ”œโ”€โ”€ local-data/ # Local storage (when not using NFS) โ””โ”€โ”€ readme.md # This documentation ``` @@ -431,19 +433,195 @@ cat > /etc/logrotate.d/azerothcore <` | + +### Deployment and Health Check Script + +The `deploy-and-check.sh` script provides automated deployment and comprehensive health verification. + +#### Features +โœ… **Layered Deployment**: Deploys database โ†’ services โ†’ tools in correct order +โœ… **Container Health Validation**: Checks all 8 core containers +โœ… **Port Connectivity Tests**: Validates all external ports +โœ… **Web Service Verification**: HTTP response and content validation +โœ… **Database Validation**: Schema and realm configuration checks +โœ… **Comprehensive Reporting**: Color-coded status with detailed results + +#### Usage Examples + +```bash +cd scripts + +# Full deployment with health checks +./deploy-and-check.sh + +# Health check only (skip deployment) +./deploy-and-check.sh --skip-deploy + +# Quick health check (basic tests only) +./deploy-and-check.sh --skip-deploy --quick-check +``` + +### Cleanup Script + +The `cleanup.sh` script provides safe and comprehensive cleanup options with multiple levels of cleanup intensity. + +#### Cleanup Levels + +- **๐ŸŸข Soft (`--soft`)**: Stop containers only (preserves data) +- **๐ŸŸก Hard (`--hard`)**: Remove containers + networks (preserves volumes/data) +- **๐Ÿ”ด Nuclear (`--nuclear`)**: Complete removal (DESTROYS ALL DATA) + +#### Usage Examples + +```bash +cd scripts + +# Safe cleanup - stop containers only +./cleanup.sh --soft + +# Moderate cleanup - remove containers and networks (preserves data) +./cleanup.sh --hard + +# Complete cleanup - remove everything (DESTROYS ALL DATA) +./cleanup.sh --nuclear + +# See what would happen without doing it +./cleanup.sh --hard --dry-run + +# Force cleanup without prompts (for automation) +./cleanup.sh --hard --force +``` + +### Script Documentation + +For complete documentation on each script: +- **Deployment**: See `scripts/DEPLOYMENT.md` +- **Cleanup**: See `scripts/CLEANUP.md` +- **Scripts Overview**: See `scripts/README.md` + ## Troubleshooting ### Common Issues diff --git a/backup-scripts/backup.sh b/scripts/backup.sh similarity index 100% rename from backup-scripts/backup.sh rename to scripts/backup.sh diff --git a/backup-scripts/restore.sh b/scripts/restore.sh similarity index 100% rename from backup-scripts/restore.sh rename to scripts/restore.sh