Unison file-synchronization tool
This wiki describes the tool Unison for file synchronization between hosts and includes an installation guide and a tutorial on how to use it. This tool facilitates code development in remote hosts, allowing you to use the preferred text editor and synchronize and back up the files between the local and remote hosts.
Unison
Unison is a bidirectional file synchronization tool for operating systems like Linux, macOS, 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. Check Unison git repository for more information.
- Unison runs on both Windows and Unix-like operating systems and is a cross-platform tool that allows synchronization between Windows and Unix.
- 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.
- 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.
- Unison full source code is available under the GNU Public License.
Installation
Unison can be installed using apt with the following command:
sudo apt install unison
Build from source
Unison can also be built from source; as a dependency, ocaml must be installed:
sudo apt-get install -y ocaml
Follow the instructions below to install Unison from source.
export UNISON_VER=v2.53.7 #check for most recent version git clone https://github.com/bcpierce00/unison.git cd unison git checkout $UNISON_VER make sudo ln -s $HOME/unison/src/unison /usr/local/bin/unison sudo ln -s $HOME/unison/src/unison-fsmonitor /usr/local/bin/unison-fsmonitor
Check the installed version:
unison -version
Files synchronization setup
To start the file synchronization, Unison looks for a prf
file which indicates root paths and files to sync as well as some configuration variables.
Below you will find an example for a sync-file.prf
.
# Roots of the synchronization. # Set the path directories that will be synchronized between the hosts. # You can use ssh to set the root on another device for example ssh://username@hostname/<path> root = <path> root = <path> # Specify the paths to synchronize within the root directory (or leave out to sync all) using the path variable path = ./<path> # Use ignore to select which files to ignore, usually large files or build files # Ignore can be set by name, path or regex ignore = Name .<file> # To name several files you can use {.<file>,.<file>,.<file>} ignore = Path */<dir-path> ignore = Regex .*<regex> # Unison Configurations # Tell it to automatically sync every 5 seconds repeat = 5 # Backup settings. Keep 5 backups of all changed files backup = Name * maxbackups = 5 # Retry once on failure retry = 1 # Skip asking for confirmation on non-conflicting changes auto = true # No questions asked by the user interface batch = true # Unison will request an extra confirmation if it appears that the entire replica has been deleted confirmbigdeletes = true # Synchronize modification times (needed for below) times = true # Automatically take the newer version when there's a conflict prefer = newer # Suppress status messages terse = true # Suppress the contacting server message during startup contactquietly = true # Log output to file log = true logfile = /$HOME/.unison/unison.log
Start sync
To start unison sync, use the following command, selecting the prf
created. The unison sync command should only be run in one of the hosts where the prf
file is saved.
unison -ui text sync-file.prf
Also, a script can be created with a loop to restart unison in case of failure.
#!/bin/bash cd ~/.unison while : do echo "Starting unison" unison -ui text sync-file.prf echo "Unison process exited. Sleep for 30 seconds before restarting" sleep 30 done
For direct inquiries, please refer to the contact information available on our Contact page. Alternatively, you may complete and submit the form provided at the same link. We will respond to your request at our earliest opportunity.
Links to RidgeRun Resources and RidgeRun Artificial Intelligence Solutions can be found in the footer below.