My personal backup strategy

There are plenty of tools to back up your personal files, and all sorts of backup strategies (such as performing a full backup once a week and incremental daily backups in between), but it seems that no two people have precisely the same approach, and there are many tutorials in books and on the Web on the subject of backing up in Linux. Anyway, here I explain my personal way of making backups, which fits my modest requirements and may be of interest to someone. If this post does nothing other than spur someone to backup their data, whatever the method, then I’ll be happy.

A recent round-up of eight GUI backup tools was published in the December 2010 issue of Linux Format magazine. It is also readable in the on-line article Best Linux backup software: 8 tools on test. Some of these GUI tools are front-ends for command line tools such as rsync and rdiff. You might want to evaluate those GUI tools, as they can make the backup process much easier for the desktop user.

Rather than backing up specific directories of files or individual files, some people prefer to create images of the whole hard disk or of specific partitions. Linux also offers some choices there, such as Clonezilla or Partimage (see, for example, the Sabayon Linux Wiki article HOWTO: Disk imaging using Partimage). I do make backup images of my partitions from time to time, but my personal files change too often for that method to be viable as my main backup strategy. And, to be honest, I find it rather inconvenient and time consuming.

GUI backup tools for Linux have improved significantly over the last three years. Some years ago my search came up blank for a Linux GUI tool having the simplicity and reliability of the shareware GUI tool I used with Windows XP. Things have certainly changed since then, but I continue to use the simple method I put together based on an rsync command given in Scott Granneman’s excellent Linux Phrasebook. Being paranoid, I eschewed encrypted backups, having had trouble recovering files from encrypted backups in the past. Anyway, without further ado, here is my backup strategy. I’m using KDE 4, but the principles apply whatever the desktop environment.

MY OBJECTIVES

This is my ‘functional specification’.

  1. Back up the contents of the Linux /home directory and the contents of a Thunderbird e-mail directory on a NTFS partition shared between Thunderbird for Windows and Thunderbird for Linux. I’m not interested in backing up files in the system directories such as /etc as I can reinstall if necessary. Any configuration files in /etc and the other system directories that I want to back up I simply copy to a directory in my /home directory, so that they are backed up with the other files in the /home directory.

  2. Have two separate external hard drives, and back up to them alternately.

  3. Copy any new files to the backup drive, copy any files that have changed since the previous backup to that drive and overwrite the corresponding files on the backup drive, and delete files from the backup drive if they were deleted from my laptop. This strategy is referred to as ‘incremental backup’, because it does not copy files that have not changed.

  4. Log the date and time of completion of each backup session in a text file.

  5. Launch a back up session manually by double-clicking on an icon on the Desktop. As I am often away from home with my laptop, I prefer to launch a back up session manually, rather than automatically using e.g. a cronjob.

HARDWARE

I have two external USB hard drives, each with 1 TB capacity, connected via a USB hub to my main laptop when I’m at home. Both are off-the-shelf NTFS drives. I gave them the volume names USBHDD01 and USBHDD02 (this can be done via Linux using, e.g. GParted, or via Windows).

SOFTWARE

I have two shell scripts backup1 and backup2 in my home directory:

~/backup1

#!/bin/bash
sudo rsync --verbose --progress --stats --recursive --times --perms --links --compress --delete /home/fitzcarraldo/ /media/USBHDD01/Backup_of_Mesh_DX_Linux_1

sudo rsync --verbose --progress --stats --recursive --times --perms --links --compress --delete "/media/Windows7/Documents and Settings/Fitzcarraldo/Application Data/Thunderbird/" /media/USBHDD01/Backup_of_Mesh_Thunderbird_1

echo "Mesh DX Linux back up 1" >> /home/fitzcarraldo/Desktop/Mesh_DX_Linux_back_up.log
date >> /home/fitzcarraldo/Desktop/Mesh_DX_Linux_back_up.log

echo "Backup completed"
date

~/backup2

#!/bin/bash
sudo rsync --verbose --progress --stats --recursive --times --perms --links --compress --delete /home/fitzcarraldo/ /media/USBHDD02/Backup_of_Mesh_DX_Linux_2

sudo rsync --verbose --progress --stats --recursive --times --perms --links --compress --delete "/media/Windows7/Documents and Settings/Fitzcarraldo/Application Data/Thunderbird/" /media/USBHDD02/Backup_of_Mesh_Thunderbird_2

echo "Mesh DX Linux back up 2" >> /home/fitzcarraldo/Desktop/Mesh_DX_Linux_back_up.log
date >> /home/fitzcarraldo/Desktop/Mesh_DX_Linux_back_up.log

echo "Backup completed"
date

I made them both executable:

$ chmod +x ~/backup1
$ chmod +x ~/backup2

I created two Desktop Configuration Files on my Desktop: Backup_1 backs up to USBHDD01, and Backup_2 backs up to USBHDD02.

~/Desktop/Backup_1

[Desktop Entry]
Comment[en_GB]=Backup /home directory to Seagate USB external HDD 01
Comment=Backup /home directory to Seagate USB external HDD 01
Encoding=UTF-8
Exec=sh /home/fitzcarraldo/backup1
GenericName[en_GB]=Backup /home to USBHDD01
GenericName=Backup /home to USBHDD01
Icon=/home/fitzcarraldo/Pictures/Icons/save_all.png
MimeType=
Name[en_GB]=Backup_1
Name=Backup_1
Path=
StartupNotify=true
Terminal=true
TerminalOptions=\s--noclose
Type=Application
X-DBUS-ServiceName=
X-DBUS-StartupType=none
X-DCOP-ServiceType=
X-KDE-SubstituteUID=false
X-KDE-Username=

