Files
first_gitea/bash_scripts/backup.sh
2025-12-16 12:02:24 +00:00

26 lines
667 B
Bash
Executable File

#!/bin/bash
# Check to make sure the user has entered exactly two arguments.
if [ $# -ne 2 ]
then
echo "Usage backup.sh <source_directory> <target_directory>"
echo "Please try again."
exit 1
fi
# Check to see if rsync is installed
if ! command -v rsync > /dev/null 2>&1
then
echo "This script requires rsync to be installed."
echo "Please use your distribution's package manager to install and try again."
exit 2
fi
# Capture the current date and store it to the format YYYY-MM-DD
current_date=$(date +%Y-%m-%d_%H-%M-%S)
rsync_options="-avb --backup-dir $2/$current_date --delete "
$(which rsync) $rsync_options $1 $2/current >> backup_$current_date.log