Inotify + Rsync for Real-Time linux file synchronization

Source: Internet
Author: User
Tags inotify
Article Title: Inotify + Rsync achieves real-time synchronization of linux Files. Linux is a technology channel of the IT lab in China. Including desktop applications, Linux system management, kernel research, embedded systems, open-source, and other basic classification, the company uses a set of systems to synchronize the use of donotify, and does not implement real-time synchronization of sub-directories. by querying data, inotify can be used to synchronize subdirectories in real time. The following are notes.

  I. Introduction

Inotify is a file system event monitoring mechanism, which is an effective alternative to dnotify. Dnotify is a file monitoring mechanism supported by earlier kernels. Inotify is a powerful, fine-grained, asynchronous mechanism that meets various file monitoring needs, not limited to security and performance.

Inotify can monitor the following file system events:

IN_ACCESS: The file is accessed.

IN_MODIFY, the file is written

IN_ATTRIB: file attributes are modified, such as chmod, chown, and touch.

IN_CLOSE_WRITE, writable file closed

IN_CLOSE_NOWRITE: the file cannot be written.

IN_OPEN, the file is open

IN_MOVED_FROM: The file is removed, such as mv.

IN_MOVED_TO: The file is moved, such as mv and cp.

IN_CREATE, create a new file

IN_DELETE: The file is deleted, such as rm.

IN_DELETE_SELF: indicates that an executable file is deleted when it is executed.

IN_MOVE_SELF, self-moving, that is, an executable file moves itself during execution

IN_UNMOUNT, the host file system is umount

IN_CLOSE, the file is closed, equivalent to (IN_CLOSE_WRITE | IN_CLOSE_NOWRITE)

IN_MOVE: The file is moved, equivalent to (IN_MOVED_FROM | IN_MOVED_TO)

Note: The files mentioned above also include directories.

 2. To use the inotify feature in shell, you need to install inotify-tools

1. inotify-tools: The general purpose of this package is to allow inotify's features to be used from within shell scripts.

: Http://inotify-tools.sourceforge.net/

Compile and install

./Configure

Make

Make install

Check manpage, man inotify, and man inotifywait.

1) inotifywait only blocks and waits for inotify events. You can monitor any group of files and directories, or monitor the entire directory tree (directories, subdirectories, etc ). Use inotifywait in shell scripts.

2) inotifywatch collects statistics about the monitored file system, including how many times each inotify event occurs.

2. System Parameters of inotify:

/Proc interfaces

The following interfaces can be used to limit the amount of kernel memory consumed by inotify:

/Proc/sys/fs/inotify/max_queued_events

The value in this file is used when an application callinotify_init (2) to set an upper limit on the number of events that can be queued to the corresponding inotify instance. events in excess of this limit are dropped, but an IN_Q_OVERFLOW event is always generated.

/Proc/sys/fs/inotify/max_user_instances

This specifies an upper limit on the number of inotify instances that can be created per real user ID.

/Proc/sys/fs/inotify/max_user_watches

This specifies a limit on the number of watches that can be associated with each inotify instance.

[1] [2] [3] Next page

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.