Created
September 19, 2013 05:36
-
-
Save gegere/6619457 to your computer and use it in GitHub Desktop.
This is the cheapest of cheapo you will find for a script that performs remote backups using simply rsync, a destination host, and a directory on that destination host to store the backups.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Cheap Rsync System for Remote Backups | |
# | |
# This is the cheapest of cheapo you will find for a script | |
# that performs remote backups using simply rsync, a destination | |
# host, and a directory on that destination host to store the backups. | |
# | |
# Author: Jason Gegere | |
# Date: 11-21-2006, 9:29AM CST | |
################# | |
# CONFIGURATION # | |
################# | |
ADMIN_EMAIL="email@example.com" | |
BACKUP_DIRS="/home/cheap_rsync4/beta2/" | |
MY_HOST="beta2" | |
DESTINATION_HOST="host.domain.com" | |
DESTINATION_DIR="/var/dev/$MY_HOST/" | |
BACKUP_USER="cheap_rsync42" | |
BANDWIDTH_LIMIT=3047 #In Kilobytes | |
################### | |
# EMAIL PROCEDURE # | |
################### | |
bad_email() { | |
echo "A backup failed on $MY_HOST while attempting to backup $1 over to $2:$3" | mail -s "Cheap Rsync - BACKUP FAILURE - $MY_HOST" $ADMIN_EMAIL | |
} | |
################## | |
# MAIN PROCEDURE # | |
################## | |
backup_main() { | |
echo -e "Preparing to backup directories ...\n" | |
for Dir in $BACKUP_DIRS; do | |
echo -e "Backing up '$Dir' to $DESTINATION_HOST:$DESTINATION_DIR ..." | |
if [ -d $Dir ]; then | |
echo -e "Running rsync command ..." | |
lstat=`rsync -rtavze 'ssh -p 22' --delete --numeric-ids --bwlimit=$BANDWIDTH_LIMIT $Dir $BACKUP_USER@$DESTINATION_HOST:$DESTINATION_DIR` | |
if [ "$lstat" = "" ]; then | |
echo -e "There was a problem rsync'ing $Dir!" | |
bad_email $Dir $DESTINATION_HOST $DESTINATION_DIR | |
else | |
good_dirs[${#good_dirs[@]}]=$Dir | |
fi | |
else | |
echo -e "$Dir is invalid, unreadable or not a directory!" | |
bad_email $Dir $DESTINATION_HOST $DESTINATION_DIR | |
fi | |
done; | |
# if [ ${#good_dirs[@]} -gt 0 ]; then | |
# echo -e "Backups were successful on $MY_HOST:\n\n${good_dirs[@]}" | mail -s "Cheap Rsync - BACKUP COMPLETE - $MY_HOST" $ADMIN_EMAIL | |
# fi | |
} | |
backup_main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment