Questions tagged [unison]

Unison is a bidirectional, conflict detecting file-synchronization tool for OSX, Unix, and Windows. It allows two replicas of a collection of files and directories to be stored on different hosts (or different disks on the same host), modified separately, and then brought up to date by propagating the changes in each replica to the other.

Overview

Unison is a file-synchronization tool for OSX, Unix, and Windows. It allows two replicas of a collection of files and directories to be stored on different hosts (or different disks on the same host), modified separately, and then brought up to date by propagating the changes in each replica to the other.

Unison shares a number of features with tools such as configuration management packages (CVS, PRCS, Subversion, BitKeeper, etc.), distributed filesystems (Coda, etc.), uni-directional mirroring utilities (rsync, etc.), and other synchronizers (Intellisync, Reconcile, etc). However, there are several points where it differs:

  • Unison runs on both Windows and many flavors of Unix (Solaris, Linux, OS X, etc.) systems. Moreover, Unison works across platforms, allowing you to synchronize a Windows laptop with a Unix server, for example.

  • Unlike simple mirroring or backup utilities, Unison can deal with updates to both replicas of a distributed directory structure. Updates that do not conflict are propagated automatically. Conflicting updates are detected and displayed.

  • Unlike a distributed filesystem, Unison is a user-level program: there is no need to modify the kernel or to have superuser privileges on either host.

  • Unison works between any pair of machines connected to the internet, communicating over either a direct socket link or tunneling over an encrypted ssh connection. It is careful with network bandwidth, and runs well over slow links such as PPP connections. Transfers of small updates to large files are optimized using a compression protocol similar to rsync.

  • Unison is resilient to failure. It is careful to leave the replicas and its own private structures in a sensible state at all times, even in case of abnormal termination or communication failures.

  • Unison has a clear and precise specification.

  • Unison is free; full source code is available under the GNU Public License.

Usage

The first time Unison is run, it will take some time to fully synchronize the specified directories. It will create archive files in the .unison directory ($HOME/.unison in Unix, $USERPROFILE\.unison in Windows) to store the structure of the sync directories and make future syncs much quicker.

Unison can be run in a very basic way by evoking it as unison [options] root1 root2 where root1 and root2 are the directories to be synced. To more easily run Unison with many options and to more easily evoke Unison from within a script or as a cron job, it is convenient to create a profile to specify the roots of synchronization and other options. If we have a profile profile.prf (stored in the .unison directory), we can use this profile by running unison profile. A simple profile will look something like this:

# profile.prf
root = /home/user
root = ssh://user@198.51.100.42//home/user
path = Documents
path = Files

This will synchronize the local directories /home/user/Documents and /home/user/Files with the corresponding remote directories on 198.51.100.42 over ssh.

A more interesting Unison profile that could be used for automating backups to a remote server could look something like this:

# profile.prf
root = /home/user
root = ssh://user@198.51.100.42//home/user
sshargs = -C -i /path/to/ssh_key

path = Documents
ignore = Path Documents/secrets
ignore = Name *.tmp
ignore = Name {.*,*}.sw[ponx]

auto = true
batch = true
confirmbigdeletes = false

backuplocation = central
backupdir = /home/user/Unison-Backups
maxbackups = 7
backup = Name {.*,*}
backupprefix = .$VERSION

This profile will sync all of /home/user/Documents to the remote server except for the /home/user/Documents/secrets subdirectory, all files with a .tmp extension, and any swap files that vim likes to create. It will also automatically sync files without asking for confirmation (auto = true) and will store backups of files that are overwritten when they are synced in /home/user/Unison-Backups.

Helpful Links

Unison Homepage
User Manual and Reference Guide
A good Unison guide by Philip Guo

102 questions
3
votes
0 answers

Unison conflict between new files and merge setting

I'm synchronizing my Sites folder on two Macs in the local network. Some Wordpress sites in this folder contain readme.txt files that are different because of different plugin or theme versions on the two Macs. They differ in file size and…
Timm
  • 2,488
  • 2
  • 22
  • 25
3
votes
3 answers

How to exclude svn metadata while synchronizing with unison?

How can I exclude all the svn metadata while synchronizing with unison?
Daniel Gartmann
  • 11,678
  • 12
  • 45
  • 60
3
votes
0 answers

Unison synchronization between host and virtual machine server

