资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

使用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的方式监控一个目录,当被监控目录下的子目录被移走后无法同步的问题
URL标题:http://cdkjz.cn/article/pgicoo.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220