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

62 questions
9
votes
1 answer

unison "end of file exception"

the few last days I am getting this exception when running unison: "End_of_file exception raised in loading archive" (this indicates a bug!) it does not help a bit, I cannot find answer elsewhere on google, ppl talk about it but seem not be able to…
4
votes
2 answers

How do I run unison between Ubuntu and CentOS 7

I am trying to sync data between an Ubuntu instance and a CentOS 7 instance. It's like a bi-directional rsync so I thought unison would be the best tool. I installed it on both instances but when I tried to connect them I received an error because…
jss367
  • 195
4
votes
1 answer

Unison: Ignore all files with *.ext, except those in a specific subdirectory

I am trying to perform a sync using Unison (2.40.102) where I want to ignore all files with a specific extension, say *.ext, but not ignore the files with this extension if they are in a specific subfolder. Folder…
blsqr
  • 43
3
votes
1 answer

Can unison be made to preserve file creation dates?

unison is a very useful tool to synchronize filesystems, for instance between different machines. It detects conflicts and asks the user about them before actually copying anything (user then decides which version of the file to copy into the other,…
Dalker
  • 1,622
3
votes
1 answer

Pre-Cache unison

I'm using my desktop and a single board cpu (Raspberry Pi 2 - 900 MHz) to sync two very large directories with large files. Often, the files are the same but the filenames are changed. Unison is suggested here for that purpose, which I've used to…
Miati
  • 3,150
3
votes
1 answer

Unison is ignoring local config and overriding remote file permissions

If I modify a local file, unison syncs that file but it removes all permissions on the destination server, leaving only the following permissions: -rw------- My local config contains the switches which should tell unison to ignore file…
Jordan
  • 141
1
vote
0 answers

How do you follow a symbolic link under a root?

I am syncing two machines using Unison: root = /home/luserface root = ssh://192.168.1.168/ I have a subdirectory "Foo" under that home, and it's a symbolic link. I have follow = Path Foo in my Unison profile, but that does not work; that Path…
1
vote
1 answer

How to exclude a sub folder from ignore

I have a build folder that I want to ignore and inside that build folder, I have a generated-src that I don't want to ignore root | - build | - lib | - bin ` - generated-src | - src ` - tst I tried with this syntax: ignorenot =…
1
vote
1 answer

Ignore a given subdirectory in every directory when syncing with unison

I want to sync my workspace directory with my external backup HD. The thing is that I use ensime and it generates an .ensime_cache subdirectory for every project and I don't want to sync those subdirectories with the backup (it can always be…
Jeff
  • 169
0
votes
1 answer

Ubuntu Unison: filter everything except multiple files

I want to synchronize two computers that are similar and update just a few files. Therefore I would like to perform a Unison and ignore everything except a list of files in different paths. Something like: # /usr/bin/unison-gtk /home/…
0
votes
1 answer

How to *install* two specific versions of Unison without installing unison-all or any other version than those two specific versions

Please do not mark as duplicate because somewhere else someone says that installing unison-all will achieve the same. I am not asking "How can I use several versions of Unison in the same machine?". The answer to that would be: install the package…
Mephisto
  • 1,077
0
votes
1 answer

Unable to synchronize files

I am trying to synchronize files between two servers: server1 and server2 I created user and gave him rights to RWX on /var/www then I added the following unison configuration…