**
建立inotify自動同步指令碼
vim inotify_rsync.sh
#!/bin/sh
src=/home/rsync/test
[email protected]:/home/rsync/test
/bin/su - rsync
/usr/local/bin/inotifywait -mrq -e modify,delete,create,attrib $ | while read d e f
do/usr/bin/rsync -ahqzt --delete $src $dst
done
賦予指令碼可執行許可權
chmod +x inotify_rsync.sh
執行指令碼
/root/inotify_rsync.sh &
設定指令碼開機自啟動
cat "/root/inotify_rsync.sh &" >> /etc/rc.local
#########################################
相關註解如下:
/usr/local/bin/inotifywait -mrq -e modify,delete,create,attrib $
-m 是保持一直監聽
-r 是遞迴檢視目錄
-q 是列印出事件
-e create,move,delete,modify,attrib 是指 「監聽 建立 移動 刪除 寫入 許可權」 事件
/usr/bin/rsync -ahqzt --delete $src $dst
-a 存檔模式
-h 儲存硬連線
-q 制止非錯誤資訊
-z 壓縮檔案資料在傳輸
-t 維護修改時間
-delete 刪除於多餘檔案
要排除同步某個目錄時,為rsync新增--exculde=pattern引數,注意,路徑是相對路徑,具體檢視man rsync。
要排除某個目錄的事件監聽的處理時,為inotifywait新增--exclude或--excludei引數,具體檢視man inotifywait。
inotifywait 命令產生三個返回值,分別是「日期,時間,檔案」 這3個返回值會做為引數傳給read,因此指令碼中的「while read d e f」 寫法細化了返回值。
inotify tools命令使用講解
inotify tools 是為linux下inotify檔案監控工具提供的一套c的開發介面庫函式,同時還提供了一系列的命令列工具,這些工具可以用來監控檔案系統的事件。inotify tools是用c編寫的,除了要求核心支援inotify外,不依賴於其他。inotify tools提供兩種工具,一是...
inotify tools命令使用講解
inotify tools 是為linux下inotify檔案監控工具提供的一套c的開發介面庫函式,同時還提供了一系列的命令列工具,這些工具可以用來監控檔案系統的事件。inotify tools是用c編寫的,除了要求核心支援inotify外,不依賴於其他。inotify tools提供兩種工具,一是...
安裝inotify tools監控工具
yum install y inotify tools root dns3 rpm ql inotify tools usr bin inotifywait usr bin inotifywatch usr lib64 libinotifytools.so.0 usr lib64 libinotif...