66 lines
2.0 KiB
Bash
66 lines
2.0 KiB
Bash
#!/bin/bash
|
|
|
|
# Load backup logic functions
|
|
source /home/jelastic/mb-backups/backup-logic.sh
|
|
|
|
# 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'
|
|
backupPath='/mnt/backups'
|
|
password_file="/etc/restic-password"
|
|
LOG_DIR="/home/jelastic/mb-backups/logs/manual/media"
|
|
LOG_FILE="${LOG_DIR}/backup_media_$(date +'%Y-%m-%d').log"
|
|
includePaths=("$APP_PATH/wp-content/uploads")
|
|
|
|
# Ensure log directory exists
|
|
mkdir -p "$LOG_DIR"
|
|
|
|
# Set Restic environment variables
|
|
export RESTIC_REPOSITORY="$backupPath"
|
|
export RESTIC_PASSWORD
|
|
|
|
# Logging start
|
|
echo "[$(date +'%Y-%m-%d %H:%M:%S')] Starting Media and Themes Backup" | tee -a "$LOG_FILE"
|
|
|
|
# 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
|
|
|
|
# Perform media backup with additional tag
|
|
for path in "${includePaths[@]}"; do
|
|
if restic backup "$path" --tag media_themes --tag "$ADDITIONAL_TAG"; then
|
|
echo "[$(date +'%Y-%m-%d %H:%M:%S')] Backup completed successfully for $path with tags: media_themes, $ADDITIONAL_TAG." | tee -a "$LOG_FILE"
|
|
else
|
|
echo "[$(date +'%Y-%m-%d %H:%M:%S')] ERROR: Backup failed for $path." | tee -a "$LOG_FILE"
|
|
exit 1
|
|
fi
|
|
done
|
|
|
|
# Logging end
|
|
echo "[$(date +'%Y-%m-%d %H:%M:%S')] Media and Themes Backup process finished." | tee -a "$LOG_FILE"
|