Feb 082010

Unison is a great tool to keep directories and files synchronized. It is extremely simple to use once you figure out how to do the setup and it can be done automatically (via a cronjob).

I show you here how to do it:

If you are not sure if used Unison before, make a backup of the default configuration file:

mv ~/.unison/default.prf ~/.unison/default.old.prf

Then start your first synchronization run manually:

unison ~/university/ ssh://philipp@lion//home/philipp/university

Where lion may be a hostname or IP in your local network or a domain name or IP on the Internet (your server or your dyndns host at home).
After the synchronization finished, you have a new file ~/.unison/default.prf containing the settings of the last run:

root = /home/philipp/university/
root = ssh://philipp@lion//home/philipp/university

So to move this file to a named profile do:

mv ~/.unison/default.prf ~/.unison/localnet.prf

Now you can run this profile using:

unison localnet

The configuration file (~/.unison/localnet.prf) gives you the possibility to adjust advanced settings:
For the synchronization operation to run without user interaction, add the option batch=true. To force Unison to resolve conflicts by keeping the newest files is equally simple: prefer=newer. If you want Unison to preserve the files’ modification times, add the times=true to the .prf config file.
So the configuration file could then look like this:

root = /home/philipp/university/
root = ssh://philipp@lion//home/philipp/university
group = true
owner = true
logfile = /var/log/unison.log


VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)

Related Posts:

  2 Responses to “Synchronize Directories using Unison”

  1. Thanks for this post Philipp, very good. I'm using Unison with many of the same options as you. Do you find a problem with the timestamp on directories when using times=true? I find that it keeps the original time of files but directory times are always timestamped at their moment of (Unison) creation?

    Mark P markshop at pengelly dot info

    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)
  2. This timestamp issue has been bugging me forever. Thanks for posting the solution. If anyone else is in my situation, I got everything synced first using unison, then added


    to my profile and re-ran unison. I then removed the 'prefer' line above (or else one would be very, very sorry next time you synced).

    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>