Set rsync + inotify in linux to synchronize files in real time

Source: Internet
Author: User
Tags inotify
Linux rsync + inotify real-time file synchronization application scenario: synchronization receiver: test01 receiving Directory:/opt/software/test/a/synchronization initiator: test02 synchronization Directory: /opt/software/test/a/add, create, and ,...
Linux rsync + inotify real-time file synchronization application scenario: synchronization receiver: test01 receiving Directory:/opt/software/test/a/synchronization initiator: test02 synchronization Directory: /opt/software/test/a/add, create, delete, and move operations under the/opt/software/test/a/directory of test02 will be synchronized to/opt/of test01/ software/test/a/directory www.2cto.com Step 1: install rsync (both test01 and test02) yum install rsync Step 2: install inotify (synchronization initiator test02) unzip inotify [root @ test02 software] # tar zxvf inotify-tools-3.14 [root @ test02 inotify-tools-3.14] #. /configure -- prefix =/us R/local/inotify [root @ test02 inotify-tools-3.14] # make [root @ test02 inotify-tools-3.14] # make install Step 3: Configure rsync (synchronization receiver test01) create rsyncd under the/etc directory. conf, the content is as follows: pid file =/var/run/rsyncd. pidport = 873 # address of test01 = 192.168.1.114uid = rootgid = rootuse chroot = yes # hosts allow = 192.168.1.20.hosts deny = * max connections = 5 motd file =/etc/rsyncd. motdlog file =/var/log/rsync. log # transfer logging = yeslog Mat = % t % a % m % f % bsyslog facility = local3timeout = 300 read only = nowrite only = no [ggly] path =/opt/software/test/a/auth users = owenzhanglist = yesigonre errorssecrets file =/etc/rsyncd. secretscomment = gugly rsyc files www.2cto.com create rsyncd in the/etc directory. secrets and Grant 600 the following permissions: # User: Password. the password does not have to be the same as the linux user's password. the user must be the linux user owenzhang: 123123 and create rsyncd in the/etc directory. motd, the content can be written at will. The rsync welcome information runs the rsyncservice xinetd start of test01 and xinetd is not installed. Use yum install xinetd to install Step 4: Configure inotify (synchronization initiator test02) to create the file gglyrsync. sh and grant the execution permission. the file name and location are casual. the content is as follows: www.2cto.com #! /Bin/bash # synchronize the receiver ipclient = 192.168.1.114src =/opt/software/test/a/# synchronize the receiver's rsync module name dest = gugly # synchronize the user = owenzhang/usr/local/inotify/bin/inotifywait-mrq -- timefmt '% d/% m/% y % H: % M' -- format' % T % w % f % e'-e modify, delete, create, move, attrib $ src | while read filesdo/usr/bin/rsync-vzrtopgq -- delete -- progress -- password-file =/opt/software/rsyncpasswd $ src $ user @ $ client :: $ destdone: Create an r in the/opt/software/Directory The syncpasswd file contains the owenzhang password in rsyncd. secrets in test01, that is, 123123. Grant the 600 permission to run gglyrsync. sh.
Related Article

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.