Bi-directional file synchronization with Unison

So for years I disliked using may laptop for any serious task because it didn't share my configuration and files. And I partially fixed that by writing a configuration sharing tool, but I also wanted to share my working directories. rsync might come as an obvious solution for the job but the synchronization has to be bi-directional, and running the command twice results in favoring the changes of one direction. rsync also has no way to handle deleted files. Luckily I stumbled upon unison.


Unison is a cross-platform file-synchronization tool. Check out the pictures on the wikipedia page if you want an estimate of how old it is. It allows you to sync two directories and manually intervene when file conflicts occur. It's like if Linus forgot to add commits to git. As with any half-decent tool it is covered by the ArchLinux wiki.

The way I run this is using these to systemd unit files:


Description=Sync directory %i with unison

ExecStart=bash -c 'unison -sshargs "-i /home/rein/.ssh/xlab18" $HOME/%i ssh://x-lab18.local.boem/unison/%i -auto -batch -times'

-auto automatically accept default nonconflicting actions , -batch ask no questions at all , -times preserve modification timestamps


Description=Sync directory %i with unison every 5 minutes


I've stored these in my ~/.config/systemd/user directory. If I were to execute systemctl --user start unison@work, my directory ~/work will be synced with the directory ~/unison/work over at my server.

I can make this run every 5 minutes by starting and enabling the timer:

systemctl --user start unison@work.timer
systemctl --user enable unison@work.timer

Created: 2023-06-20

Updated: 2023-11-21