Real-time backup

The main reason for moving to Lucid Lynx (Ubuntu 10.04 LTS) was to be able to run a real-time backup system.   As noted earlier, I normally have all my data files – word processing files, spreadsheets, digital images, etc. – in a single data partition.   I have now also consolidated my electronic mail messages on the same disk by virtue of running Thunderbird as the mailer and specifying the storage location for its message databases. Now, it’s time to ensure that all of the above are well and truly backed up.

Recent Linux kernels have included a function named inotify that monitors disk activity and, in particular, flags when files are written to disk or deleted. In order to create a file backup utility someone needed to combine inotify’s file event monitoring with the rsync file synchronization utility. Fortunately, Benedikt Böhm, a computer programmer in Germany, has provided just this functionality in a package named inosync.

The inosync utility is actually a Python script, and is effectively provided by Benedikt as open-source code. The beauty of Ubuntu 10.04 is (a) Python is installed by default, and (b) inosync is available in Ubuntu’s software repositories, and so can be downloaded and installed from the Ubuntu Software Centre.

The main script file is inosync itself (, located in the /usr/bin/ file folder; however, there is usually no need to modify this file (and hence no real need to know anything about Python scripting). Normal customization of the program is handled through a second script file, the example for which is given as The minimum changes that need to be made to this latter file are to specify the disk or file folder to be monitored as the source of any file updates, and the disk or file folder to be used as the target where the backup is to be maintained.

In my case, for the system I am currently using, I changed the script file name to and modified two lines in the source code to specify my source and target disks as:

# directory that should be watched for changes
wpath = "/media/DataDisk/"

# common remote path
rpath = "/media/BarracudaData/D/"

The command line to call inosync, and initiate the backup process is:

inosync -c ./inosync/ -d -v

where the c switch indicates the name and location of the configuration file to be used, the d switch tells inosync to “daemonize” (i.e. run in the background), and the v switch causes debugging information to be printed as necessary.

Now, I find that this command is way too intricate to be entered manually, so I use a simple bash script file instead.

echo "Mirror DataDisk to BarracudaData"
# Check that DataDisk is mounted
if grep '/media/DataDisk' /etc/mtab > /dev/null 2>&1; then
# Check that the BarracudaData disk is available
if grep '/media/BarracudaData' /etc/mtab > /dev/null 2>&1; then
inosync -c ./inosync/ -d -v
echo " "
echo "Mount BarracudaData and try again"
echo " "
echo " "
echo "Mount DataDisk and try again"
echo " "
echo "Shell command complete"

The above file checks that both the data partition and the backup disk are mounted before it calls inosync and sets the backup in progress. If one of the two disks is unavailable, the script issues an error message and quits. Otherwise, the script completes and inosync runs in the background, silently copying any new or updated files that are written to the source drive onto the target disk, and deleting from the target any files that are removed from the source, all while maintaining the source disk’s directory structure.

If none of the above makes any sense (or if you have a burning desire to know why I selected /media/BarracudaData/D/ rather than /media/BarracudaData/ as the target folder), I have documented the required procedures in a bit more detail in one of my Exploring Linux articles published in Ottawa PC News, the monthly newsletter of the Ottawa PC Users’ Group.

A future post will follow up on the above information, perhaps providing a little more insight where needed, but also with some methods for making the process a little more sophisticated. So, if real-time backup with inosync sounds like a good idea, stay tuned, it get better…



Benedikt Böhm

Exploring Linux – Part 16

Kernel Korner – Intro to inotify


This entry was posted in Backup. Bookmark the permalink.

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 )

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s