mirror of
https://github.com/uprightbass360/AzerothCore-RealmMaster.git
synced 2026-01-13 09:07:20 +00:00
enhance backup process and remove dashboards
This commit is contained in:
@@ -19,6 +19,7 @@ services:
|
||||
- "${MYSQL_EXTERNAL_PORT}:${MYSQL_PORT}"
|
||||
volumes:
|
||||
- ${STORAGE_PATH}/mysql-data:/var/lib/mysql-persistent
|
||||
- ${HOST_BACKUP_PATH}:/backups
|
||||
- type: tmpfs
|
||||
target: /var/lib/mysql-runtime
|
||||
tmpfs:
|
||||
@@ -26,26 +27,107 @@ services:
|
||||
entrypoint: ["/bin/bash", "-c"]
|
||||
command:
|
||||
- |
|
||||
echo "🔧 Starting MySQL with NFS-compatible setup..."
|
||||
echo "🔧 Starting MySQL with NFS-compatible setup and auto-restore..."
|
||||
mkdir -p /var/lib/mysql-runtime
|
||||
chown -R mysql:mysql /var/lib/mysql-runtime
|
||||
chmod 755 /var/lib/mysql-runtime
|
||||
|
||||
if [ -f "/var/lib/mysql-persistent/backup.sql" ]; then
|
||||
echo "📦 SQL backup found, will restore after MySQL starts..."
|
||||
# Check if MySQL data directory is empty (fresh start)
|
||||
if [ ! -d "/var/lib/mysql-runtime/mysql" ]; then
|
||||
echo "🆕 Fresh MySQL installation detected..."
|
||||
|
||||
# Check for available backups (prefer daily, fallback to hourly, then legacy)
|
||||
if [ -d "/backups" ] && [ "$(ls -A /backups)" ]; then
|
||||
# Try daily backups first
|
||||
if [ -d "/backups/daily" ] && [ "$(ls -A /backups/daily)" ]; then
|
||||
LATEST_BACKUP=$(ls -1t /backups/daily | head -n 1)
|
||||
if [ -n "$LATEST_BACKUP" ] && [ -d "/backups/daily/$LATEST_BACKUP" ]; then
|
||||
echo "📦 Latest daily backup found: $LATEST_BACKUP"
|
||||
echo "🔄 Will restore after MySQL initializes..."
|
||||
export RESTORE_BACKUP="/backups/daily/$LATEST_BACKUP"
|
||||
fi
|
||||
# Try hourly backups second
|
||||
elif [ -d "/backups/hourly" ] && [ "$(ls -A /backups/hourly)" ]; then
|
||||
LATEST_BACKUP=$(ls -1t /backups/hourly | head -n 1)
|
||||
if [ -n "$LATEST_BACKUP" ] && [ -d "/backups/hourly/$LATEST_BACKUP" ]; then
|
||||
echo "📦 Latest hourly backup found: $LATEST_BACKUP"
|
||||
echo "🔄 Will restore after MySQL initializes..."
|
||||
export RESTORE_BACKUP="/backups/hourly/$LATEST_BACKUP"
|
||||
fi
|
||||
# Try legacy backup structure last
|
||||
else
|
||||
LATEST_BACKUP=$(ls -1t /backups | head -n 1)
|
||||
if [ -n "$LATEST_BACKUP" ] && [ -d "/backups/$LATEST_BACKUP" ]; then
|
||||
echo "📦 Latest legacy backup found: $LATEST_BACKUP"
|
||||
echo "🔄 Will restore after MySQL initializes..."
|
||||
export RESTORE_BACKUP="/backups/$LATEST_BACKUP"
|
||||
else
|
||||
echo "🆕 No valid backups found, will initialize fresh..."
|
||||
fi
|
||||
fi
|
||||
else
|
||||
echo "🆕 No backup directory found, will initialize fresh..."
|
||||
fi
|
||||
else
|
||||
echo "🆕 No backup found, will initialize fresh MySQL..."
|
||||
echo "📁 Existing MySQL data found, skipping restore..."
|
||||
fi
|
||||
|
||||
echo "🚀 Starting MySQL server with custom datadir..."
|
||||
exec docker-entrypoint.sh mysqld \
|
||||
--datadir=/var/lib/mysql-runtime \
|
||||
--default-authentication-plugin=mysql_native_password \
|
||||
--character-set-server=${MYSQL_CHARACTER_SET} \
|
||||
--collation-server=${MYSQL_COLLATION} \
|
||||
--max_connections=${MYSQL_MAX_CONNECTIONS} \
|
||||
--innodb-buffer-pool-size=${MYSQL_INNODB_BUFFER_POOL_SIZE} \
|
||||
--innodb-log-file-size=${MYSQL_INNODB_LOG_FILE_SIZE}
|
||||
|
||||
# Start MySQL in background for potential restore
|
||||
if [ -n "$RESTORE_BACKUP" ]; then
|
||||
echo "⚡ Starting MySQL in background for restore operation..."
|
||||
docker-entrypoint.sh mysqld \
|
||||
--datadir=/var/lib/mysql-runtime \
|
||||
--default-authentication-plugin=mysql_native_password \
|
||||
--character-set-server=${MYSQL_CHARACTER_SET} \
|
||||
--collation-server=${MYSQL_COLLATION} \
|
||||
--max_connections=${MYSQL_MAX_CONNECTIONS} \
|
||||
--innodb-buffer-pool-size=${MYSQL_INNODB_BUFFER_POOL_SIZE} \
|
||||
--innodb-log-file-size=${MYSQL_INNODB_LOG_FILE_SIZE} &
|
||||
|
||||
MYSQL_PID=$!
|
||||
|
||||
# Wait for MySQL to be ready
|
||||
echo "⏳ Waiting for MySQL to become ready for restore..."
|
||||
while ! mysqladmin ping -h localhost -u root --silent; do
|
||||
sleep 2
|
||||
done
|
||||
|
||||
echo "🔄 MySQL ready, starting restore from $RESTORE_BACKUP..."
|
||||
|
||||
# Install curl for downloading restore script
|
||||
apt-get update && apt-get install -y curl
|
||||
|
||||
# Download restore script from GitHub
|
||||
curl -fsSL https://raw.githubusercontent.com/uprightbass360/acore-compose/main/scripts/restore.sh -o /tmp/restore.sh
|
||||
chmod +x /tmp/restore.sh
|
||||
|
||||
# Modify restore script to skip confirmation and use correct backup path
|
||||
sed -i 's/sleep 10/echo "Auto-restore mode, skipping confirmation..."/' /tmp/restore.sh
|
||||
sed -i 's/BACKUP_DIR=\${BACKUP_DIR:-\/backups}/BACKUP_DIR=\/backups/' /tmp/restore.sh
|
||||
sed -i 's/MYSQL_PASSWORD=\${MYSQL_PASSWORD:-password}/MYSQL_PASSWORD=${MYSQL_ROOT_PASSWORD}/' /tmp/restore.sh
|
||||
|
||||
# Extract timestamp from backup path and run restore
|
||||
BACKUP_TIMESTAMP=$(basename "$RESTORE_BACKUP")
|
||||
echo "🗄️ Restoring databases from backup: $BACKUP_TIMESTAMP"
|
||||
/tmp/restore.sh "$BACKUP_TIMESTAMP"
|
||||
|
||||
echo "✅ Database restore completed successfully!"
|
||||
|
||||
# Keep MySQL running in foreground
|
||||
wait $MYSQL_PID
|
||||
else
|
||||
# Normal startup without restore
|
||||
exec docker-entrypoint.sh mysqld \
|
||||
--datadir=/var/lib/mysql-runtime \
|
||||
--default-authentication-plugin=mysql_native_password \
|
||||
--character-set-server=${MYSQL_CHARACTER_SET} \
|
||||
--collation-server=${MYSQL_COLLATION} \
|
||||
--max_connections=${MYSQL_MAX_CONNECTIONS} \
|
||||
--innodb-buffer-pool-size=${MYSQL_INNODB_BUFFER_POOL_SIZE} \
|
||||
--innodb-log-file-size=${MYSQL_INNODB_LOG_FILE_SIZE}
|
||||
fi
|
||||
restart: unless-stopped
|
||||
healthcheck:
|
||||
test: ["CMD", "sh", "-c", "mysqladmin ping -h localhost -u ${MYSQL_USER} -p${MYSQL_ROOT_PASSWORD} --silent || exit 1"]
|
||||
@@ -67,41 +149,66 @@ services:
|
||||
MYSQL_USER: ${MYSQL_USER}
|
||||
MYSQL_PASSWORD: ${MYSQL_ROOT_PASSWORD}
|
||||
BACKUP_RETENTION_DAYS: ${BACKUP_RETENTION_DAYS}
|
||||
BACKUP_RETENTION_HOURS: ${BACKUP_RETENTION_HOURS}
|
||||
BACKUP_CRON_SCHEDULE: ${BACKUP_CRON_SCHEDULE}
|
||||
BACKUP_DIR: ${BACKUP_DIR}
|
||||
DB_AUTH_NAME: ${DB_AUTH_NAME}
|
||||
DB_WORLD_NAME: ${DB_WORLD_NAME}
|
||||
DB_CHARACTERS_NAME: ${DB_CHARACTERS_NAME}
|
||||
TZ: ${TZ}
|
||||
volumes:
|
||||
- ${HOST_BACKUP_PATH}:/backups
|
||||
- ${HOST_BACKUP_SCRIPTS_PATH}:/scripts
|
||||
working_dir: /scripts
|
||||
working_dir: /tmp
|
||||
command:
|
||||
- /bin/bash
|
||||
- -c
|
||||
- |
|
||||
echo "🔧 Starting backup service using external script..."
|
||||
echo "🔧 Starting enhanced backup service with hourly and daily schedules..."
|
||||
|
||||
# Make sure backup script is executable
|
||||
chmod +x /scripts/backup.sh
|
||||
# Install curl if not available
|
||||
apt-get update && apt-get install -y curl
|
||||
|
||||
# Download backup scripts from GitHub
|
||||
echo "📥 Downloading backup scripts from GitHub..."
|
||||
curl -fsSL https://raw.githubusercontent.com/uprightbass360/acore-compose/main/scripts/backup.sh -o /tmp/backup.sh
|
||||
curl -fsSL https://raw.githubusercontent.com/uprightbass360/acore-compose/main/scripts/backup-hourly.sh -o /tmp/backup-hourly.sh
|
||||
curl -fsSL https://raw.githubusercontent.com/uprightbass360/acore-compose/main/scripts/backup-daily.sh -o /tmp/backup-daily.sh
|
||||
chmod +x /tmp/backup.sh /tmp/backup-hourly.sh /tmp/backup-daily.sh
|
||||
|
||||
# Wait for MySQL to be ready before starting backup service
|
||||
echo "⏳ Waiting for MySQL to be ready..."
|
||||
sleep 30
|
||||
|
||||
# Run initial backup
|
||||
echo "🚀 Running initial backup..."
|
||||
/scripts/backup.sh
|
||||
# Run initial daily backup
|
||||
echo "🚀 Running initial daily backup..."
|
||||
/tmp/backup-daily.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"
|
||||
# Enhanced scheduler with hourly and daily backups
|
||||
echo "⏰ Starting enhanced backup scheduler:"
|
||||
echo " 📅 Daily backups: ${BACKUP_CRON_SCHEDULE} (retention: ${BACKUP_RETENTION_DAYS} days)"
|
||||
echo " ⏰ Hourly backups: every hour (retention: ${BACKUP_RETENTION_HOURS} hours)"
|
||||
|
||||
# Track last backup times to avoid duplicates
|
||||
last_daily_hour=""
|
||||
last_hourly_minute=""
|
||||
|
||||
while true; do
|
||||
current_hour=$(date +%H)
|
||||
current_minute=$(date +%M)
|
||||
current_time="$current_hour:$current_minute"
|
||||
|
||||
# Check if it's 3:00 AM (matching default cron schedule)
|
||||
if [ "$$current_hour" = "03" ] && [ "$$current_minute" = "00" ]; then
|
||||
echo "⏰ [$(date)] Scheduled backup time reached, running backup..."
|
||||
/scripts/backup.sh
|
||||
# Daily backup check (9:00 AM)
|
||||
if [ "$$current_hour" = "09" ] && [ "$$current_minute" = "00" ] && [ "$$last_daily_hour" != "$$current_hour" ]; then
|
||||
echo "📅 [$(date)] Daily backup time reached, running daily backup..."
|
||||
/tmp/backup-daily.sh
|
||||
last_daily_hour="$$current_hour"
|
||||
# Sleep for 2 minutes to avoid running multiple times
|
||||
sleep 120
|
||||
# Hourly backup check (every hour at minute 0, except during daily backup)
|
||||
elif [ "$$current_minute" = "00" ] && [ "$$current_hour" != "09" ] && [ "$$last_hourly_minute" != "$$current_minute" ]; then
|
||||
echo "⏰ [$(date)] Hourly backup time reached, running hourly backup..."
|
||||
/tmp/backup-hourly.sh
|
||||
last_hourly_minute="$$current_minute"
|
||||
# Sleep for 2 minutes to avoid running multiple times
|
||||
sleep 120
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user