使用rsync+inotify的方式监控一个目录,当被监控目录下的子目录被移走后无法同步的问题
2014-06-17 14:31
423 查看
最近在测试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
本文出自 “Linux SA John” 博客,请务必保留此出处http://john88wang.blog.51cto.com/2165294/1427271
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
本文出自 “Linux SA John” 博客,请务必保留此出处http://john88wang.blog.51cto.com/2165294/1427271
相关文章推荐
- Spring boot 使用注解方式无法新建一个后台线程问题
- 使用inotify+rsync 实现文件目录实时同步
- 无法打开多维数据集(使用Dundas的OLAP显示控件时的一个小的问题)
- 一个恶心的无法同步服务器与pda时间的龌龊问题
- 使用网络目录映射虚拟目录出现 500.19 权限不足问题的一个解决办法
- Linux中使用rsync实现多服务器之间文件同步问题
- 有关使用 GPS Intermediate Driver 无法获取到GPS数据的一个问题
- [转载].关于使用QII 10.0编译器无法编辑和查看中文的问题一个变通解决方案
- 使用PLSQL Developer时,“ORA-12154: TNS:无法解析指定的连接标识符”问题的一个解决办法
- 使用rsync进行CentOS服务器之间的目录同步
- 使用PLSQL Developer时,“ORA-12154: TNS:无法解析指定的连接标识符”问题的一个解决办法
- windows2003下asp.Net站点无法使用用户名+密码的方式连接SQLSERVER的问题
- 解决一个页面有两个FCKeditor时,无法使用FCKeditorAPI.GetInstance问题
- rsync+inotify多目录多ip实时同步
- 使用ODBC和OLEDB两种方式执行同一个存储过程,结果不同的问题!
- 一个无法使用 GetGraphics() 的问题
- 使用rsync+inotify配置触发式(实时)远程同步
- 使用rsync+inotify配置触发式(实时)远程同步
- 如何使用inotify编写目录监控程序
- 关于【apache- tomcat- 5.5.15/conf /Catalina/localhost配置虚拟目录】时的一些问题。(配置web项目的方式不止一种,虚拟目录就是一个)