续rsync +inotify_rsync inotify数据实施同步

如图,内容不解释,保持服务器

   更正图:rsyncservice 192.168.56.69                  rsync client 192.168.56.60

●rsync service创建目录已经用户并且使用户无法登录,授权用户给共享目录;

#useradd rsync -s /sbin/nologin -M

#mkdir -p /root/nanwang

#chown -R rsync.rsync /root/nanwang

#echo "rsync_backup:666666" >> /etc/rsync.password

#chmod 600 /etc/rsync.password

●配置rsync服务器

[root@p_w_picpath data]# more /etc/rsyncd.conf
uid = rsync
gid = rsync
use chroot = no
max connections = 99999
timeout = 300
pid file =/var/run/rsyncd.pid
lock file = /var/run/rsyncd.lock
log file = /var/log/rsyncd.log
[umaildata]
path=/root/data
comment = umailtest
ignore errors
read only = false
list = false
hosts allow = 192.168.56.0/24
hosts deny = *
auth users = rsync_backup
secrets file = /etc/rsync.password

● 辅助服务器为inotify以及rsync客户端

配置inotify

下载并且编译inotify 工具。

 #  tar zxf inotify-tools-3.14.tar.gz

#  cd inotify-tools-3.14

#  ./configure --prefix=/usr/local/  && make && make install

[root@p_w_picpath ~]# more /root/tools/rsyncinotify.sh
   date=date+%F
   /usr/local/bin/inotifywait -mr --timefmt '%d/%m/%y %H:%M' --format '%T %w %f' \
-e close_write /root/nw/ | while read date time dir file;
   do
   rsync -az  /root/nw/ rsync://rsync_backup@192.168.56.69/umaildata --password-file=/etc/rsync.password & >> /dev/null 2>1 \
  echo "At $date file umaildata was backed up via rsync" >> /var/log/rsyncinotify.log
  done