Backup Your Files

One of the worst experiences you can have as a computer operator is to realize you (or something else) just did something and wiped out your files. The purpose of this article is to show you how to automatically backup your files often and automatically. I use this setup to backup my documents every hour (I save more often then that). This gives me hourly versions of all my files I am working on. It even protects me from accidentally saving over an important document (at least to the last hour).

Install Rsync-incr

You could do everything you need with Rsync… but our goal here is easy and automatic. Rsync-incr is a nice shell script that uses Rsync to do incremental backups, surrounding it with an easy interface. Win Win.. The stability of Rsync, with an easy to use interface.


Go here to download Rsync-incr


Install it by copying it to a good location. I use /usr/local/sbin/ or /usr/local/bin depending on if I am an admin on the system, or just a user on a shared host.

make sure to set the permissions as executable.

# chmod +x rsync-incr

Setup Cron to run hourly (or more often)

create a new file in /etc/cron.hourly/ and place these contents into it..

# vim /etc/cron.hourly/myDocuments-backup

Now it’s time to configure your backups.. I usually place my backups on a different drive. On my system /home is one drive and / is my other (each have multiple few partitions).

the syntax is rsync-incr <options> N From To N = the maximum number of copies to keep. N with ‘m’ after is (eg 50m) will keep the backups below that size requirement

We use the option –snap. This will create incremental copies with the appearance of full copies (by using hard links).

#!/bin/bash path=/usr/local/bin myfiles=/home/sfrancia/documents backupPath=/usr/local/backup/home/sfrancia/documents $path/rsync-incr --snap 48 $myfiles $backupPath 2>&1

Make sure it is executable.

# chmod +x /etc/cron.hourly/myDocuments-backup

I usually test it simply run that cron file from the command line.

# /etc/cron.hourly/myDocuments-backup

Restoring a Backup

To restore a backup, use standard rsync (trailing slashes are IMPORTANT):

# rsync -HSax --delete --force backup / original /

Related articles