最近在测试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的方式监控一个目录,当被监控目录下的子目录被移走后无法同步的问题
分享路径:http://lswzjz.com/article/pgicoo.html