I am trying to set up unison to synchronize directories between my host OS and a virtual OS. I can ssh from my host terminal with no problems. When Unison tries to ssh, I get "Fatal error: Lost connection with the server.". Some more details: I have…
nikosd
  • 919
  • 3
  • 16
  • 26
3
votes
2 answers

Sync two computers and also use git

Here is my situation: I have two machines- A desktop and a laptop the home folders of which I keep in sync using unison. This setup works fine as I can carry my work around and have everything readily aviable. Now I want to throw git into this…
anikomei
  • 73
  • 1
  • 9
3
votes
1 answer

How do I use unison to synchronize only dotfiles and dotfolders?

I would like to synchronize only files and folders that start with a dot in my home folder. More specifically, I only want to synchronize the files and folders listed by: ls -ld ~/.[^.]* Unison command line I tried: unison /home/username…
3
votes
2 answers

Gaining better performance with inotify-tools and unison.

I use inotify-tools and unison to synchronize folders between machines. Because I have a large folder to synchronize, I just simply write an inotifywait script to do the job automatically. Is it sensible to let inotifywait to monitor the…
ice6
  • 1,173
  • 9
  • 9
2
votes
1 answer

exec error code 2

I'm using Unison to sync files between two servers. I'm trying to get PHP to call it after a file is uploaded. I'm using exec, but it's returning an error code of 2. exec("/usr/bin/unison /var/www/html/files ssh://a2//var/www/html/files -batch…
gen_Eric
  • 223,194
  • 41
  • 299
  • 337
2
votes
3 answers

On Mac Big Sur, how do I downgrade my version of Unision to a specific version?

I’m running Mac OS 11.5.2 (Big Sur). I have the following version of unison installed using brew install unison Which is $ unison -version unison version 2.51.4 (ocaml 4.12.0) However, in order to work with a virtual Ubuntu box, which runs $…
Dave
  • 15,639
  • 133
  • 442
  • 830
2
votes
0 answers

Unison: Ignore files with Regex doesn't work

I tried to ignore some files that end with ".NUMBERS" like .133443. I tried this Regex but it still copies the files: unison -batch -owner -group -times -ignore "Regex ^*\.[0-9]+$" /hadoop/bigdata/giin/data…
anis
  • 21
  • 1
2
votes
1 answer

Can I use regex for 'rootalias' alignment in Unison?

Beyond Compare has a feature called "alignment override" which allows me to specify a regex rule for matching items with different names. Folders on my destination have prefixes which I want to ignore. For example, I can specify that a source folder…
Dan
  • 1,257
  • 2
  • 15
  • 31
2
votes
1 answer

How to use expect to bypass the initial `Press return to continue.` question of unison?

I'd like to bypass the Press return to continue. question of unison (This happens when the sync is an intial sync. If it is not the first time, then this question does not appear and expect should be able to know this and do nothing). When this…
user1424739
  • 11,937
  • 17
  • 63
  • 152
2
votes
0 answers

Install specific version of unison with homebrew

I'm using docker-sync and unison in a docker env. In my docker-sync.yml I am using the following version of the container eugenmayer/unison:2.51.2.1' And as advised on the website I installed unison on local with homebrew, unfortunately, the…
T3ddy
  • 127
  • 2
  • 11
2
votes
2 answers

Unison failed: Uncaught exception Failure("input_value: ill-formed message")

I have two computers one running Ubuntu 19.04 and another running Ubuntu 20.04. I synchronize them both with a server at my workplace running CentOS 7.7.1908 using unison. My Ubuntu 19.04 machine is running Unison 2.48.4. My Ubuntu 20.04 machine…
2
votes
2 answers

Regex alternative to negative lookahead

I want to match all paths that include the keyword build unless they also contain .html Here is a working regex that uses negative lookahead: https://regexr.com/4msck I am using regex for path matching in unison which does not support negative…
Adam Griffiths
  • 680
  • 6
  • 26
  • 60
2
votes
0 answers

Docker sync on Mac and Symfony still slow and sync suddenly stops

I'm working on a Mac with Symfony PHP framework. Without docker-sync response time for basic app (symfony 3.4) it takes me around 20sec to load. With docker-sync its much faster (about 3sec), but it's not working quite the best. I had to downgrade…
Mario
  • 151
  • 4
  • 16