What is Unison
Unison is a small file synchronisation tool, very similar to Dropbox actually. Only difference is that Dropbox is a cloud service, while Unison is able to perform syncing between two computers on a local network.
Install Unison on MAC
I have been downloading Unison (version 2.40.69) for MAC OSX. You can find it here.
The interface looks like the screenshot below:
Install Unison on Raspberry Pi
pi@raspberrypi ~/TestUnison $ sudo apt-get install unison pi@raspberrypi ~/TestUnison $ unison -version unison version 2.40.65
We should configure Unison to sync correctly. To do this
WAPPTASTIC: $ cd /Users/wapptastic/Library/Application Support/Unison WAPPTASTIC: $ ls -al total 64 drwx------ 10 wauterw staff 340 Dec 25 18:13 . drwx------ 53 wauterw staff 1802 Dec 25 18:18 .. -rw------- 1 wauterw staff 658 Nov 19 21:24 ar09d2ec108d12d6b57ec99b7a6b117f6e -rw------- 1 wauterw staff 779 Dec 25 18:13 ar4d95c69eb4e432a71f26ae4240c5733d -rw------- 1 wauterw staff 917 Aug 22 14:55 ar7537e7a45b78e53777318b7340628532 -rw-r--r-- 1 wauterw staff 3329 Dec 25 18:11 default.prf -rw------- 1 wauterw staff 172 Nov 19 21:23 fp09d2ec108d12d6b57ec99b7a6b117f6e -rw------- 1 wauterw staff 34 Dec 25 18:18 fp4d95c69eb4e432a71f26ae4240c5733d -rw------- 1 wauterw staff 34 Aug 22 14:55 fp7537e7a45b78e53777318b7340628532 -rwxr-xr-x 1 wauterw staff 356 Oct 21 19:46 start.py
You see there is a default.prf file. This file is used by the MAC version of Unison when the application starts. Using this profile, Unison knows ‘from’ where ‘to’ where you would like to sync.
# Unison preferences file root = /Users/wapptastic/TestUnison root = ssh://email@example.com//home/pi/TestUnison # Some regexps specifying names and paths to ignore #ignore = Path stats ## ignores /var/www/stats #ignore = Path stats/* ## ignores /var/www/stats/* #ignore = Path */stats ## ignores /var/www/somedir/stats, but not /var/www/a/b/c/stats #ignore = Name *stats ## ignores all files/directories that end with "stats" #ignore = Name stats* ## ignores all files/directories that begin with "stats" #ignore = Name *.tmp ## ignores all files with the extension .tmp # When set to true, this flag causes the user interface to skip # asking for confirmations on non-conflicting changes. (More # precisely, when the user interface is done setting the # propagation direction for one entry and is about to move to the # next, it will skip over all non-conflicting entries and go # directly to the next conflict.) auto=true # When this is set to true, the user interface will ask no # questions at all. Non-conflicting changes will be propagated; # conflicts will be skipped. batch=true # !When this is set to true, Unison will request an extra # confirmation if it appears that the entire replica has been # deleted, before propagating the change. If the batch flag is # also set, synchronization will be aborted. When the path # preference is used, the same confirmation will be requested for # top-level paths. (At the moment, this flag only affects the # text user interface.) See also the mountpoint preference. confirmbigdel=true # When this preference is set to true, Unison will use the # modification time and length of a file as a `pseudo inode # number' when scanning replicas for updates, instead of reading # the full contents of every file. Under Windows, this may cause # Unison to miss propagating an update if the modification time # and length of the file are both unchanged by the update. # However, Unison will never overwrite such an update with a # change from the other replica, since it always does a safe # check for updates just before propagating a change. Thus, it is # reasonable to use this switch under Windows most of the time # and occasionally run Unison once with fastcheck set to false, # if you are worried that Unison may have overlooked an update. # The default value of the preference is auto, which causes # Unison to use fast checking on Unix replicas (where it is safe) # and slow checking on Windows replicas. For backward # compatibility, yes, no, and default can be used in place of # true, false, and auto. See the section "Fast Checking" for more # information. fastcheck=true # When this preference is set to true, the textual user interface # will print nothing at all, except in the case of errors. # Setting silent to true automatically sets the batch preference # to true. silent=true # When this flag is set to true, file modification times (but not # directory modtimes) are propagated. times=true The most important pieces are:
- The source file is /Users/wapptastic/TestUnison
- The destination sync folder is /home/pi/TestUnison and can be found ssh://firstname.lastname@example.org
- No questions are asked by the Unison program (like confirmation messages etc….)
Putting it to test
Before we continue testing, it is important to note that we must align the major version numbers, in our case we both have 2.40 so that should work.
When the default.prf profile is correctly configured, launch Unison on your MAC. When Unison starts, you will get a screenshot similar to the one above. Then hit the ‘rescan’ button. This will scan the source folder for new content. Below screenshot is taking a view on the source folder (Unison on MAC) as well as the destination folder on the Raspberry Pi. Obviously, both folders are completely empty.
Create some folders and files in the source directory on your MAC:
and then rescan again using Unison:
Obviously, you see that Unison has noticed the changes in the source directly, but as we did not sync yet with the destination folder, that one remains empty.
Then hit ‘Go’ in the Unison app on your MAC. You will see that Unison will then start to sync and that eventually the filers and folders end up in the destination folder. Great, so all content between our MAC folder and Raspberry Pi folder are now in sync.
To show that the sync really works bidirectionally, let’s remove some folders from the destination directory on our Raspbery Pi. In below screenshot, you can see we removed the folders ‘test2’ and ‘test3’, but did not perform the sync yet.
Eventually, after performing the sync, we end up only with the folder ‘test 1’ in our MAC. It’s clear from this that Unison is syncing bidirectionally.
Have fun with this great tool!!