溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》
  • 首頁 > 
  • 教程 > 
  • 開發技術 > 
  • 移動開發 > 
  • 使用rsync+inotify的方式監控一個目錄,當被監控目錄下的子目錄被移走后無法同步的問題

使用rsync+inotify的方式監控一個目錄,當被監控目錄下的子目錄被移走后無法同步的問題

發布時間:2020-06-27 14:38:19 來源:網絡 閱讀:1274 作者:自由linux 欄目:移動開發

最近在測試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



向AI問一下細節

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

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女