scripts/rsync.sh

53 lines
1.3 KiB
Bash
Raw Normal View History

2021-01-21 16:58:32 -05:00
#!/usr/bin/env bash
#
# Backup automation to off-site storage service
#
#
# Note: This script is not portable
# License: Anyone is free to use and modify it
#
function send_notification
{
echo "Sending notification."
echo $2 | mail -s "$1" ${EMAIL}
}
CONF=$1
TODAY=`date`
HOSTNAME=`hostname -f`
CURR_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
BOOTSTRAP=${CURR_DIR}/bootstrap.sh
if [ ! -e $CONF ] || [ -z "${CONF}" ];then
echo 'EXITING: Missing configuration file'
exit 1
fi
source $CONF
if [ ! -e $BOOTSTRAP ];then
echo 'EXITING: boostrap.sh must be in the same directory as this script'
exit 1
fi
source $BOOTSTRAP
echo "RYSNC CRON: Syncing local directory to remote server"
run_cmd "rsync ${RSYNC_OPTIONS} ${RSYNC_LOCAL_PATH} ${RSYNC_REMOTE_PATH}"
if [ ${__returnstatus} != 0 ]; then
echo "RYSNC CRON: Failed to sync files..."
echo "RYSNC CRON: Additional information stored in ${LOG}..."
send_notification "CRON: Failed to upload files to off-site storage on ${HOSTNAME}" "Failed to upload ${RSYNC_LOCAL_PATH} to off-site storage on ${TODAY}"
exit 1
fi
echo "Completed..."
send_notification "CRON: Uploaded files to off-site storage successfully on ${HOSTNAME}" "Completed uploading ${RSYNC_LOCAL_PATH} to off-site storage on ${TODAY}"
exit 0