最近在測試rsync+inotify的方式同步PHP代碼到一個(gè)集群下的WEB服務(wù)器。如被監(jiān)控的目錄是/var/www/html下有三個(gè)目錄
創(chuàng)新互聯(lián)公司從2013年開始,先為德城等服務(wù)建站,德城等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢服務(wù)。為德城企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。
dream_android dream_ios game_router
當(dāng)我把dream_android這個(gè)目錄更名為android后,發(fā)現(xiàn)其他服務(wù)器上沒有出現(xiàn)android并且原有的dream_android并沒有被刪除。測試游戲時(shí)發(fā)現(xiàn)大量的404錯(cuò)誤,最大的問題就是代碼同步出現(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有個(gè)move的event
/usr/bin/rsync -avz --delete $src2/ $host::$dst2 這里將目標(biāo)服多余的文件刪除。
rsync的--delete參數(shù)奇怪的一點(diǎn)是如果一個(gè)目錄被重新更名了,但是目錄內(nèi)的文件沒有發(fā)生改變,將不會被同步出去并刪除目標(biāo)服上其他多余的文件
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.
增加一個(gè)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
分享題目:使用rsync+inotify的方式監(jiān)控一個(gè)目錄,當(dāng)被監(jiān)控目錄下的子目錄被移走后無法同步的問題
本文地址:http://www.chinadenli.net/article0/pgicoo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站設(shè)計(jì)公司、手機(jī)網(wǎng)站建設(shè)、響應(yīng)式網(wǎng)站、網(wǎng)站導(dǎo)航、企業(yè)網(wǎng)站制作、外貿(mào)網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)