Syncing files with unison

From LWP-Wiki
Jump to: navigation, search

Installing and configuring Unison File Synchronizer

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.

First follow the SSH how to to set up a direct connection between your LWP and your other computer(s)

1. Install the Unison package (on Debian based systems)

apt-get install unison

2. Configure the Unison defaults (EDIT ~/.unison/default.prf)

# skip asking for confirmations on non-conflicting changes
# the user interface will ask no questions at all
# Unison will request an extra confirmation if it appears that the entire replica has been deleted
# 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$
# the group attributes of the files are synchronized
# the owner attributes of the files are synchronized
# prefer newer version of files in case of conflicts
# the textual user interface will print nothing at all, except in the case of errors.
# file modification times (but not directory modtimes) are propagated.

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.

5. Manually synchronize a directory

unison ~/<dir> ssh://<dir>

This will sync ~/<dir> between the local machine and

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

*/5 * * * * unison ~/<dir> ssh://<dir> &> /dev/null