Files
AzerothCore-RealmMaster/scripts/backup.sh
uprightbass360 7b256e7571 Merge playerbot backup support from modules branch
- Add automatic detection of acore_playerbots database in all backup scripts
- Improve restore script with better error handling
- Add logging of databases being backed up
- Include test-backup-detection.sh script
2025-10-11 02:09:46 -04:00

73 lines
2.5 KiB
Bash
Executable File
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
set -e
# Configuration from environment variables
MYSQL_HOST=${MYSQL_HOST:-ac-mysql}
MYSQL_PORT=${MYSQL_PORT:-3306}
MYSQL_USER=${MYSQL_USER:-root}
MYSQL_PASSWORD=${MYSQL_PASSWORD:-password}
BACKUP_DIR="/backups"
RETENTION_DAYS=${BACKUP_RETENTION_DAYS:-7}
DATE_FORMAT="%Y%m%d_%H%M%S"
# Database names - core databases
DATABASES=("acore_auth" "acore_world" "acore_characters")
# Check if acore_playerbots database exists and add it to backup list
echo "Checking for optional acore_playerbots database..."
if mysql -h$MYSQL_HOST -P$MYSQL_PORT -u$MYSQL_USER -p$MYSQL_PASSWORD -e "USE acore_playerbots;" 2>/dev/null; then
DATABASES+=("acore_playerbots")
echo "✅ acore_playerbots database found - will be included in backup"
else
echo " acore_playerbots database not found - skipping (this is normal for some installations)"
fi
# Create backup directory
mkdir -p $BACKUP_DIR
# Generate timestamp
TIMESTAMP=$(date +$DATE_FORMAT)
BACKUP_SUBDIR="$BACKUP_DIR/$TIMESTAMP"
mkdir -p $BACKUP_SUBDIR
echo "[$TIMESTAMP] Starting AzerothCore database backup..."
echo "[$TIMESTAMP] Databases to backup: ${DATABASES[@]}"
# Backup each database
for db in "${DATABASES[@]}"; do
echo "[$TIMESTAMP] Backing up database: $db"
mysqldump -h$MYSQL_HOST -P$MYSQL_PORT -u$MYSQL_USER -p$MYSQL_PASSWORD \
--single-transaction --routines --triggers --events \
--hex-blob --quick --lock-tables=false \
--add-drop-database --databases $db \
| gzip > $BACKUP_SUBDIR/${db}.sql.gz
if [ $? -eq 0 ]; then
SIZE=$(du -h $BACKUP_SUBDIR/${db}.sql.gz | cut -f1)
echo "[$TIMESTAMP] ✅ Successfully backed up $db ($SIZE)"
else
echo "[$TIMESTAMP] ❌ Failed to backup $db"
exit 1
fi
done
# Create backup manifest
cat > $BACKUP_SUBDIR/manifest.json <<EOF
{
"timestamp": "$TIMESTAMP",
"databases": ["${DATABASES[@]}"],
"backup_size": "$(du -sh $BACKUP_SUBDIR | cut -f1)",
"retention_days": $RETENTION_DAYS,
"mysql_version": "$(mysql -h$MYSQL_HOST -P$MYSQL_PORT -u$MYSQL_USER -p$MYSQL_PASSWORD -e 'SELECT VERSION();' -s -N)"
}
EOF
# Clean up old backups based on retention policy
echo "[$TIMESTAMP] Cleaning up backups older than $RETENTION_DAYS days..."
find $BACKUP_DIR -type d -name "[0-9]*" -mtime +$RETENTION_DAYS -exec rm -rf {} + 2>/dev/null || true
# Log backup completion
echo "[$TIMESTAMP] ✅ Backup completed successfully"
echo "[$TIMESTAMP] Backup location: $BACKUP_SUBDIR"
echo "[$TIMESTAMP] Current backups:"
ls -la $BACKUP_DIR/