Step 1: Assumptions
I use fedora, but you can use anything and just install rdiff-backup however you'd like.
Also it is available from download here: http://rdiff-backup.nongnu.org/
Step 3: Identify the directories you want to backup
Step 4: Automate
First thing in the script, we will check to see the usb drive is mounted, and quit if not.
#!/bin/bash
#Script to backup to usb drive
BACKUPBASE="/backups"
#check to see if backup target is mounted.
if `df -h | grep $BACKUPBASE >/dev/null `
then
echo "Starting $0 `date`"
else
echo "ERROR: $BACKUPBASE not mounted"
echo "$0 exiting `date` "
exit 1
fi
Step 5: Write a function
function backup {
DEST=$1$2
SOURCE=$2
echo "Src : $SOURCE"
if [-d $DEST]
then
echo "Dest: $DEST"
else
mkdir -p $DEST
echo "Dest: $DEST -created"
OPTS="--force"
fi
#Perform backup
rdiff-backup -v2 --exclude-special-files $OPTS $SOURCE $DEST
#Cleanup version files older than 4weeks
rdiff-backup -v2 --remove-older-than 4W --force $DEST
#Print a report of what we backed up and cleaned up
rdiff-backup --list-changed-since 0D23h00m $DEST
}
Step 6: Do Tell the script which dirs to backup
backup $BACKUPBASE /etc
backup $BACKUPBASE /usr/local
backup $BACKUPBASE /home
Step 7: The whole thing together now
#Script to backup to usb drive
BACKUPBASE="/backups"
#Check to see if backup drive is mounted.
if `df -h | grep $BACKUPBASE >/dev/null `
then
echo "Starting $0 `date`"
else
echo "ERROR: $BACKUPBASE not mounted"
echo "$0 exiting `date` "
exit 1
fi
function backup {
DEST=$1$2
SOURCE=$2
echo "Src : $SOURCE"
if [-d $DEST]
then
echo "Dest: $DEST"
else
mkdir -p $DEST
echo "Dest: $DEST -created"
OPTS="--force"
fi
#Perform backup
rdiff-backup -v2 --exclude-special-files $OPTS $SOURCE $DEST
#Cleanup version files older than 4weeks
rdiff-backup -v2 --remove-older-than 4W --force $DEST
#Print a report of what we backed up and cleaned up
rdiff-backup --list-changed-since 0D23h00m $DEST
}
backup $BACKUPBASE /data
backup $BACKUPBASE /etc
backup $BACKUPBASE /usr/local
backup $BACKUPBASE /home
Step 8: Add to cron
10 1 * * * /usr/local/scripts/backup-rdiff.sh > /var/log/backup.log 2>&1
Step 9: Restore
rdiff-backup -r 2D /backup/etc/named.conf /etc/named.conf
Simple and very effective.

















































Visit Our Store »
Go Pro Today »




Works a treat.