Copy files from the remote rsync server to the local machine. This mode is started when the SRC path information contains the "::" delimiter.
Copy files from the local machine to the remote rsync server. This mode is started when the DST path information contains the "::" delimiter.
The main contents of the configuration file are as follows:
UID = Rootgid = Rootport = 873max Connections = 200timeout = 600pid File =/var/run/rsyncd.pidlog File =/var/log/rsync.lo Glockfile =/VAR/RUN/RSYNCD.LOCKMOTD File =/etc/rsyncd/rsyncd.mothlog format =%t%a%m%f%bsyslog facility = Local3host Allow = 10.34.38.130host deny = *[test]path =/home/rsyncignore Errors = Yeslist = Noignore Errorsread only = Noauth user s = roothost Allow = 10.34.38.130secrets file =/etc/rsyncd/rsyncd.secrets
To start the Rsync service:
Rsync--daemon starts the rsync service as a daemon
--address binding a specified IP address to service
--config=xxx specifying the configuration file path
--port= 897 Specifies the port, not the default port when using
Rsync parameters:
-A operates in archive mode, replicates directories, and symbolic connections are equivalent to-rlptgod
-R is recursive
-L is a linked file, which means copying a linked file
-P Keep File original permissions
-T keep the file in its original time
-G hold file original user group
-O Keep File original owner
-d equivalent to block device files
-Z Compression during transfer
-P Transfer Progress
-V Transfer Progress message, and-P point relationship
-e SSH parameters establish an encrypted connection
-U only updates to prevent local new files from being rewritten, noting both machine clocks while
--progress means to show detailed progress
--delete means that if the server side deletes the file, then the client will also delete the file accordingly, maintaining a true consistency
--PASSWORD-FILE=/PASSWORD/PATH/FILE Specifies the password file so that it can be used in the script without having to enter the authentication password interactively, it is important to note that the password file permission attribute is set to only the primary readable
--exclude use when uploading a file that is not included
The password file has permission set to 600 that is chmod 600/etc/xxx/password
Packaged:
TAR-ZCVF html_$ (Date +%f). tar.gz./html/
Push:
RSYNC-AVZP html_2015-01-03.tar.gz [Email protected]::test--password-file=/etc/rsync/rsync.password The file directory stored behind the password
Find/xxx-type f-name "*.gz"-mtime +7 | Xargs rm-f
Rsync-avzp--delete a/b/Copy the content under a to B and delete the original file contents in B
RSYNC-AVZP--delete b/[email protected]::test--password-file=/etc/rsync/rsync.password synchronizes content from local A to the rsync server, synchronizing the contents of a, If there is anything else on the server, it will be erased.
INotify Tools
Inotify is a powerful, fine-grained, asynchronous file system event monitoring mechanism, the Linux kernel from 2.6.13, joined the Inotify support, through Inotify can monitor the file system to add, delete, modify, move and other subtle events, using this kernel interface, Third-party software can monitor the file system under the various changes, and inotify-tools is such a third-party software.
In the above section, we mentioned that rsync can achieve triggered file synchronization, but through the crontab daemon mode trigger, synchronous data and actual data will be different, and inotify can monitor the file system changes, when the file has any changes, trigger rsync synchronization, This just solves the real-time problem of synchronizing data.
Inotifywait Related parameters:
Inotifywait is a monitoring wait event that can be used with a shell script, which describes some of the commonly used parameters:
-M, which is--monitor, indicates that the event listening state is always maintained
-R,--recursive, which represents a recursive query directory
-Q, which is--quiet, indicates that a monitoring event is printed out
-E,--event, this parameter allows you to specify the events to monitor, common events such as modify, delete, create, attrib, etc.
--TIMEFMT: The output format for the specified time
--format: Specify details for the change file
These two parameters are generally used together, by specifying the output format, with the output similar to:
15/04/10 00:29/web/www/xxxx.shdelete,isdir was rsynced
15/04/10 00:30/web/www/index.htmlmodify was rsynced
The corresponding script is:
#!/bin/bashsrc=/root/rsync/des1=testhost=10.34.38.128user=root/usr/local/bin/inotifywait-mrq--timefmt '%d/%m/%y %h:%m '--format '%T%w%f%e '-e close_write,delete,create,attrib $src |while read Filesdo/usr/bin/rsync-avzp--delete $src [Email protected] $host:: $des 1--password-file=/etc/rsync/rsync.passwordecho "${files} was rsynced" >>/var/log/ Rsync2.log 2>&1done###########################################################
The purpose of this script is to monitor file directory changes through inotify, which triggers rsync to synchronize operations, because this process is an active trigger operation, through the system kernel, so, compared to those who traverse the entire directory of the scanning method, the efficiency is much higher.
Sometimes this happens: when writing a large file to a inotify-monitored directory (this is/root/rsync), it takes a while to write the large file, and INotify continues to output the updated information of the file. This will continue to trigger rsync to perform synchronous operation, occupy a large number of system resources, then the best way to do this is to wait for the file to be finished before triggering rsync synchronization. In this case, you can modify the INotify monitoring event, namely: "-e Close_write,delete,create,attrib".
Add this script/etc/rsync/inotify.sh to the System self-boot file
chmod +x inotify.sh
echo "/etc/rsync/inotify.sh &" >>/etc/rc.local
At this point, you can test the success of the synchronization!!
Article referenced: http://ixdba.blog.51cto.com/2895551/580280
This article from the "Day Up goto" blog, please be sure to keep this source http://ttxsgoto.blog.51cto.com/4943095/1599140
Rsync+inotify syncing notes in real time