Unison
This document describes how to set up bidirectional synchronisation of wallpaper images between a macOS computer and a Raspberry Pi using Unison.
Prerequisites
- macOS computer with Homebrew installed
- Raspberry Pi running Raspbian
- SSH access to your Raspberry Pi
- Basic knowledge of terminal commands
Directory Paths
- macOS:
$HOME/Pictures/wallpaper - Raspberry Pi:
$HOME/runtipi/media/data/images/wallpaper
Installation
On macOS
brew install unisonOn Raspberry Pi
sudo apt-get updatesudo apt-get install unisonBasic Usage
Bidirectional Synchronisation
This command synchronises files in both directions, maintaining consistency between both folders:
unison ~/Pictures/wallpaper ssh://pi@raspberry-pi-hostname//home/pi/runtipi/media/data/images/wallpaper -batch -autoReplace raspberry-pi-hostname with your Pi’s actual hostname or IP address.
One-way Synchronisation (Pull from Pi)
This command pulls all files from the Pi to your Mac, overwriting local changes:
unison ~/Pictures/wallpaper ssh://pi@raspberry-pi-hostname//home/pi/runtipi/media/data/images/wallpaper -batch -prefer ssh://pi@raspberry-pi-hostname//home/pi/runtipi/media/data/images/wallpaperOne-way Synchronisation (Push to Pi)
This command pushes all files from your Mac to the Pi, overwriting changes on the Pi:
unison ~/Pictures/wallpaper ssh://pi@raspberry-pi-hostname//home/pi/runtipi/media/data/images/wallpaper -batch -prefer ~/Pictures/wallpaperSetting Up Profiles
Unison profiles make it easier to run commands with preset options.
Create Profiles Directory
mkdir -p ~/.unisonBidirectional Sync Profile
Create a file at ~/.unison/wallpaper.prf with the following content:
# Roots of the synchronisationroot = /Users/yourusername/Pictures/wallpaperroot = ssh://pi@raspberry-pi-hostname//home/pi/runtipi/media/data/images/wallpaper
# General optionsauto = truebatch = trueconfirmbigdel = truefastcheck = truetimes = true
# Log output to a filelog = truelogfile = /Users/yourusername/.unison/wallpaper-sync.log
# File patterns to ignoreignore = Name .DS_Storeignore = Name ._.DS_Storeignore = Name Thumbs.dbReplace yourusername and raspberry-pi-hostname with your actual values.
Pull-only Profile
Create a file at ~/.unison/wallpaper-pull.prf with the following content:
# Roots of the synchronisationroot = /Users/yourusername/Pictures/wallpaperroot = ssh://pi@raspberry-pi-hostname//home/pi/runtipi/media/data/images/wallpaper
# General optionsauto = truebatch = truefastcheck = truetimes = true
# Always prefer the Pi's versionprefer = ssh://pi@raspberry-pi-hostname//home/pi/runtipi/media/data/images/wallpaper
# Log output to a filelog = truelogfile = /Users/yourusername/.unison/wallpaper-pull.log
# File patterns to ignoreignore = Name .DS_Storeignore = Name ._.DS_Storeignore = Name Thumbs.dbPush-only Profile
Create a file at ~/.unison/wallpaper-push.prf with the following content:
# Roots of the synchronisationroot = /Users/yourusername/Pictures/wallpaperroot = ssh://pi@raspberry-pi-hostname//home/pi/runtipi/media/data/images/wallpaper
# General optionsauto = truebatch = truefastcheck = truetimes = true
# Always prefer the Mac's versionprefer = /Users/yourusername/Pictures/wallpaper
# Log output to a filelog = truelogfile = /Users/yourusername/.unison/wallpaper-push.log
# File patterns to ignoreignore = Name .DS_Storeignore = Name ._.DS_Storeignore = Name Thumbs.dbRunning with Profiles
Once your profiles are set up, you can run Unison with simple commands:
- Bidirectional sync:
unison wallpaper - Pull from Pi:
unison wallpaper-pull - Push to Pi:
unison wallpaper-push
Automating with Cron
You can schedule regular syncs using cron:
crontab -eAdd one of the following lines depending on your preference:
# Bidirectional sync every hour0 * * * * /usr/local/bin/unison wallpaper
# Pull from Pi daily at 9am0 9 * * * /usr/local/bin/unison wallpaper-pull
# Push to Pi daily at 6pm0 18 * * * /usr/local/bin/unison wallpaper-pushTroubleshooting
SSH Authentication Issues
If you encounter SSH authentication problems, set up passwordless SSH:
-
Generate SSH key (if you don’t already have one):
Terminal window ssh-keygen -t ed25519 -
Copy your key to the Raspberry Pi:
Terminal window ssh-copy-id pi@raspberry-pi-hostname
Version Mismatch
Unison requires the same version on both systems. If you encounter version errors:
-
Check versions:
Terminal window unison -version # On Macssh pi@raspberry-pi-hostname 'unison -version' # On Pi -
If they don’t match, you may need to compile from source on one system to match the other.
Large File Transfer Issues
For very large collections, initial sync might time out. Try:
unison wallpaper -batch -auto -maxthreads 1 -confirmbigdel=falseNotes
- First sync will be slower as Unison builds its database
- Default conflict resolution in batch mode is to skip the file
- The log files contain details of each sync operation
- Consider using
rsyncfor one-time bulk transfers of large collections