mirror of
https://github.com/uprightbass360/AzerothCore-RealmMaster.git
synced 2026-01-13 09:07:20 +00:00
update backup process
This commit is contained in:
@@ -69,7 +69,7 @@ NETWORK_GATEWAY=172.20.0.1
|
|||||||
# BACKUP CONFIGURATION
|
# BACKUP CONFIGURATION
|
||||||
# Host volume paths for backup
|
# Host volume paths for backup
|
||||||
HOST_BACKUP_PATH=./backups
|
HOST_BACKUP_PATH=./backups
|
||||||
HOST_BACKUP_SCRIPTS_PATH=./backup-scripts
|
HOST_BACKUP_SCRIPTS_PATH=./scripts
|
||||||
|
|
||||||
# Backup settings
|
# Backup settings
|
||||||
BACKUP_CRON_SCHEDULE=0 3 * * *
|
BACKUP_CRON_SCHEDULE=0 3 * * *
|
||||||
|
|||||||
@@ -77,61 +77,31 @@ services:
|
|||||||
- /bin/bash
|
- /bin/bash
|
||||||
- -c
|
- -c
|
||||||
- |
|
- |
|
||||||
echo "🔧 Starting simple backup service..."
|
echo "🔧 Starting backup service using external script..."
|
||||||
|
|
||||||
# Create backup function
|
# Make sure backup script is executable
|
||||||
run_backup() {
|
chmod +x /scripts/backup.sh
|
||||||
echo "💾 [$(date)] Starting database backup..."
|
|
||||||
|
|
||||||
# Wait for MySQL to be available
|
# Wait for MySQL to be ready before starting backup service
|
||||||
for i in $(seq 1 10); do
|
echo "⏳ Waiting for MySQL to be ready..."
|
||||||
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
|
|
||||||
sleep 30
|
sleep 30
|
||||||
run_backup
|
|
||||||
|
# Run initial backup
|
||||||
|
echo "🚀 Running initial backup..."
|
||||||
|
/scripts/backup.sh
|
||||||
|
|
||||||
# Simple cron-like scheduler (runs backup at 3 AM daily)
|
# 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
|
while true; do
|
||||||
current_hour=$(date +%H)
|
current_hour=$(date +%H)
|
||||||
current_minute=$(date +%M)
|
current_minute=$(date +%M)
|
||||||
|
|
||||||
# Check if it's 3:00 AM (matching default cron schedule)
|
# Check if it's 3:00 AM (matching default cron schedule)
|
||||||
if [ "$$current_hour" = "03" ] && [ "$$current_minute" = "00" ]; then
|
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 for 2 minutes to avoid running multiple times
|
||||||
sleep 120
|
sleep 120
|
||||||
else
|
else
|
||||||
|
|||||||
190
readme.md
190
readme.md
@@ -31,6 +31,8 @@ This project is a Docker/Podman implementation based on:
|
|||||||
- [Configuration](#configuration)
|
- [Configuration](#configuration)
|
||||||
- [Volume Management](#volume-management)
|
- [Volume Management](#volume-management)
|
||||||
- [Maintenance](#maintenance)
|
- [Maintenance](#maintenance)
|
||||||
|
- [Backup System](#backup-system)
|
||||||
|
- [Deployment Scripts](#deployment-scripts)
|
||||||
- [Troubleshooting](#troubleshooting)
|
- [Troubleshooting](#troubleshooting)
|
||||||
- [Security Considerations](#security-considerations)
|
- [Security Considerations](#security-considerations)
|
||||||
|
|
||||||
@@ -104,7 +106,7 @@ acore-compose/
|
|||||||
├── docker-compose-azerothcore-services.env # Services configuration
|
├── docker-compose-azerothcore-services.env # Services configuration
|
||||||
├── docker-compose-azerothcore-tools.env # Tools configuration
|
├── docker-compose-azerothcore-tools.env # Tools configuration
|
||||||
├── docker-compose-azerothcore-optional.env # Optional services config
|
├── 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)
|
├── local-data/ # Local storage (when not using NFS)
|
||||||
└── readme.md # This documentation
|
└── readme.md # This documentation
|
||||||
```
|
```
|
||||||
@@ -431,19 +433,195 @@ cat > /etc/logrotate.d/azerothcore <<EOF
|
|||||||
EOF
|
EOF
|
||||||
```
|
```
|
||||||
|
|
||||||
### Automated Backups
|
## Backup System
|
||||||
|
|
||||||
The database layer includes an automated backup service. Configure via environment variables in `docker-compose-azerothcore-database.env`:
|
The deployment includes a comprehensive automated backup system with individual database backups, compression, and retention management.
|
||||||
|
|
||||||
|
### Backup Configuration
|
||||||
|
|
||||||
|
Configure via environment variables in `docker-compose-azerothcore-database.env`:
|
||||||
|
|
||||||
- `BACKUP_CRON_SCHEDULE`: Cron expression (default: "0 3 * * *" - 3 AM daily)
|
- `BACKUP_CRON_SCHEDULE`: Cron expression (default: "0 3 * * *" - 3 AM daily)
|
||||||
- `BACKUP_RETENTION_DAYS`: Days to keep backups (default: 7)
|
- `BACKUP_RETENTION_DAYS`: Days to keep backups (default: 7)
|
||||||
|
- `HOST_BACKUP_PATH`: Local backup storage path (default: ./backups)
|
||||||
|
- `HOST_BACKUP_SCRIPTS_PATH`: Backup scripts path (default: ./scripts)
|
||||||
|
|
||||||
|
### Backup Features
|
||||||
|
|
||||||
|
✅ **Individual Database Backups**: Separate compressed files for each database
|
||||||
|
✅ **Backup Manifests**: JSON metadata with timestamps and backup information
|
||||||
|
✅ **Automated Compression**: Gzip compression for space efficiency
|
||||||
|
✅ **Retention Management**: Automatic cleanup of old backups
|
||||||
|
✅ **External Scripts**: Uses external backup/restore scripts for flexibility
|
||||||
|
|
||||||
|
### Backup Operations
|
||||||
|
|
||||||
|
#### Automatic Backups
|
||||||
|
The `ac-backup` container runs continuously and performs scheduled backups:
|
||||||
|
- **Schedule**: Daily at 3:00 AM by default (configurable via `BACKUP_CRON_SCHEDULE`)
|
||||||
|
- **Databases**: All AzerothCore databases (auth, world, characters)
|
||||||
|
- **Format**: Individual compressed SQL files per database
|
||||||
|
- **Retention**: Automatic cleanup after configured days
|
||||||
|
|
||||||
|
#### Manual Backups
|
||||||
|
|
||||||
#### Manual Backup Trigger:
|
|
||||||
```bash
|
```bash
|
||||||
# Execute backup immediately
|
# Execute backup immediately using container
|
||||||
docker exec ac-backup /backup.sh
|
docker exec ac-backup /scripts/backup.sh
|
||||||
|
|
||||||
|
# Or run backup script directly (if scripts are accessible)
|
||||||
|
cd scripts
|
||||||
|
./backup.sh
|
||||||
|
|
||||||
|
# Check backup status and logs
|
||||||
|
docker logs ac-backup --tail 20
|
||||||
|
|
||||||
|
# List available backups
|
||||||
|
ls -la backups/
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Backup Structure
|
||||||
|
|
||||||
|
```
|
||||||
|
backups/
|
||||||
|
├── 20250930_181843/ # Timestamp-based backup directory
|
||||||
|
│ ├── acore_auth.sql.gz # Compressed auth database (8KB)
|
||||||
|
│ ├── acore_world.sql.gz # Compressed world database (77MB)
|
||||||
|
│ ├── acore_characters.sql.gz # Compressed characters database (16KB)
|
||||||
|
│ └── manifest.json # Backup metadata
|
||||||
|
├── 20250930_120000/ # Previous backup
|
||||||
|
└── ... # Additional backups (retention managed)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Backup Metadata
|
||||||
|
|
||||||
|
Each backup includes a `manifest.json` file with backup information:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"timestamp": "20250930_181843",
|
||||||
|
"databases": ["acore_auth acore_world acore_characters"],
|
||||||
|
"backup_size": "77M",
|
||||||
|
"retention_days": 7,
|
||||||
|
"mysql_version": "8.0.43"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Backup Restoration
|
||||||
|
|
||||||
|
#### Using Restore Script
|
||||||
|
```bash
|
||||||
|
cd scripts
|
||||||
|
./restore.sh /path/to/backup/directory/20250930_181843
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Manual Restoration
|
||||||
|
```bash
|
||||||
|
# Restore individual database from compressed backup
|
||||||
|
gunzip -c backups/20250930_181843/acore_world.sql.gz | \
|
||||||
|
docker exec -i ac-mysql mysql -uroot -p${MYSQL_ROOT_PASSWORD} acore_world
|
||||||
|
|
||||||
|
# Restore all databases from a backup directory
|
||||||
|
for db in auth world characters; do
|
||||||
|
gunzip -c backups/20250930_181843/acore_${db}.sql.gz | \
|
||||||
|
docker exec -i ac-mysql mysql -uroot -p${MYSQL_ROOT_PASSWORD} acore_${db}
|
||||||
|
done
|
||||||
|
```
|
||||||
|
|
||||||
|
### Backup Monitoring
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Monitor backup service logs
|
||||||
|
docker logs ac-backup -f
|
||||||
|
|
||||||
|
# Check backup service status
|
||||||
|
docker ps | grep ac-backup
|
||||||
|
|
||||||
|
# Verify recent backups
|
||||||
|
find backups/ -name "*.sql.gz" -mtime -1 -ls
|
||||||
|
|
||||||
|
# Check backup sizes
|
||||||
|
du -sh backups/*/
|
||||||
|
```
|
||||||
|
|
||||||
|
## Deployment Scripts
|
||||||
|
|
||||||
|
The `scripts/` directory contains automation tools for deployment, health checking, and cleanup operations.
|
||||||
|
|
||||||
|
### Available Scripts
|
||||||
|
|
||||||
|
| Script | Purpose | Usage |
|
||||||
|
|--------|---------|--------|
|
||||||
|
| `deploy-and-check.sh` | Automated deployment and health verification | `./deploy-and-check.sh [--skip-deploy] [--quick-check]` |
|
||||||
|
| `cleanup.sh` | Multi-level resource cleanup | `./cleanup.sh [--soft\|--hard\|--nuclear] [--dry-run]` |
|
||||||
|
| `backup.sh` | Manual database backup | `./backup.sh` |
|
||||||
|
| `restore.sh` | Database restoration | `./restore.sh <backup_directory>` |
|
||||||
|
|
||||||
|
### 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
|
## Troubleshooting
|
||||||
|
|
||||||
### Common Issues
|
### Common Issues
|
||||||
|
|||||||
Reference in New Issue
Block a user