Rsync + inotify (relatively real-time)
System environment
Cat/etc/issue
CentOS Release 6.6 (Final)
Uname-sr
Linux 2.6.32-504.el6.x86_64
Server Planning
Rsync Server: 192.168.10.241
rsync + inotify-tools Server: 192.168.10.231
Configuring the Rsync server configuration can refer to the relevant configuration of rsync in the blog RSYNC+LSYNCD
1. Configure rsync client and Inotify-tools to implement file real-time synchronization
Edit the Rsync client, provide the add password file, and modify the permissions to 600
echo "123456" >/etc/backserver.pas
chmod 600/etc/backserver.pas
Ll/etc/backserver.pas
-RW-------1 root root 7 Jul 15:34/etc/backserver.pas
Yum Install Inotify-tools-y
Writing synchronization Scripts
1. Local synchronization
Vim lsyncd_local.sh
--------------------------------------------------------------------------------------------------------------- ---------------
#!/bin/bash
Lsync_local () {
Log_path=/home/web
srcpath=/opt/
/usr/bin/inotifywait-mrq--timefmt '%F%T '--format '%e%w%f%T '-e create,delete,modify,move,attrib $SrcPath |whi Le read line
Do
RSYNC-VZRTOPG--progress--delete $SrcPath/tmp/back/
Echo-n "$line" >> ${log_path}/inotify_local_$ (date "+%f"). LOG
Done
}
Lsync_local
--------------------------------------------------------------------------------------------------------------- ---------------
2. Remote synchronization
# Vim Lsync_remote.sh
--------------------------------------------------------------------------------------------------------------- ---------------
#!/bin/bash
Lsync_remote () {
Log_path=/home/web
srcpath=/opt/
/usr/bin/inotifywait-mrq--timefmt '%F%T '--format '%e%w%f%T '-e create,delete,modify,move,attrib $SrcPath |whi Le read line
Do
RSYNC-VZRTOPG--progress--delete $SrcPath [email protected]::home--password-file=/etc/backserver.pas
Echo-n "$line" >> ${log_path}/inotify_remote_$ (date "+%f"). LOG
Done
}
Lsync_remote
--------------------------------------------------------------------------------------------------------------- ---------------
2. Record the synchronization time log
Tailf Inotify_local_2015-07-28.log
modify/opt/test.sh 2015-07-28 16:14:33
Create/opt/test.bak 2015-07-28 16:15:33
Modify/opt/test.bak 2015-07-28 16:15:33
Modify/opt/test.bak 2015-07-28 16:17:34
modify/opt/test.sh 2015-07-28 16:18:04
Delete/opt/test.bak 2015-07-28 16:18:09
modify/opt/test.sh 2015-07-28 16:24:35
modify/opt/test.sh 2015-07-28 16:25:29
This article is from the Linux tours blog, so be sure to keep this source http://openlinuxfly.blog.51cto.com/7120723/1679287
Rsync+inotify for real-time file synchronization