Rsync and rsync + inotify

Source: Internet
Author: User
Tags inotify syslog rsync

Rsync and rsync + inotify

Rsync is a data image backup tool in Unix-like systems -- remotesync. A Fast Incremental Backup Tool, Remote Sync, supports local replication or synchronization with other SSH and rsync hosts. Rsync is managed by a super process with the Service port 873.

Features:

1. images can be used to save the entire directory tree or file system;

2. High data transmission efficiency;

3. Secure data transmission through SSH;

4. Anonymous transmission is supported.

Working Mode:

1. Shell mode, also known as local mode

2. In remote shell mode, you can use the SSH protocol to host the remote transmission process. There are two commands:

3. In list mode, only content in the source is listed.-NV

4. In service mode, rsync works as a daemon to receive data synchronization requests from the client;

 

The following describes how to use rsync.

Options for common rsync commands:

-N: synchronization test. The real synchronization process is not executed;

-V: Detailed output mode

-Q: silent mode

-C: Checksum, enabling the verification function

-R: recursive Replication

-A: Archive and retain the original attributes of the file;

-P: retain the File Permission;

-T: The timestamp of the file to be retained;

-L: Reserved Symbolic Links

-G: reserved group

-O: retain the owner

-D: Keep the device file.

 

-E ssh: Use SSH for transmission;

-Z: Compressed and transmitted;

 

-- Progress: display progress bar

-- Stats: shows how to perform compression and transmission.

Note: In the rsync command, if the source path is a directory and there is/at the end of the copy path, the contents in the directory will be copied instead of the Directory direction; if there is no/at the end /, the directory itself and all files in the directory will be synchronized; whether or not there is/irrelevant to the end of the target path;

 

Example: [[email protected] ~] # Rsync-r -- stats-e SSH -- Progress/etc/PAM. d [email protected]:/RMP/copy files from the local machine to another host


 

The following describes the service mode of rsync and the combination of rsync and inotify for Real-time Data Synchronization and update.

Rsync Service Mode

1. Set the rsync server

# Yum-y install xinetd

# Chkconfig rsync on

2. Provide configuration files for rsync

/Etc/rsyncd. conf

The configuration file is divided into two sections:

Global configuration segment: 1

Shared configuration segments: Multiple

Configuration example:

# Global settings

Uid = Nobody // the user who runs the rsync daemon

Gid = Nobody // the group that runs the rsync daemon

Use chroot = No // do not use chroot

Max connections = 10 // The maximum number of connections is unlimited

Strict modes = Yes // do you want to work in strict mode?

PID file =/var/run/rsyncd. PID // lock file storage location

Log File =/var/log/rsyncd. Log // location where the log file is stored

# Directory to be synced

[Tools] // The Authentication Module name, which must be specified on the client.

Path =/Data // directory to be synchronized, which is indispensable

Ignore errors = Yes // indicates whether to continue copying (yes) or stop copying (NO) if an error occurs during file copying)

Read Only = No // non-read-only

Write only = No // not write only

Hosts allow = 172.16.0.0/16 // which hosts are allowed for access and whitelist?

Hosts deny = * // blacklist

List = false // whether to allow users to list objects

Uid = root //

Gid = root

3. Start the service

# Service xinetd start

Check whether the port is listening on port 873/tcp after it is started.

4. Use the server to enable the authentication function

1) Add configuration in the shared definition to implement

[Tools]

Path =/Data

Ignore errors = Yes

Read Only = No

Write only = No

Hosts allow = 172.16.0.0/16

Hosts deny = *

List = false

Uid = root

Gid = root

Auth users = username list // The authenticated user name. If this row is not displayed, it indicates that the user is anonymous and has nothing to do with the system.

Secrets file =/etc/rsyncd. passwd // table of password and user name comparison, which is generated by the password file.

Note: The username list is a comma-separated list of usernames in rsyncd. passwd;

2) create a password file (the File Permission is 600, this file cannot allow other users to have permissions, and the user password cannot exceed 8 digits)

Format: Username: Password

3) restart the service to implement authentication.

 

 

Use of rsync + inotify

The instance is implemented using two servers. The file server IP address is 172.16.25.1, And the inotify Server IP address is 172.16.25.2.

First, set up the environment required by the File Server

[[Email protected] ~] # Yum install xinetd-y // install the super daemon [[email protected] ~] # Mkdir/root/Data // create the shared directory [[email protected] data] # Vim/etc/rsyncd. conf // configure the rsync service configuration file (the following file configuration items are described in detail in the preceding rsync service mode, which is not described in detail here) # global settingsuid = nobodygid = nobodyuse chroot = nomax connections = 10 strict modes = yespid file =/var/run/rsyncd. pidlog file =/var/log/rsyncd. log # directory to be synced [tools] Path =/root/data/ignore errors = yesread only = nowrite only = nohosts allow = 172.16.0.0/16 hosts deny = * List = falseuid = rootgid = rootauth users = nydiasecrets file =/etc/rsyncd. passwd [[email protected] data] # Vim/etc/rsyncd. passwd // create the authentication user's password file Nydia: Nydia // The file content only needs to fill in the user and password and use: to separate, set the permission for this file to 600 [[email protected] data] # chkconfig rsync on // Add the service to the startup list [[email protected] data] # service xinetd start // then, start the super daemon service to complete rsync file server configuration.


 

