The following is a script I use to make a set up backups from a remote host using rsync. Because the script uses hard links a week's worth of backups rarely takes more than 20% more space than the backup for a single day.
Just a note: near the first of the year the date commands seem to be a bit screwy. Someone who feels like looking more closely at this can tell me why, otherwise I'm not going to worry about it.
#!/bin/sh # Incremental backup script for bash, based on rsync, syncs files on chiba # to this machine. One sync is made every night, incrementals are handled # with hardlinks to unchanged files. # # Once a week the newest daily snapshot becomes the newest weekly snapshot, # and once a month the newest weekly snapshot becomes the newest monthly # snapshot, and we will hold three months of backups. Becuase of the hardlinks # we should be able to keep increments without wasting much more space than # a simple full backup would already take. # Start by setting variables: current month, dead month, current week, # dead week, current day, and dead day MONTH=chiba.monthly.`date +%G-%m` WEEK=chiba.weekly.`date +%G-%V` DAY=chiba.daily.`date +%G-%m-%d` YESTERDAY=chiba.daily.`date -d -1day +%G-%m-%d` DEADMONTH=chiba.monthly.`date -d -3month +%G-%m` DEADWEEK=chiba.weekly.`date -d -4week +%G-%V` DEADDAY=chiba.daily.`date -d -7day +%G-%m-%d` # Rotate the daily backup files. Start by tossing the latest dead file, # and then create the latest backup with rsync, using hard links. # This happens every day if [ -d /home/backup/$DEADDAY ]; then rm -rf /home/backup/$DEADDAY fi rsync -plrtvz --delete --rsh='ssh -c blowfish' --ignore-errors \ --stats --progress --link-dest=/home/backup/$YESTERDAY \ scblock@chiba.tessier.com:/home/scblock/ /home/backup/$DAY/ # Check if it is Saturday. If so, rotate the weekly backups. Start by tossing # the latest dead file, and then copy the latest daily snapshot to the # weekly snapshot file if [ `date +%u` = 6 ]; then if [ -d /home/backup/$DEADWEEK ]; then rm -rf /home/backup/$DEADWEEK fi cp -al /home/backup/$DAY /home/backup/$WEEK fi # Check if it is the first of the month. If so, rotate the monthly backups. # Start by tossing the latest dead file, and then copy the latest daily # Snapshot to the monthly snapshot file. if [ `date +%d` = 1 ]; then if [ -d /home/backup/$DEADMONTH ]; then rm -rf /home/backup/$DEADMONTH ]; fi cp -al /home/backup/$DAY /home/backup/$MONTH fi