I know you want to write your own script, but take a look at rsnapshot [1]. I've been using it for a while to backup my systems at home and it's been delightful. Just a small program based on rsync that handles backups in a nice simple, more space efficient, and automated way.
[1] http://rsnapshot.org/ -- Samuel Baldwin - logik.li