rsync combined with inotify real-time synchronization configuration

Source: Internet
Author: User
Tags event listener inotify rsync man rsync

rsync combined with inotify real-time synchronization configuration

System environment: 192.168.121.128 (source) 192.168.121.129 (Purpose)

192.168.121.129 (Purpose) to install the Rsync service:

Yum install rsync or wget rsync website rsync-3.1.2.tar.gz compiled installation, no parameters required./configure--prefix=/usr/local/rsync

cat /etc/rsyncd.confuid=root//rsync daemon user git=root//// The group use chroot = no // //running the rsync daemon does not use chrootmax connections = 10   //Maximum number of connections limit strict modes = yes//If true, the password file can only be accessed by a user running the rsync server, and no other user can access the file. The default value is true. Pid file = /var/run/rsyncd.pid lock file = /var/run/rsync.lock log  file = /var/log/rsyncd.log [tmp] path = /tmp//directories that need to be synchronized comment =  rsync from 192.168.121.128read only = no write only = no  hosts allow = 192.168.121.128hosts deny = * list = falseuid  = root gid = root auth users = webuser//This user is independent of the system user Secrets file  = /etc/rsync.passwd//defines the authenticated user password file 

cat/etc/rsync.passwd

webuser:password//user and password separated by semicolons


and set the 600 file properties:

chmod 600/etc/rsync.passwd


To start the Rsync service:

/usr/local/rsync/bin/rsync--port=873--address=192.168.121.129--daemon


To do a push test on the 192.168.121.128 (source) Host:

RSYNC-AVH--delete--password-file=/etc/rsync.passwd/tmp/[email protected]::tmp


#注意:/tmp directory default system is already there, if synchronization of other directories, the source host must have, but the destination host may not have, need to manually create, otherwise will error, cannot find the directory, synchronization failed.



192.168.121.128 Source Host Installation INotify service

Download installation

# wget http://nchc.dl.sourceforge.net/project/inotify-tools/inotify-tools/3.13/inotify-tools-3.13.tar.gz# Tar xzvf inotify-tools-3.14.tar.gz# CD inotify-tools-3.13#./configure--prefix=/usr/local/inotify# make# make install


To create a inotify_rsync.sh script:

cat inotify_rsync.sh#!/bin/sh#function:rysnc 192.168.121.128  to   192.168.121.129if [ ! -f /etc/rsync.passwd ];then         echo  "Password" >/etc/rsync.passwd        /bin/ Chmod 600 /etc/rsync.passwdfilog=/usr/local/inotify/logs/rsync.logsrc= "/tmp/" #注意src如果为/tmp, The TMP directory will be synchronized to the target host, the/tmp/tmp recursive directory appears, so you need to synchronize the files in that directory, need to/end. Host= "192.168.121.129" module= "tmp"/usr/local/inotify/bin/inotifywait -mr --timefmt  '%d/%m/%y  %h:%m '  --format  '%t %w %f '  -e close_write,modify,delete,create,attrib   $SRC  |  while read date time dir file; dofilechange=${dir}$ {FILE}/USR/BIN/RSYNC -AVH --DELETE  --PROGRESS --PASSWORD-FILE=/ETC/RSYNC.PASSWD   $SRC   --exclude-from= "/usr/local/inotify/logs/rules.txt"  [email protected] $host:: $module &echo  "at ${time} on ${date}, file  $FILECHANGE  was  Backed up via rsync " >>  $logdone



#脚本中有delete参数, the test environment can come casually, the production environment is recommended to prohibit the delete parameter.


mkdir/usr/local/inotify/logs//if no directories or files need to be created manually touch/usr/local/inotify/logs/rules.txt


The relevant notes are as follows:

/usr/local/bin/inotifywait-mrq-e Modify,delete,create,attrib ${SRC}

-M is to keep listening

-R is a recursive view directory

-Q is the print out event


-e Close_write,modify,delete,create,attrib refers to the "Listen for create mobile Delete Write permission" event


/USR/BIN/RSYNC-AVH--delete--progress--password-file

-A archive mode

-H Save Hard Connection

-delete deletion of redundant files

--password-file Password file

Today's parameters can be man rsync


To exclude synchronizing a directory, add the--exculde=pattern parameter to rsync, and note that the path is a relative path, specifically to view man rsync.

To exclude the processing of an event listener for a directory, add the--exclude or--excludei parameter to inotifywait to see the man inotifywait.

--exclude-from= "/usr/local/inotify/logs/rules.txt" can match filter files:

If you exclude files that include. SVN:

#cat/usr/local/inotify/logs/rules.txt

-*.svn*


The inotifywait command produces three return values, namely "date, time, file", which are passed as parameters to read, so that the "while read D E F" in the script refines the return value.


Give script permission to execute

#chmod +x inotify_rsync.sh


Run

#sh iotify_rsync.sh &





This article is from the "LINUX Super Dream" blog, make sure to keep this source http://215687833.blog.51cto.com/6724358/1883500

rsync combined with inotify real-time synchronization configuration

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.