Real-time synchronization of rsync+inotify data

Source: Internet
Author: User

1, after the installation of Inotify-tools, the/usr/local/bin directory will be a new generation of inotifywait and inotifywatch two instructions;

Inotifywait: Used to wait for a specific event;

Inotifywatch: used to collect monitored file system statistics, including the number of inferior information per inotify event;


The common options for the inotifywait command are as follows:

-M is to keep listening

-R is a recursive view directory

-Q is the print out event

-e <event>,--event <event> Specifies the specific events that need to be monitored, and all file events are monitored by default;

--timefmt <fmt> when using%t in the--format option, the--TIMEFRT option can be used to specify a custom time format that conforms to the strftime specification; the usual parameters after--timefrt are '%d/%m/%y%h:%m ' ;

--format <fmt> custom inotifywait output format, such as--format '%T%w%f '; the usual format characters are as follows:

%T: Use the custom time format in the--TIMEFMT option;

%w: Displays the file name of the monitored files;

%f: If the object of an event is a directory, the name of the monitored directory is displayed, and the default display is an empty string;


2,vim inotify.sh

#!/bin/bash


Src= "/opt/pub"

Dst= "/opt/share"


/opt/app/inotify/bin/inotifywait-mrq--timefmt '%d/%m/%y%h:%m '--format '%T%w%f '-e modify,delete,create,attrib,move $SRC | While read file

Do

Rsync-avzp--delete $src/$DST/

echo "$file was rsynced" >> Rsync.log 2>&1

Done

This article is from the "Linuxdream" blog, make sure to keep this source http://books.blog.51cto.com/2600359/1598957

Real-time synchronization of rsync+inotify 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.