Monday, January 28, 2013

2 Way Synchronization with Unison

2 Way directory Synchronization

I found unison is a better option than rsync if the files in both locations frequently change, or if you want to synchronise between more than 2 locations. and you need to keep all locations synchronised.

yum install unison 
on all machines that you want to synchronise between.

for password-less sync make sure you setup ssh private/public key
as described in this previous post ssh public/private key

create a file


copy and paste the following into your file

# set paths / dirs

# binary file name

# server names 
# sync local +server1 with server2 and server3

# sync it
for r in ${_rserver}
        for p in ${_paths}
                ${_unison} -batch -force newer -times "${p}"  "ssh://${r}/${p}"

save the file and give it execute rights

chmod + x

to run the script on a cronjob every half an hour and output details into a log file

crontab -e

and add the following

*/30 * * * * /path/to/ &>/var/log/

save and you are done.


No comments: