Using unison+inotify to realize bidirectional real-time synchronization of data

Source: Internet
Author: User
Tags inotify ocaml


Using unison+inotify to realize bidirectional real-time synchronization of data


Environment: Centos 6.5 64-bit

server1:192.168.1.201

server2:192.168.1.250

Requirements software: OCaml Unison inotify

I am all installed using Yum, if you like to use the source code compiled installation can download the source package.

Yum Install OCaml unison inotify


The first step : To ensure that the two servers can be accessed via SSH without password, in order to secure, you need to create a normal user:

The same steps are performed on both sides:

Useradd Unison

passwd Unison

Su-unison

Ssh-keygen-t RSA (direct three-time return)

mkdir. SSH

SCP. Ssh/id_rsa.pub 192.168.1.250:/home/unison/.ssh/authrized_keys

SCP. Ssh/id_rsa.pub 192.168.1.201:/home/unison/.ssh/authrized_keys

chmod. SSH


Step two: Create a shell script to perform the synchronization

On the Server1.

vim/home/unison/inotify.sh

#! /bin/bash

Ip2= "192.168.1.250"

Src2= "/home/unison/test"

Dst2= "/home/unison/test"

/usr/bin/inotifywait-mrq-e Create,delete,modify,move $SRC 2 | while read line; Do

/usr/bin/unison-batch $src 2 ssh://$ip 2//$DST 2

Echo-n "$line" >>/home/unison/inotify.log

Echo ' date| Cut-d '-f1-4 ' >>/home/unison/inotify.log

Done

To create a script on Server2:

#! /bin/bash

ip1= "192.168.1.201"

src1= "/home/unison/test"

dst1= "/home/unison/test"

/usr/bin/inotifywait-mrq-e Create,delete,modify,move $SRC 1 | while read line; Do

/usr/bin/unison-batch $src 1 ssh://$ip 1//$DST 1

Echo-n "$line" >>/home/unison/inotify.log

Echo ' date| Cut-d '-f1-4 ' >>/home/unison/inotify.log

Done


Finally, the script can be executed on two servers respectively.

If you want to start the boot, you can add to the/etc/rc.d/rc.local.

This article from the "Shallow faint" blog, please be sure to keep this source http://cuixiang.blog.51cto.com/8204722/1678737

Using unison+inotify to realize bidirectional real-time synchronization of data

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.