Inotify + rsync

Source: Internet
Author: User

I. Rsync introduction:
Rsync is a data image backup tool in Unix-like systems. It can be seen from the software name-Remote Sync.

Features:
Images can be used to save the entire directory tree and file system.
It is easy to maintain the permissions, time, and soft links of the original file.
Installation without special permissions.
Fast: During the first synchronization, rsync copies all the content, but transfers only modified files in the next synchronization. Rsync can compress and decompress data during data transmission, so it can use less bandwidth.
Security: You can use SCP, ssh, and other methods to transmit files. Of course, you can also use a direct socket connection.

Ii. inotify introduction:
Inotify can monitor files or directories. When a directory is monitored, it can monitor its subdirectories and files at the same time. In addition, inotify uses the file descriptor as an interface. Therefore, you can use the normal file I/O operations select, poll, and epoll to monitor changes in the file system.

Common File System events that inotify can monitor include:
In_access: The file is accessed.
In_modify: File Modified
In_attrib, File Attribute Modified
In_close_write: The file opened in writable mode is disabled.
In_close_nowrite: files opened in non-writable mode are closed.
In_open: The file is opened.
In_moved_from: The file is removed from the monitored directory.
In_moved_to: The file is moved to the monitored directory.
In_create: create a file or subdirectory in the monitored directory
In_delete: the file or directory is deleted.
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

3. inotify-Tools
Inotify is an API that needs to be called by developing applications. For most users, this is inconvenient. The emergence of inotify-tools makes up for this deficiency. Inotify-tools is a set of components, including a C library and several command line tools. These command line tools can be used to monitor events in a file system through command lines or scripts.

Inotify-tools provides two command line tools:
Inotifywait: waits for the corresponding event on the monitored file through the inotify API and returns the monitoring result. By default, normal results are returned to the standard output, the diagnostic class information is returned to the standard error output. It can exit after monitoring the specified event on the corresponding monitoring object, or conduct continuous monitoring.
Inotifywatch: uses the inotify API to collect events related to monitored files or directories and output statistics.

Inotifywait command usage introduction:
Inotifywait is especially suitable for waiting for an event in a script and performing corresponding operations based on a specific event. For example, you can use the script to monitor the changes, creation, deletion, and attribute information on files in a specified directory, then, use the rsync command to synchronize the files corresponding to an event to other hosts. The common options are as follows:
-M, -- monitor: the default action of inotifywait is to exit after a specific event of the specified file is monitored. This option can be used for continuous monitoring;
-R, -- Recursive: recursively monitors all files in a specified directory, including new files or subdirectories. If the number of files in the directory to be monitored is large, you usually need to modify the/proc/sys/fs/inotify/max_users_watchs kernel parameters because the default value is 8192.
-E <event>, -- event <event>: Specifies the specific event to be monitored. All events are monitored by default. <event> here, including access, modify, attrib, close_write, close_nowirte, close, open, moved_to, moved_from, move, create, delete, delete_selt, etc;
-- Timefmt <FMT>: When % T is used in the -- format option, the -- timefrt option can be used to specify a custom time format that complies with the strftime specification, available time format characters can be obtained through the strftime manual page; -- common parameters after timefrt are '% d/% m/% Y % H: % m ';
-- Format <FMT>: Customize the output format of inotifywait, for example, -- format '% T % w % F'. Common Format characters are as follows:
% W: display the name of the monitored file;
% F: if the object of an event is a directory, the name of the monitored directory is displayed. The default value is an empty string;
% T: Use the custom time format in the -- timefmt option.


Inotify + rsync

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.