From f4b5dcd9ae8d7c4682f31f8e27c74db2f8750b2b Mon Sep 17 00:00:00 2001 From: Anthony Date: Tue, 7 Jan 2025 00:30:34 +0800 Subject: [PATCH] Added import backup-logic.sh to mb-backups folder --- manifest.jps | 1 + scripts/imports/backup_database.sh | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/manifest.jps b/manifest.jps index 46f1ecd..8ccd6ef 100644 --- a/manifest.jps +++ b/manifest.jps @@ -319,6 +319,7 @@ actions: - mkdir -p /home/litespeed/mb-backups/logs/restore - chown -R litespeed:litespeed /home/litespeed/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_core_files.sh - curl -O https://deploy-proxy.mightybox.io/addons/mb-backup-manager/raw/branch/main/scripts/imports/backup_database.sh diff --git a/scripts/imports/backup_database.sh b/scripts/imports/backup_database.sh index 42f6656..5afe4aa 100644 --- a/scripts/imports/backup_database.sh +++ b/scripts/imports/backup_database.sh @@ -20,18 +20,20 @@ backupPath='/mnt/backups' password_file="/etc/restic-password" LOG_DIR="/home/jelastic/mb-backups/logs" 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_PASSWORD='gaQjveXl24Xo66w' # Ensure log directory exists mkdir -p "$LOG_DIR" -# Set Restic environment variables +# Set Restic and MySQL environment variables export RESTIC_REPOSITORY="$backupPath" export RESTIC_PASSWORD # Updated to use the command line argument 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 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_backup_repo if [ $? -ne 0 ]; then @@ -60,7 +68,7 @@ if [ $? -ne 0 ]; then fi # 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" else echo "[$(date +'%Y-%m-%d %H:%M:%S')] ERROR: Database backup failed." | tee -a "$LOG_FILE"