47 lines
1.6 KiB
Bash
47 lines
1.6 KiB
Bash
|
#!/bin/bash
|
||
|
|
||
|
# Validate input parameters
|
||
|
if [ "$#" -ne 2 ]; then
|
||
|
echo "Usage: $0 <RESTIC_PASSWORD> <ADDITIONAL_TAG>"
|
||
|
exit 1
|
||
|
fi
|
||
|
|
||
|
# Assign command line arguments to variables
|
||
|
RESTIC_PASSWORD="$1"
|
||
|
ADDITIONAL_TAG="$2"
|
||
|
|
||
|
# Configuration
|
||
|
APP_PATH='/var/www/webroot/ROOT'
|
||
|
WP_CONFIG="${APP_PATH}/wp-config.php"
|
||
|
backupPath='/mnt/backups'
|
||
|
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
|
||
|
BACKUP_USER='wp_backup'
|
||
|
BACKUP_PASSWORD='gaQjveXl24Xo66w'
|
||
|
|
||
|
# Ensure log directory exists
|
||
|
mkdir -p "$LOG_DIR"
|
||
|
|
||
|
# Set Restic 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
|
||
|
|
||
|
# Logging start
|
||
|
echo "[$(date +'%Y-%m-%d %H:%M:%S')] Starting Database Backup with additional tag: $ADDITIONAL_TAG" | tee -a "$LOG_FILE"
|
||
|
|
||
|
# Perform backup with additional tag
|
||
|
if mysqldump -u "$BACKUP_USER" "$DB_NAME" | restic backup --stdin --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"
|
||
|
fi
|
||
|
|
||
|
# Logging end
|
||
|
echo "[$(date +'%Y-%m-%d %H:%M:%S')] Database Backup process finished." | tee -a "$LOG_FILE"
|