Skip to content

Instantly share code, notes, and snippets.

Last active July 7, 2023 02:08
  • Star 11 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Configure unison for continuous sync

Configure unison for bi-directional sync

1. On client

  1. Create a profile (~/.unison/bidirsync.prf):
# Unison preferences
label = bi-directonal sync with server
root = /home/<user>/git
root = ssh://<user>@<server-name>//home/<user>/sync/git
sshargs = -oIdentityFile=/home/<user>/.ssh/<privkey-name>
batch = true
auto = true
repeat = watch
logfile = /home/<user>/.unison/unison.log
  1. Test the profile with unison bidirsync

Create systemd job

  1. Create the directory mkdir -p ~/.config/systemd/user
  2. Add file unison.service:

ExecStart=/usr/bin/unison bidirsync

  1. Start/stop the job: systemctl --user {start|stop} unison
  2. Check status: systemctl --user status unison
  3. Enable/disable background job: systemctl --user {enable|disable} unison

2. On client and server

  1. Download depwndencies: sudo apt-get install ocaml python-pyinotify
  2. Download unison from
  3. Unpack
  4. Build and install: make NATIVE=false && make install (binaries go to ~)

Optional setup

Depending on the number of files to watch it may be required to increase the number of files that can be watched: echo fs.inotify.max_user_watches=500000 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment