cat /usr/bin/backup.sh #!/bin/bash # Author: Brice Burgess - bhb@iceburg.net # rbackup.sh -- secure backup to a remote machine using rsync. # Directories to backup. Separate with a space. Exclude trailing slash! SOURCES="/home/adnane/these" # IP or FQDN of Remote Machine RMACHINE=mydomaine.com # Remote username RUSER=root # Directory to backup to on the remote machine. This is where your backup(s) will be stored # Exclude trailing slash! RTARGET="/root/backup" # Your EXCLUDE_FILE tells rsync what NOT to backup. Leave it unchanged, missing or # empty if you want to backup all files in your SOURCES. If performing a # FULL SYSTEM BACKUP, ie. Your SOURCES is set to "/", you will need to make # use of EXCLUDE_FILE. The file should contain directories and filenames, one per line. # An example of a EXCLUDE_FILE would be: # /proc/ # /tmp/ # /mnt/ # *.SOME_KIND_OF_FILE EXCLUDE_FILE= # Comment out the following line to disable verbose output VERBOSE="-v" ####################################### ########DO_NOT_EDIT_BELOW_THIS_POINT######### ####################################### if ! ssh $RUSER@$RMACHINE "test -x $RTARGET"; then echo "Target directory on remote machine doesn't exist or bad permissions." echo "Exiting..." exit 2 fi echo "Verifying Sources..." for source in $SOURCES; do echo "Checking $source..." if [ ! -x $source ]; then echo "Error with $source!" echo "Directory either does not exist, or you do not have proper permissions." exit 2 fi done if [ -f $EXCLUDE_FILE ]; then EXCLUDE="--exclude-from=$EXCLUDE_FILE" fi echo "Sources verified. Running rsync..." for source in $SOURCES; do # Create directories in $RTARGET to mimick source directory hiearchy if ! ssh $RUSER@$RMACHINE "test -d $RTARGET/$source"; then ssh $RUSER@$RMACHINE "mkdir -p $RTARGET/$source" fi rsync $VERBOSE $EXCLUDE -a --delete -e ssh $source/ $RUSER@$RMACHINE:$RTARGET/$source/ done exit 0