Inotify Server Configuration

First, introduce the inotify overview and usage, and then start to configure the service.

Inotify is a Linux feature that monitors file system operations, such as reading, writing, and creating. Inotify is responsive, easy to use, and much more efficient than the busy polling of cron tasks. Learn how to integrate inotify into your application and discover a group of command line tools that can be used to further automate system governance.

Inotifywait

Syntax:
Inotifywait [-hcmrq] [-E] [-T] [-- format] [-- timefmt] [...]
Parameters:
-H,-help
Output help information
@
Exclude files that do not need to be monitored. They can be relative paths or absolute paths.
-Fromfile
Read the files to be monitored or excluded from the file. A row of files starts.
-M,-Monitor
If a task is received without exiting, it is executed indefinitely. The default action is to exit immediately after receiving a message.
-D,-daemon
Like-Monitor, apart from running in the background, you must specify-OUTFILE to output the event to a file. -Syslog is also used.
-O,-OUTFILE
Output a task to a file instead of a standard output.
-S,-syslog
Output Error information to system logs
-R,-recursive
Monitors all subdirectories in a directory.
-Q,-quiet
If this parameter is specified once, no detailed information is output. If the parameter is specified twice, no information is output except fatal errors.
-Exclude
Files to be excluded from regular expression matching are case sensitive.
-Excludei
The file to be excluded by regular expression matching. case insensitive.
-T,-Timeout
Set the timeout value. If the value is 0, it is executed indefinitely.
-E,-Event
Specifies the event to be monitored.
-C,-CSV
Output CSV format.
-Timefmt
Specifies the time format, used in the-format option % t format.
-Format
Specify the output format.
% W indicates the directory where the event occurred
% F indicates the file in which the event occurred
% E indicates the event
% Xe events are separated by "X"
% T uses the time format defined by-timefmt

Inotifywatch

Syntax:
Inotifywatch [-hvzrqf] [-E] [-T] [-A] [-D] [...]
Parameters:
-H,-help
Output help information
-V,-verbose
Output details
@
Exclude files that do not need to be monitored. They can be relative paths or absolute paths.
-Fromfile
Read the files to be monitored or excluded from the file. A row of files starts.
-Z,-zero
Output table rows and columns, even if the element is empty
-Exclude
Files to be excluded from regular expression matching are case sensitive.
-Excludei
The file to be excluded by regular expression matching. case insensitive.
-R,-recursive
Monitors all subdirectories in a directory.
-T,-Timeout
Set timeout
-E,-Event
Only listens to specified events.
-A,-ascending
Sort events in ascending order.
-D,-descending
Sort events in descending order.

Event listening

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/47/AA/wKiom1P9opiAthPzAAIpJIdZv20921.jpg "Title =" 2014-08-27_165844.jpg "alt =" wkiom1p9opiathpzaaipjidzv20921.jpg "/>

Note: The information in inotifywatch is reproduced at http://www.51rhca.com/archives/133.

After a brief introduction, we will start to configure the service.

[[Email protected] ~] # Yum installinotify-tools-y // installation toolkit [[email protected] ~] #/Usr/bin/inotifywait-mrq-e modify, delete, create, attrib/root/Data // Use this command to test the inotify tool effect, when you create a file under/root/data, the inotify tool will prompt you [[email protected] ~] # Vim/tmp/inotify. Sh // edit the script for automatically updating inotify #! /Bin/bash/usr/bin/inotifywait-mrq-timefmt '% d/% m/% Y % H: % m' -- format' % T % w % F'-e modify, delete, create, attrib/root/data/| while read filedo/usr/bin/rsync-vzrtopg -- delete -- password-file =/etc/rsyncd. passwd -- Progress/root/data/[email protected]: toolsecho "$ {files} was rsynced">/var/log/rsync. log 2> & 1 done [[email protected] ~] # Vim/etc/rsyncd. passwd // create this file and fill in the file server's user password Nydia [[email protected] TMP] # bash + x inotify. sh // the file can be run after the file is created, and the inotify service is configured, now, you only need to test [email protected] data] # Touch 3.abc // create a file in the/root/data directory of the current server, then you can see related prompts for the script you just compiled, and you can view the synchronized files on the file server.


 

 


This article is from the "Learning ing" blog, please be sure to keep this source http://nydia.blog.51cto.com/6404696/1545806

Rsync and rsync + inotify

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.