Thursday, March 30, 2006

Backup using rsync

Backup using rsync #!/bin/sh # backup.sh -- backup to a local drive using rsync
# Directories to backup. Separate with a space. Exclude trailing slash! SOURCES="/home/wendy /home/daisy /var/mail"
Read More


# Directory to backup to. This is where your backup(s) will be stored.
# Exclude trailing slash! TARGET="/mnt/usb-harddrive/backup"
# Your EXCLUDE_FILE tells rsync what NOT to backup. Leave it unchanged 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="/path/to/your/exclude_file.txt"
# Comment out the following line to disable verbose output VERBOSE="-v" ########################### if [ ! -x $TARGET ]; then echo "Backup target does not exist or you don't have permission!" 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 $TARGET to mimick source directory hiearchy if [ ! -d $TARGET/$source ]; then mkdir -p $TARGET/$source fi rsync $VERBOSE --exclude=$TARGET/ $EXCLUDE -a --delete $source/ $TARGET/$source/ done exit 0

No comments: