linux下rsync的同步( 二 )

安装 inotify在A服务器.部署了机房上使用root安装
cd /home/tar -xvf inotify-tools-3.13.tar.gz

linux下rsync的同步

文章插图
cd inotify-tools-3.13/./configure && make && make install
linux下rsync的同步

文章插图
inotifywait  命令 格式格式:inotifywait -mrq -e 监控动作 1,监控动作 2 /监控目录 &示例:inotifywait -mrq -e create,delete /filesrc &-m:始终保持事件监听状态-r:递归查询目录-q:只打印监控事件的信息监控动作:modify(内容),create,attrib(权限),move,deletersync+inotify实现数据同步使用root操作
在部署机房的服务器上操作
cd /home脚本1:只会同步增加修改的文件,不会同步删除的文件
vi rsync.sh#!/bin/basha="inotifywait -mrq -e create,delete,modify /home/wxq/"b="rsync -avz /home/wxq/ rsync@192.168.10.162:/home/wxq/"$a | while read directory event file  #while 判断是否接收到监控记录do$bdone脚本2:无论是新增还是修改,删除都会同步
a="inotifywait -mrq -e create,attrib,move,delete,modify /home/wxq/"b="rsync -avz --delete /home/wxq/ rsync@192.168.10.162:/home/wxq/"$a | while read directory event filedo$bdone按下 :wq! 即可保存
su rsync我们开始执行脚本
bash /home/rsync.sh &//表示在后台执行
linux下rsync的同步

文章插图
接下来我们看看效果
linux下rsync的同步

文章插图
【linux下rsync的同步】

推荐阅读