#!/bin/bash # Exit on error set -e # Validate input parameters if [ "$#" -ne 2 ]; then echo "Usage: $0 " exit 1 fi # Assign arguments to variables RESTIC_PASSWORD="$1" CUSTOM_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 # Start logging echo "[$(date +'%Y-%m-%d %H:%M:%S')] Starting Media Backup with tags: media_themes, $CUSTOM_TAG" | tee -a "$LOG_FILE" # Verify password file exists if [ ! -f "$password_file" ]; then echo "ERROR: Password file not found at $password_file" | tee -a "$LOG_FILE" exit 1 fi # Verify repository access if ! restic snapshots > /dev/null 2>&1; then echo "ERROR: Unable to access the restic repository. Aborting backup." | tee -a "$LOG_FILE" exit 1 fi # Perform the backup for path in "${includePaths[@]}"; do if restic backup "$path" \ --tag media_themes \ --tag "$CUSTOM_TAG" \ --force \ --option b2.connections=4; then echo "[$(date +'%Y-%m-%d %H:%M:%S')] Backup completed successfully for $path with tags: media_themes, $CUSTOM_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 # End logging echo "[$(date +'%Y-%m-%d %H:%M:%S')] Media Backup process finished." | tee -a "$LOG_FILE"