国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Linux > 正文

Inotify+Rsync實現linux文件實時同步

2024-08-28 00:00:15
字體:
來源:轉載
供稿:網友

公司一套系統的同步使用的donotify,不能實現子目錄的實時同步,通過查資料,發現inotify可以實現子目錄的實時同步,以下為筆記。

  一、介紹

  Inotify 是文件系統事件監控機制,作為 dnotify 的有效替代。dnotify 是較早內核支持的文件監控機制。Inotify 是一種強大的、細粒度的、異步的機制,它滿足各種各樣的文件監控需要,不僅限于安全和性能。

  inotify 可以監視的文件系統事件包括:

  IN_ACCESS,即文件被訪問

  IN_MODIFY,文件被 write

  IN_ATTRIB,文件屬性被修改,如 chmod、chown、touch 等

  IN_CLOSE_WRITE,可寫文件被 close

  IN_CLOSE_NOWRITE,不可寫文件被 close

  IN_OPEN,文件被 open

  IN_MOVED_FROM,文件被移走,如 mv

  IN_MOVED_TO,文件被移來,如 mv、cp

  IN_CREATE,創建新文件

  IN_DELETE,文件被刪除,如 rm

  IN_DELETE_SELF,自刪除,即一個可執行文件在執行時刪除自己

  IN_MOVE_SELF,自移動,即一個可執行文件在執行時移動自己

  IN_UNMOUNT,宿主文件系統被 umount

  IN_CLOSE,文件被關閉,等同于(IN_CLOSE_WRITE | IN_CLOSE_NOWRITE)

  IN_MOVE,文件被移動,等同于(IN_MOVED_FROM | IN_MOVED_TO)

  注:上面所說的文件也包括目錄。

  二、為能在shell下使用inotify特性,需要安裝inotify-tools

  1、inotify-tools:The general purpose of this package is to allow inotify's features to be used from within shell scripts.

  下載地址:http://inotify-tools.sourceforge.net/

  編譯安裝

  ./configure

  make

  make install

  完成后,注意查看manpage,man inotify 、 man inotifywait

   1)inotifywait 僅執行阻塞,等待 inotify 事件。您可以監控任何一組文件和目錄,或監控整個目錄樹(目錄、子目錄、子目錄的子目錄等等)。在 shell 腳本中使用 inotifywait。

   2)inotifywatch 收集關于被監視的文件系統的統計數據,包括每個 inotify 事件發生多少次。

  2、inotify的系統相關參數:

  /proc interfaces

  The following interfaces can be used to limit the amount of kernel memory consumed by inotify:

  /proc/sys/fs/inotify/max_queued_events

  The value in this file is used when an application calls inotify_init(2) to set an upper limit on the number of events that can be queued to the corresponding inotify instance. Events in excess of this limit are dropped, but an IN_Q_OVERFLOW event is always generated.

  /proc/sys/fs/inotify/max_user_instances

  This specifies an upper limit on the number of inotify instances that can be created per real user ID.

  /proc/sys/fs/inotify/max_user_watches

  This specifies a limit on the number of watches that can be associated with each inotify instance.

  3、inotifywait 相關的參數(更多,查看manpage):

  inotifywait

  This command simply blocks for inotify events, making it appropriate for use in shell scripts. It can watch any set of files and directories, and can recursively watch entire directory trees.

  -m, --monitor

  Instead of exiting after receiving a single event, execute indefinitely. The default behaviour is to exit after the first event occurs.

  -r, --recursive

  Watch all subdirectories of any directories passed as arguments. Watches will be set up recursively to an unlimited depth. Symbolic links are not

  traversed. Newly created subdirectories will also be watched.

  -q, --quiet

  If specified once, the program will be less verbose. Specifically, it will not state when it has completed establishing all inotify watches.

  -e , --event

   Listen for specific event(s) only. The events which can be listened for are listed in the EVENTS section. This option can be specified more than once. If omitted, all events are listened for. use“,”separate multi events


 

  三、使用

  1.查看是否支持inotify,從kernel 2.6.13開始正式并入內核,RHEL5已經支持。看看是否有 /proc/sys/fs/inotify/目錄,以確定內核是否支持inotify 

[root@RHEL5 Rsync]# ll /proc/sys/fs/inotify
total
0
-rw-r--r-- 1 root root 0 Oct  9 09:36 max_queued_events
-rw-r--r-- 1 root root 0 Oct  9 09:36 max_user_instances
-rw-r--r-- 1 root root 0 Oct  9 09:36 max_user_watches
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 自贡市| 承德县| 长沙县| 城固县| 松原市| 秦安县| 合阳县| 墨脱县| 内江市| 东兴市| 浙江省| 永德县| 长武县| 永州市| 贵南县| 前郭尔| 云龙县| 内丘县| 临沧市| 当阳市| 平罗县| 丰台区| 廉江市| 全椒县| 大理市| 都江堰市| 塘沽区| 石景山区| 龙里县| 岳阳县| 璧山县| 内江市| 平原县| 库伦旗| 宜川县| 邢台市| 安泽县| 祁门县| 右玉县| 东乡县| 庐江县|