mb-backup-manager/scripts/imports/backup_core_files.sh

72 lines
2.0 KiB
Bash
Raw Normal View History

2024-09-18 16:53:20 +00:00
#!/bin/bash
2024-11-12 18:15:11 +00:00
# Load the backup logic functions
source /home/jelastic/mb-backups/backup-logic.sh
2024-09-18 16:53:20 +00:00
# Check for required arguments
if [ $# -ne 2 ]; then
echo "Usage: $0 <RESTIC_PASSWORD> <ADDITIONAL_TAG>"
exit 1
fi
# Assign arguments to variables
RESTIC_PASSWORD="$1"
ADDITIONAL_TAG="$2"
# Configuration
APP_PATH='/var/www/webroot/ROOT'
backupPath='/mnt/backups'
2024-11-12 18:15:11 +00:00
password_file="/etc/restic-password"
2024-09-18 16:53:20 +00:00
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
2024-11-12 18:15:11 +00:00
# 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
2024-09-18 16:53:20 +00:00
# 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"
2024-11-12 18:15:11 +00:00
exit 1
2024-09-18 16:53:20 +00:00
fi
# Logging end
echo "[$(date +'%Y-%m-%d %H:%M:%S')] Backup process finished." | tee -a "$LOG_FILE"