Added import backup-logic.sh to mb-backups folder

main
Anthony 2025-01-07 00:30:34 +08:00
parent bca47a3616
commit f4b5dcd9ae
2 changed files with 15 additions and 6 deletions

View File

@ -319,6 +319,7 @@ actions:
- mkdir -p /home/litespeed/mb-backups/logs/restore - mkdir -p /home/litespeed/mb-backups/logs/restore
- chown -R litespeed:litespeed /home/litespeed/mb-backups - chown -R litespeed:litespeed /home/litespeed/mb-backups
- cd /home/jelastic/mb-backups - cd /home/jelastic/mb-backups
- curl -O https://deploy-proxy.mightybox.io/addons/mb-backup-manager/raw/branch/main/scripts/backup-logic.sh
- curl -O https://deploy-proxy.mightybox.io/addons/mb-backup-manager/raw/branch/main/scripts/imports/backup_all.sh - curl -O https://deploy-proxy.mightybox.io/addons/mb-backup-manager/raw/branch/main/scripts/imports/backup_all.sh
- curl -O https://deploy-proxy.mightybox.io/addons/mb-backup-manager/raw/branch/main/scripts/imports/backup_core_files.sh - curl -O https://deploy-proxy.mightybox.io/addons/mb-backup-manager/raw/branch/main/scripts/imports/backup_core_files.sh
- curl -O https://deploy-proxy.mightybox.io/addons/mb-backup-manager/raw/branch/main/scripts/imports/backup_database.sh - curl -O https://deploy-proxy.mightybox.io/addons/mb-backup-manager/raw/branch/main/scripts/imports/backup_database.sh

View File

@ -20,18 +20,20 @@ backupPath='/mnt/backups'
password_file="/etc/restic-password" password_file="/etc/restic-password"
LOG_DIR="/home/jelastic/mb-backups/logs" LOG_DIR="/home/jelastic/mb-backups/logs"
LOG_FILE="${LOG_DIR}/backup_database_$(date +'%Y-%m-%d').log" LOG_FILE="${LOG_DIR}/backup_database_$(date +'%Y-%m-%d').log"
DB_NAME=$(grep "define( 'DB_NAME'" $WP_CONFIG | cut -d "'" -f 4)
DB_USER=$(grep "define( 'DB_USER'" $WP_CONFIG | cut -d "'" -f 4)
DB_PASSWORD=$(grep "define( 'DB_PASSWORD'" $WP_CONFIG | cut -d "'" -f 4)
# Backup user and password # Extract database credentials from wp-config.php
DB_NAME=$(grep "define( 'DB_NAME'" "$WP_CONFIG" | cut -d "'" -f 4)
DB_USER=$(grep "define( 'DB_USER'" "$WP_CONFIG" | cut -d "'" -f 4)
DB_PASSWORD=$(grep "define( 'DB_PASSWORD'" "$WP_CONFIG" | cut -d "'" -f 4)
# Backup user and password (optional)
BACKUP_USER='wp_backup' BACKUP_USER='wp_backup'
BACKUP_PASSWORD='gaQjveXl24Xo66w' BACKUP_PASSWORD='gaQjveXl24Xo66w'
# Ensure log directory exists # Ensure log directory exists
mkdir -p "$LOG_DIR" mkdir -p "$LOG_DIR"
# Set Restic environment variables # Set Restic and MySQL environment variables
export RESTIC_REPOSITORY="$backupPath" export RESTIC_REPOSITORY="$backupPath"
export RESTIC_PASSWORD # Updated to use the command line argument export RESTIC_PASSWORD # Updated to use the command line argument
export MYSQL_PWD=$BACKUP_PASSWORD # Use the backup user's password for mysqldump export MYSQL_PWD=$BACKUP_PASSWORD # Use the backup user's password for mysqldump
@ -52,6 +54,12 @@ if [ "$stored_password" != "$RESTIC_PASSWORD" ]; then
exit 1 exit 1
fi fi
# Verify backup path exists
if [ ! -d "$backupPath" ]; then
echo "ERROR: Backup path $backupPath does not exist." | tee -a "$LOG_FILE"
exit 1
fi
# Check repository accessibility and integrity # Check repository accessibility and integrity
check_backup_repo check_backup_repo
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
@ -60,7 +68,7 @@ if [ $? -ne 0 ]; then
fi fi
# Perform database backup with additional tag # Perform database backup with additional tag
if mysqldump -u "$BACKUP_USER" "$DB_NAME" | restic backup --stdin --tag wordpress_db --tag "$ADDITIONAL_TAG"; then if mysqldump -u "$BACKUP_USER" "$DB_NAME" | restic backup --stdin --stdin-filename "${DB_NAME}.sql" --tag wordpress_db --tag "$ADDITIONAL_TAG"; then
echo "[$(date +'%Y-%m-%d %H:%M:%S')] Database backup completed successfully with tags: wordpress_db, $ADDITIONAL_TAG." | tee -a "$LOG_FILE" echo "[$(date +'%Y-%m-%d %H:%M:%S')] Database backup completed successfully with tags: wordpress_db, $ADDITIONAL_TAG." | tee -a "$LOG_FILE"
else else
echo "[$(date +'%Y-%m-%d %H:%M:%S')] ERROR: Database backup failed." | tee -a "$LOG_FILE" echo "[$(date +'%Y-%m-%d %H:%M:%S')] ERROR: Database backup failed." | tee -a "$LOG_FILE"