Debian Tutorials

Debian Tutorials


Step by step tutorials showing you how to install and configure various applications and services on Debian based Linux distros.

March 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
25262728293031

Categories


Installing and configuring Unison File Synchronizer

Ástþór IPÁstþór IP

Unison is a file-synchronization tool for Unix 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.

1. Install the Unison package

apt-get install unison

2. Configure the Unison defaults (pico /root/.unison/default.prf)

# skip asking for confirmations on non-conflicting changes
auto=true
 
# the user interface will ask no questions at all
batch=true
 
# Unison will request an extra confirmation if it appears that the entire replica has been deleted
confirmbigdeletes=true
 
# Unison will use the modification time and length of a file as a `pseudo inode number' when scanning replicas for updates, instead of reading the full cont$
fastcheck=true
 
# the group attributes of the files are synchronized
group=true
 
# the owner attributes of the files are synchronized
owner=true
 
# prefer newer version of files in case of conflicts
prefer=newer
 
# the textual user interface will print nothing at all, except in the case of errors.
silent=true
 
# file modification times (but not directory modtimes) are propagated.
times=true

A few of the configuration values will make Unsion silent so that no user action will be required to do the sync, deleted files will be moved to /var/backups/unison to avoid accidental deletion and if the same file is updated on both servers we’ll keep the newer file.

3. Create a private key to avoid passphrase popup to be able to do automatic synchronization

ssh-keygen -t dsa

4. Copy the key to the remote machine

ssh-copy-id -i .ssh/id_dsa.pub [email protected]

5. Manually synchronize a directory

unison /var/www ssh://remote.machine.com//var/www

This will sync /var/www between the local machine and remote.machine.com

6. Automatically synchronize every 5 minutes using crontab (crontab -e)

*/5 * * * * unison /var/www ssh://remote.machine.com//var/www &> /dev/null

Comments 3
  • Ludovic
    Posted on

    Ludovic Ludovic

    Author

    God that tutorial’s just perfect. Many many thanks! Thanks to that, I can sync my list of prohibited url’s between my proxies working in loadbalancing. That is great!


  • Sudeer
    Posted on

    Sudeer Sudeer

    Author

    Is the step 6 should be done in both the servers are only in Master. please let me know. thanks.


  • aip
    Posted on

    aip aip

    Author

    @Sudeer: You only need to perform those steps on a single server which will synchronize to the remote server using SSH.