Rsync is a well known tool for many who work in Linux regularly. Quite some time ago I put together a short script that uses Rsync and logs the result nicely. The first task Rsync performs is to send an incremental file list which contains any differences between the source and destination drive, then makes changes to the destination drive accordingly. Because of that last part extreme caution should be used when executing such a script because you run the risk of overwriting information on the destination drive you may not want removed. I have a dedicated drive for DV backups mounted in /media/dv-backup. To use this script just change the variables accordingly:
#!/bin/bash #dv backup script src=/media/dv dest=/media/dv-backup log=/var/log/backup/dv-backup.log echo "---" $date "-------------------" >> $log rsync -t -r -v --delete $src $dest >> $log echo "--------------- END ---------------" >> $log
I have my backups log in /var/log/backup/ and they merely append the file each time Rsync runs. I’m aware this is quite a simple script and could even be consolidated to one line. However, I found that breaking this up makes it easy to read and change. Also, who wants to remember every Rsync switch they want each time they want to perform a differential backup?
One quick change you could make to make it require less manually editing is replace the variables to take the terminal arguments. Such a revision is listed below:
src=$1 dest=$2 log=$3 echo "---" $date "-------------------" >> $log rsync -t -r -v --delete $src $dest >> $log echo "--------------- END ---------------" >> $log
Usage to achieve same result as original:
./backup.sh /media/dv /media/dv-backup /var/log/backup/dv-backup.log
Both script revisions are attached: backup.sh backup2.sh Use at your own risk.. don’t blame me if you incorrectly wipe a drive!
