yet another backup script

After reading the excellent Easy Automated Snapshot-Style Backups with Linux and Rsync, I deicided to make a new backup script for my home directory that would keep the last 9 incremental snapshots.

Here is the resulting script:

#!/bin/bash
if [ -n "$1" ] ; then
	FROM=$1
else
	FROM=/home/username
fi

if [ -n "$2" ] ; then
	TO=$2
else
	TO=/mnt/arc
fi

LINKTO=--link-dest=$TO/`basename $FROM`.1
OPTS="-Ca --delete --exclude-from=$FROM/bin/rsync-excluded -delete-excluded"
NUMBER_OF_BACKUPS=10


find $TO -maxdepth 1 -type d -name '*.[0-9]'| sort -rn| while read dir
do
	this=`expr match "$dir" '.*\([0-9]\)'`; 
	let next=($this+1)%$NUMBER_OF_BACKUPS;
	basedirname=${dir%.[0-9]}
	if [ $next -eq 0 ] ; then
		 rm -rf $dir
	else
		 mv $dir $basedirname.$next
	fi
done
rsync $OPTS $LINKTO $FROM/ $TO/`basename $FROM.0`

It would be nice to extend it to add the possibility to create an unlimited number of incremental backups.

P.S. In the plans: a detailed explanation of the payslip calculation in Belgium