最近在測試rsync+inotify的方式同步PHP代碼到一個集群下的WEB服務(wù)器。如被監(jiān)控的目錄是/var/www/html下有三個目錄
創(chuàng)新互聯(lián)公司從2013年開始,先為德城等服務(wù)建站,德城等地企業(yè),進行企業(yè)商務(wù)咨詢服務(wù)。為德城企業(yè)網(wǎng)站制作PC+手機+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。
dream_android dream_ios game_router
當我把dream_android這個目錄更名為android后,發(fā)現(xiàn)其他服務(wù)器上沒有出現(xiàn)android并且原有的dream_android并沒有被刪除。測試游戲時發(fā)現(xiàn)大量的404錯誤,最大的問題就是代碼同步出現(xiàn)了問題。
檢查同步腳本中inotify和rsync相關(guān)的信息
/usr/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f%e' -e close_write,modify,delete,create,attrib
這里監(jiān)控/var/www/html 目錄下的文件修改,刪除,創(chuàng)建和屬性更改。查看inotifywait的man手冊發(fā)現(xiàn)inotifywait有個move的event
/usr/bin/rsync -avz --delete $src2/ $host::$dst2 這里將目標服多余的文件刪除。
rsync的--delete參數(shù)奇怪的一點是如果一個目錄被重新更名了,但是目錄內(nèi)的文件沒有發(fā)生改變,將不會被同步出去并刪除目標服上其他多余的文件
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事件就可以監(jiān)控文件的更名了。
/usr/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f%e' -e move,close_write,modify,delete,create,attrib