There are endless ways of backing up Linux systems, such as using backup2l or the ever popular rsync. This time around though I will focus on Unison, which is a very useful and competent tool. It both has a command-line interface and a GUI version. The command-line version is obvious useful for automatic synchronizations, whereas the GUI version is perfect for day-to-day sporadic desktop use.
First of all you have to get hooked up with the unison binaries, since they tend not to be in default Linux distributions. This can easily be done in Ubuntu by installing the packages unison and unison-gtk.
You will probably want to sync with an external disk or server, and the easiest way is just to hook up an external USB-disk. You can however also connect to an SSH or RSH server, or simply pipe the data through a socket. For the sake of simplicity I will create two local directories to use for this article. The data directory would be used locally, and the backup directory in some other place.
joch@lightman:~$ mkdir -p sync/data sync/backup
We want to have some data in the data directory too, so we can try out unison to see if it works.
joch@lightman:~$ echo “an example text” > sync/data/file1.txt
joch@lightman:~$ echo “another example” > sync/data/file2.txt
So now we have two text-files in the data directory. The time has come to invoke unison the simplest way possible.
joch@lightman:~$ unison sync/data/ sync/backup/
This would, at least in theory, copy the two files from the data directory to the backup directory. The first time you try to synchronize two directories, a gigantic warning message will appear in you console.
Warning: No archive files were found for these roots. (and 12 more lines)
This is just unison saying that you haven’t synchronized these directories before, so no worries. Unison should now sync the directories, and you will probably notice that you have to confirm each action. Okay for two files, but it could be somewhat tedious when talking about ten thousand. You will want to add -auto to the command-line to automatically accept default actions when you have made sure that everything works as desired.
So, let’s have a look at the graphical version. We assume the same file set-up as for the command-line demo.
So, start with executing the Unison GUI from the menu. In Ubuntu it will be located in Applications –> Internet –> Unison. The first screen is the profile screen (yes, you can use these profiles with the command-line version substituting the path-names for the profile name), and here we want to “Create a new profile”.
Enter a name for the profile in the pop-up and click OK. Then press OK in the profiles screen after selecting the created profile. You will first be given the chance to add your first directory, and this would then be ~/sync/data/. The next step is to define where to back-up you precious data.
We will use Local and browse to ~/sync/backup/ here and the press OK. Notice the same warning message again, this time in the GUI!.
It should have noticed the changes that needs to be made, and pressing Go in the toolbar will execute the operation.
There isn’t much more to it. The next time, just select the already created profile and just hit Go to sync again. Unison does have lots of different options for the advanced users, but I will leave it for you to experiment with.
Remember, always have a fresh backup. It’s not a matter of if your hard-drive crashes, it’s a matter of when.