Backup with rsync a la time machine: a proof

I am struggling for backups since ever. I assume just like anybody. For my personal machines I used rsync in combination with my script Then I kept reading online about using rsync for incremental backups but I could not find any simple example. So I did this little script:

#! /bin/sh
#TESTING: DIRRSYNC="${HOME}/tmp/rs/rsyncBackup"
#mydate=`date +%Y%m%d-%H%M` #FORMAT: 20130131-2226 / Windows SMB / Samba with --modify-window=1
mydate=`date +%Y%m%d-%H%M%S` #FORMAT: 20130131-222618
OPTRSYNC="-av --delete --backup"
if [ -z $1 ]; then
echo "please give a dir name."
exit 1;
PRJDIR=`basename ${1}`
DIRBKPUP=" --backup-dir=${DIRBACKUPS}/${PRJDIR}/B-${mydate}"
#rsync --dry-run ${OPTRSYNC} ${DIRBKPUP} $1 ${DIRRSYNC}/${PRJDIR}
echo "Running: " rsync ${OPTRSYNC} ${DIRBKPUP} $1 ${DIRRSYNC}/${PRJDIR}
# Create List Files
if [ -d ${DIRBACKUPS}/${PRJDIR} ]; then
find ${PRJDIR}/B-${mydate} > ${PRJDIR}/B-${mydate}.filelist

I have to admit that instead to google it for years, I could have just read the rsync manual page in details.

It is currently available also at:

How does it works? This is an extract of the current README:


In principle it works much alike the Mac OS time machine.

You need first to define a backup directory (which can be on a network disk, any which shows up as path on your system. For example I have a samba mounted on my macbook). This is this line in the script:


The rest is preconfigured, but check the script which is really few lines.

Then DirToBackUp

will create a directory ‘/Volumes/ExtDisk/MacBackUp/DirToBackUp’ which is a copy of your original dir, and eventually later a directory ‘/Volumes/ExtDisk/MacBackUp-BP/DirToBackUp/B-‘ which contains deleted and changed files old versions.

The script is in very beta but a starting point.

It creates also a file list for the ‘/Volumes/ExtDisk/MacBackUp-BP/DirToBackUp/B-‘ directory.

The idea is that if you look for a file, you know already which file on your current system, and you might need to look only on the old backups, like:

grep myfile /Volumes/ExtDisk/MacBackUp-BP/DirToBackUp/*.filelist

The backup destination is hardcoded. My idea is to use the script in the future as a templates and create scripts like:, and use them in a cron job with only the requested backup directory as parameter.

This because we might need different options depending on the destination. One option is already mentioned as comment in the script: ‘–modify-window=1’. This is used when for example you are working with Samba, SMB, or Windows destinations as you might end up on a file system which has only a 1 minute (+-1 implicit) time difference stored for file dates.


Now I can keep using ‘’ to archive old incremental backups!

Please keep up to date on github for the future of this script. If you feel to participate, I will be very happy, backup is a problem which will probably never end.



One comment

  1. Pingback: Backup with rsync a la Time Machine ™: Call for help | FM Techottis

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s