#!/bin/bash # Load the backup logic functions source /home/jelastic/mb-backups/backup-logic.sh # Check for required arguments if [ $# -ne 2 ]; then echo "Usage: $0 " exit 1 fi # Assign arguments to variables RESTIC_PASSWORD="$1" ADDITIONAL_TAG="$2" # Configuration APP_PATH='/var/www/webroot/ROOT' backupPath='/mnt/backups' password_file="/etc/restic-password" LOG_DIR="/home/jelastic/mb-backups/logs" LOG_FILE="${LOG_DIR}/backup_core_files_$(date +'%Y-%m-%d').log" excludePaths=( "$APP_PATH/wp-content/uploads" ) # Ensure log directory exists mkdir -p "$LOG_DIR" # Set Restic environment variables export RESTIC_REPOSITORY="$backupPath" export RESTIC_PASSWORD # Verify that the password file exists and matches the supplied password if [ ! -f "$password_file" ]; then echo "ERROR: Password file not found at $password_file" | tee -a "$LOG_FILE" exit 1 fi # Load and verify password from the file stored_password=$(cat "$password_file") if [ "$stored_password" != "$RESTIC_PASSWORD" ]; then echo "ERROR: Password mismatch. Aborting backup." | tee -a "$LOG_FILE" exit 1 fi # Check repository accessibility and integrity check_backup_repo if [ $? -ne 0 ]; then echo "[$(date +'%Y-%m-%d %H:%M:%S')] ERROR: Backup repository check failed. Aborting backup." | tee -a "$LOG_FILE" exit 1 fi # Logging start echo "[$(date +'%Y-%m-%d %H:%M:%S')] Starting Core Files Backup with tags: core_files, $ADDITIONAL_TAG" | tee -a "$LOG_FILE" # Building exclude options excludeOptions="" for path in "${excludePaths[@]}"; do excludeOptions+="--exclude $path " done # Perform backup with both tags if restic backup $excludeOptions "$APP_PATH" --tag core_files --tag "$ADDITIONAL_TAG"; then echo "[$(date +'%Y-%m-%d %H:%M:%S')] Core files backup completed successfully." | tee -a "$LOG_FILE" else echo "[$(date +'%Y-%m-%d %H:%M:%S')] ERROR: Core files backup failed." | tee -a "$LOG_FILE" exit 1 fi # Logging end echo "[$(date +'%Y-%m-%d %H:%M:%S')] Backup process finished." | tee -a "$LOG_FILE"