Skip to content

Instantly share code, notes, and snippets.

@asksven
Last active October 16, 2023 20:45
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save asksven/ee38dbe5bdab7e39aa133a1df24dd034 to your computer and use it in GitHub Desktop.
Save asksven/ee38dbe5bdab7e39aa133a1df24dd034 to your computer and use it in GitHub Desktop.
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
#debug=all
  1. Test the profile with unison bidirsync

Create systemd job

  1. Create the directory mkdir -p ~/.config/systemd/user
  2. Add file unison.service:
[Unit]
Description=Unison

[Service]
Environment="PATH=/usr/bin"
ExecStart=/usr/bin/unison bidirsync
#%i
Restart=always
RestartSec=10

[Install]
WantedBy=default.target
  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 https://github.com/bcpierce00/unison/releases
  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