温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

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

发布时间:2020-06-27 14:38:19 来源:网络 阅读:1210 作者:自由linux 栏目:移动开发

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

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



向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI