Backing Up with unison

Although the rsync command is good to back up one machine to another, it assumes that the machine being backed up is the only one where the data is being modified. What if you have two machines that both modify the same file and you want to sync those files? Unison is a tool that will let you do that. It’s common for people to want to work with the same documents on their laptop and desktop systems. Those machines might even run different operating systems. Because unison is a cross-platform application, it can let you sync files that are on both Linux and Windows systems. To use unison in Linux, you must install the unison package (type the sudo apt-get install unison command).With unison, you can define two roots representing the two paths to synchronize. Those roots can be local or remote over ssh. For example:

$ unison /home/marvin ssh://marvin@server1//home/fcaen
$ unison /home/marvin /mnt/backups/marvin-homedir

NOTE: Make sure you run the same version of unison on both machines.

Unison contains both graphical and command-line tools for doing unison backups. It will try to run the graphical version by default. This may fail if you don’t have a desktop running or if you’re launching unison from within screen. To force unison to run in command line mode, add the -ui text option as follows:

$ unison /home/marvin ssh://marvin@server1//home/fcaen -ui text
Contacting server…
marvin@server1’s password:
Looking for changes
Waiting for changes from server
Reconciling changes
local server1
newfile —-> memo.txt [f] y
Propagating updates

The unison utility will then compare the two roots and for each change that occurred since last time, ask you what you want to do. In the example above, there’s a new file called memo.txt on the local system. You are asked if you want to proceed with the update (in this case, copy memo.txt from the local machine to server1). Type y to do the updates. If you trust unison, add -auto to make it take default actions without prompting you:

$ unison /home/marvin ssh://marvin@server1//home/fcaen -auto

For more information, see the man page for unison. In addition, you can view unison options using the -help option. You can also display and page through the unison manual using the -doc all option as shown here:

See unison options
$ unison -help

Display unison manual
$ unison -doc all | less

If you find yourself synchronizing two roots frequently, you can create a profile, which is a series of presets. In graphical mode, the default screen makes you create profiles. Profiles are stored in .prf text files in the ~/.unison/ directory.

They can be as simple as the following:

root = /home/marvin
root = ssh://marvin@server1//home/fcaen

If this is stored in a profile called fc-home.prf, you can invoke it simply with the following command line:

$ unison fc-home


About msotela

This blog is for anyone who wants to access the power of a Linux system as a systems administrator or user. You may be a Linux enthusiast, a Linux professional, or possibly a computer professional who is increasingly finding the Windows systems in your data center supplanted by Linux boxes.

Posted on September 23, 2009, in Unix/Linux. Bookmark the permalink. Leave a comment.

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

%d bloggers like this: