Syncing files with unison: Difference between revisions

From LWP-Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 4: Line 4:
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.
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 [https://lwp2-wiki.webhosting.rug.nl/index.php?title=Ssh_to_lwp| SSH how to] to set up a direct connection between your LWP and your other computer(s)'''
'''First follow the [https://lwpwiki.webhosting.rug.nl/index.php?title=Ssh_to_lwp| 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)
1. Install the Unison package (on Debian based systems)

Revision as of 14:55, 12 February 2015

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
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.

5. Manually synchronize a directory

unison ~/<dir> ssh://PC-Work.fac.rug.nl//~/<dir>

This will sync ~/<dir> between the local machine and PC-Work.fac.rug.nl

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

*/5 * * * * unison ~/<dir> ssh://PC-Work.fac.rug.nl//~/<dir> &> /dev/null