22 October 2010

My backup script (improved)

Some months ago I published "Backup with rsync" one of my shell scripts because I had tried several backup utilities but none suited my needs. But as so many things in life you  never finish a script. You keep on thinking about different ways to improve it. So it grows bigger and (hopefully) better. I have changed the location of the backup, instead of using a usb pendrive I bought a toshiba usb hard drive (1Tb) and added two useful features. One is the date and time in the log file and the other is that the script now sends me an e-mail with the log file.
I started working with mutt including the log file as an attachment but I think that this way it is even easier. Nevertheless I think I'll continue working with the script. I might use it to make remote backups.

Feel free to use it or adapt it to your liking and also to let me know if it useful for you. Here it is:

#! /bin/bash

#This is a very simple backup script using rsync. It copies files to a (local) usb hard drive       asuming that it is already mounted. If not, I recommend using pmount.
# The ampersand sign is used to redirect standard error to a logfile.
# I use it with anacron. (15 minutes after startup)
# I have added date and time as useful information.
# I have also added a line to send me a daily report to my e-mail address. #MAD short for Mail ADdress
rsync -rlptoDvh  --delete /home/chals/*. /media/USB-HDD/backups &> asb.log
echo $(date) >> asb.log
mail -s "Automatically Sent Backup report" $MAD < /asb.log