~/Desktop/Backup_2

[Desktop Entry]
Comment[en_GB]=Backup /home directory to Seagate USB external HDD 02
Comment=Backup /home directory to Seagate USB external HDD 02
Encoding=UTF-8
Exec=sh /home/fitzcarraldo/backup2
GenericName[en_GB]=Backup /home to USBHDD02
GenericName=Backup /home to USBHDD02
Icon=/home/fitzcarraldo/Pictures/Icons/save_all.png
MimeType=
Name[en_GB]=Backup_2
Name=Backup_2
Path=
StartupNotify=true
Terminal=true
TerminalOptions=\s--noclose
Type=Application
X-DBUS-ServiceName=
X-DBUS-StartupType=
X-DCOP-ServiceType=
X-KDE-SubstituteUID=false
X-KDE-Username=

I downloaded a pretty PNG icon from the Web for the two Desktop Configuration Files, and stored it in a convenient directory, declared in the Desktop Configuration Files.

To launch a back up session I just need to double-click on the relevant icon.

Each of the two scripts records in a text file ~/Desktop/Mesh_DX_Linux_back_up.log the date and time when it completed. The next time I launch a back up, the event is appended to the log. An example of the contents of this log file is shown below:

Mesh DX Linux back up 1
Tue May 18 01:12:00 BST 2010
Mesh DX Linux back up 2
Fri May 28 19:47:33 BST 2010
Mesh DX Linux back up 1
Thu Jul  1 17:28:43 BST 2010
Mesh DX Linux back up 2
Sat Jul 31 01:03:03 BST 2010
Mesh DX Linux back up 1
Thu Aug 19 20:55:18 BST 2010
Mesh DX Linux back up 2
Sat Sep 11 19:13:12 BST 2010
Mesh DX Linux back up 1
Sun Sep 19 19:42:30 BST 2010
Mesh DX Linux back up 2
Fri Sep 24 23:51:19 BST 2010
Mesh DX Linux back up 1
Sun Sep 26 21:23:28 BST 2010
Mesh DX Linux back up 2
Tue Oct  5 01:19:18 BST 2010
Mesh DX Linux back up 1
Fri Oct  8 09:59:13 BST 2010
Mesh DX Linux back up 2
Fri Oct 22 11:36:29 BST 2010
Mesh DX Linux back up 1
Mon Nov  1 15:49:07 GMT 2010
Mesh DX Linux back up 2
Fri Dec  3 02:43:59 GMT 2010

By looking in this file I can see when I performed the latest backup and which of the two icons I need to double-click for my next backup.

If my house is unoccupied for any length of time then I take one of the drives or the laptop with me, or leave them in a secure remote location. So, if the house burns down or a thief were to break in, at least one hard disk would still be in my possession with my work files on it.

ENHANCEMENTS

Of course, I could increase the number of hard drives in order to enable me to retrieve files from further back in time, but my current strategy fits my needs. Your needs may be different to mine, so adapt the strategy as you wish. If you are not backing up your data, please do something about it now! I have been saved a few times in the past by retrieving a file from one of my backup drives that I inadvertently deleted or modified on my laptop.

EDIT (April 18, 2012): Here is a small improvement to my original scheme. It is better to move the sudo command to the Desktop Configuration File so that you only have to enter your password once and can leave the backup unattended. In my original scheme, if the number of files to backup is large enough, the sudo timeout would mean you would have to re-enter your password when the second sudo command is executed by the shell script. So I changed the two shell scripts and the two Desktop Configuration Files slightly as shown below. I won’t bother listing ~/backup2 and ~/Desktop/Backup_2 as the change is the same.

~/backup1

#!/bin/bash
echo -n "Mount the backup drive and then press ENTER: "
read ACKNOWLEDGE

echo "********** Backing up my home directory **********"

rsync --verbose --progress --stats --recursive --times --perms --links --compress --delete /home/fitzcarraldo/ /media/USBHDD01/Backup_of_Mesh_DX_Linux_1

echo "********** Backing up my Thunderbird directory **********"

rsync --verbose --progress --stats --recursive --times --perms --links --compress --delete "/media/Windows7/Documents and Settings/Fitzcarraldo/Application Data/Thunderbird/" /media/USBHDD01/Backup_of_Mesh_Thunderbird_1

echo "Mesh DX Linux back up 1" >> /home/fitzcarraldo/Desktop/Mesh_DX_Linux_back_up.log
date >> /home/fitzcarraldo/Desktop/Mesh_DX_Linux_back_up.log

echo "********** Backup completed **********"
date

~/Desktop/Backup_1

[Desktop Entry]
Comment[en_GB]=Backup /home directory to Seagate USB external HDD 01
Comment=Backup /home directory to Seagate USB external HDD 01
Encoding=UTF-8
Exec=sudo sh /home/fitzcarraldo/backup1
GenericName[en_GB]=Backup /home to USBHDD01
GenericName=Backup /home to USBHDD01
Icon=/home/fitzcarraldo/Pictures/Icons/save_all.png
MimeType=
Name[en_GB]=Backup_1
Name=Backup_1
Path=
StartupNotify=true
Terminal=true
TerminalOptions=\s--noclose
Type=Application
X-DBUS-ServiceName=
X-DBUS-StartupType=none
X-DCOP-ServiceType=
X-KDE-SubstituteUID=false
X-KDE-Username=