最近在測試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
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。