使用rsync+inotify的方式监控一个目录,当被监控目录下的子目录被移走后无法同步的问题

最近在测试rsync+inotify的方式同步PHP代码到一个集群下的WEB服务器。如被监控的目录是/var/www/html下有三个目录

创新互联公司从2013年开始,先为德城等服务建站,德城等地企业,进行企业商务咨询服务。为德城企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。

dream_android  dream_ios  game_router

当我把dream_android这个目录更名为android后,发现其他服务器上没有出现android并且原有的dream_android并没有被删除。测试游戏时发现大量的404错误,最大的问题就是代码同步出现了问题。

检查同步脚本中inotify和rsync相关的信息

/usr/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f%e' -e   close_write,modify,delete,create,attrib

这里监控/var/www/html 目录下的文件修改,删除,创建和属性更改。查看inotifywait的man手册发现inotifywait有个move的event

/usr/bin/rsync -avz --delete  $src2/    $host::$dst2    这里将目标服多余的文件删除。

rsync的--delete参数奇怪的一点是如果一个目录被重新更名了,但是目录内的文件没有发生改变,将不会被同步出去并删除目标服上其他多余的文件

       moved_to

              A file or directory was moved into a watched directory.  This event occurs even if the file is simply moved from and to the same directory.

       moved_from

              A file or directory was moved from a watched directory.  This event occurs even if the file is simply moved from and to the same directory.

       move  A file or directory was moved from or to a watched directory.   Note  that  this  is  actually implemented  simply  by  listening  for  both  moved_to and moved_from, hence all close events received will be output as one or both of these, not MOVE.

    增加一个move事件就可以监控文件的更名了。

/usr/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f%e' -e move,close_write,modify,delete,create,attrib

分享题目:使用rsync+inotify的方式监控一个目录,当被监控目录下的子目录被移走后无法同步的问题
本文地址:https://www.cdcxhl.com/article0/pgicoo.html

成都网站建设公司_创新互联,为您提供网站设计公司手机网站建设响应式网站网站导航企业网站制作外贸网站建设

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

搜索引擎优化