Unison

Unison is an extremely useful file synchronization tool that I use every day. You can think of it like a manual--and more configurable--version of Dropbox or Google Drive. Unison has the advantage that you control when syncing happens and it's relatively easy to configure it to ignore certain files or folders. You can also sync from anywhere on your hard drive rather than having to use a designated folder as with the above programs.

While there are packaged Unison solutions using apt-get and brew, Unison is very particular about which versions are running on the computers you are trying to sync. You also need to watch which version of OCAML (a prerequisite of Unison) you are using. Since I use both OSX and Ubuntu and the package versions differ if their repositories, I found it easier to install everything from source.

Installation

Build-Essentials (if you don't have it already)

  • sudo apt-get install build-essential exuberant-ctags

OCAML

Unison

  • wget unison-2.48.3.tar.gz
  • tar xvzf unison-2.48.3.tar.gz
  • cd unison-2.48.3
  • make UISTYLE=text -j4
  • sudo mv unison /usr/bin/unison

Configuration

Unison configuration profiles are stored in the $HOME/.unison directory. Create a file in that folder and name it whatever you want--you will use this name when you want to synchronize using this profile. An example configuration profile, named Project, might look like the following:

root = /Volumes/BackupDrive/project                #Location of local version
root = ssh://my-remote-server.com//opt/project     #Location of remote version

backup = Name *           #not strictly necessary
backuplocation = local    #these options will create backups when you sync
                          #you can read more in the docs

ignore = Name *.o
ignore = Name .DS_store
ignore = Name Thumbs.db
ignore = Name *.bin
ignore = Name *.svn
ignore = Name *.pyc
perms = 0             #file permissions not synched

Synchronizing

Once you've got everything installed and configured, synchronization is simple. Simply type unison Project (where Project is the name of the profile) at the command line. The program will then ask you for each file how you want to push (either from local to remote or remote to local). It will also make suggestions based on file modification time and you can configure it to automatically use those suggestions without prompting for approval. Once you've decided how all the files should be synchronized, Unison will prompt you to proceed. The rest is automatic.