scripts/backup.sh
2024-02-10 22:39:41 -07:00

24 lines
645 B
Bash

#!/bin/bash
# Check if the required parameters are provided
if [ "$#" -ne 2 ]; then
echo "Usage: $0 <source_folder> <destination_folder>"
exit 1
fi
# Source and destination folders
source_folder="$1"
destination_folder="$2"
# Extract the last folder of the source path
source_folder_name=$(basename "$source_folder")
# Log file path based on the specified format
log_file="/var/log/backup-${source_folder_name}.log"
# Run rsync with the appropriate options and log the output
rsync -av --delete "$source_folder/" "$destination_folder/" >> "$log_file" 2>&1
# Log completion message
echo "Backup completed on $(date)" >> "$log_file"