diff --git a/bash_scripts/backup.sh b/bash_scripts/backup.sh new file mode 100755 index 0000000..d51a55e --- /dev/null +++ b/bash_scripts/backup.sh @@ -0,0 +1,25 @@ +#!/bin/bash + + +# Check to make sure the user has entered exactly two arguments. +if [ $# -ne 2 ] +then + echo "Usage backup.sh " + 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