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
This commit is contained in:
uprightbass360
2025-10-11 02:09:46 -04:00
parent ed1251d0df
commit 7b256e7571
5 changed files with 99 additions and 6 deletions

View File

@@ -10,9 +10,18 @@ BACKUP_DIR="/backups"
RETENTION_DAYS=${BACKUP_RETENTION_DAYS:-3}
DATE_FORMAT="%Y%m%d_%H%M%S"
# Database names from environment variables
# Database names from environment variables - core databases
DATABASES=("${DB_AUTH_NAME:-acore_auth}" "${DB_WORLD_NAME:-acore_world}" "${DB_CHARACTERS_NAME:-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 daily backup directory
DAILY_DIR="$BACKUP_DIR/daily"
mkdir -p $DAILY_DIR
@@ -23,6 +32,7 @@ BACKUP_SUBDIR="$DAILY_DIR/$TIMESTAMP"
mkdir -p $BACKUP_SUBDIR
echo "[$TIMESTAMP] Starting AzerothCore daily backup..."
echo "[$TIMESTAMP] Databases to backup: ${DATABASES[@]}"
# Backup each database with additional options for daily backups
for db in "${DATABASES[@]}"; do

View File

@@ -10,9 +10,18 @@ BACKUP_DIR="/backups"
RETENTION_HOURS=${BACKUP_RETENTION_HOURS:-6}
DATE_FORMAT="%Y%m%d_%H%M%S"
# Database names from environment variables
# Database names from environment variables - core databases
DATABASES=("${DB_AUTH_NAME:-acore_auth}" "${DB_WORLD_NAME:-acore_world}" "${DB_CHARACTERS_NAME:-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 hourly backup directory
HOURLY_DIR="$BACKUP_DIR/hourly"
mkdir -p $HOURLY_DIR
@@ -23,6 +32,7 @@ BACKUP_SUBDIR="$HOURLY_DIR/$TIMESTAMP"
mkdir -p $BACKUP_SUBDIR
echo "[$TIMESTAMP] Starting AzerothCore hourly backup..."
echo "[$TIMESTAMP] Databases to backup: ${DATABASES[@]}"
# Backup each database
for db in "${DATABASES[@]}"; do

View File

@@ -10,9 +10,18 @@ BACKUP_DIR="/backups"
RETENTION_DAYS=${BACKUP_RETENTION_DAYS:-7}
DATE_FORMAT="%Y%m%d_%H%M%S"
# Database names
# 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
@@ -22,6 +31,7 @@ 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

View File

@@ -24,15 +24,31 @@ fi
echo "⚠️ WARNING: This will overwrite existing databases!"
echo "Restoring from backup: $TIMESTAMP"
# List databases that will be restored
echo "Databases that will be restored:"
for backup_file in $BACKUP_SUBDIR/*.sql.gz; do
if [ -f "$backup_file" ]; then
db_name=$(basename "$backup_file" .sql.gz)
echo " - $db_name"
fi
done
echo "Press Ctrl+C within 10 seconds to cancel..."
sleep 10
# Restore databases
for backup_file in $BACKUP_SUBDIR/*.sql.gz; do
if [ -f "$backup_file" ]; then
echo "Restoring $backup_file..."
zcat "$backup_file" | mysql -h$MYSQL_HOST -P$MYSQL_PORT -u$MYSQL_USER -p$MYSQL_PASSWORD
echo "✅ Restored $(basename $backup_file)"
db_name=$(basename "$backup_file" .sql.gz)
echo "Restoring database: $db_name"
# Restore with error handling for optional databases
if zcat "$backup_file" | mysql -h$MYSQL_HOST -P$MYSQL_PORT -u$MYSQL_USER -p$MYSQL_PASSWORD; then
echo "✅ Successfully restored $db_name"
else
echo "⚠️ Warning: Failed to restore $db_name (this may be normal for optional databases)"
fi
fi
done

View File

@@ -0,0 +1,47 @@
#!/bin/bash
# Test script to verify acore_playerbots database detection
# This script simulates the database detection logic without running an actual backup
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}
echo "=== Testing AzerothCore Database Detection ==="
echo ""
# Core databases
DATABASES=("acore_auth" "acore_world" "acore_characters")
echo "Core databases: ${DATABASES[@]}"
# Test if acore_playerbots database exists
echo ""
echo "Testing for 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 - would be included in backup"
else
echo " acore_playerbots database not found - would be skipped (this is normal for some installations)"
fi
echo ""
echo "Final database list that would be backed up: ${DATABASES[@]}"
echo ""
# Test connection to each database that would be backed up
echo "Testing connection to each database:"
for db in "${DATABASES[@]}"; do
if mysql -h$MYSQL_HOST -P$MYSQL_PORT -u$MYSQL_USER -p$MYSQL_PASSWORD -e "USE $db; SELECT 'OK' as status;" 2>/dev/null | grep -q OK; then
echo "$db: Connection successful"
else
echo "$db: Connection failed"
fi
done
echo ""
echo "=== Database Detection Test Complete ==="