inotify結合rsync監控目錄的實時變化

inotify結合rsync監控目錄的實時變化

Inotigy安裝使用

/bin/sh/server/scripts/inotify.sh & 放入rc.local配置文件,自行啓動

優點:監控文件系統事件變化,通過同步工具實現數據實時同步,

缺點:併發大於200個文件(10-100k)同步就會延遲,

 

[root@NFS-Server data]# mkdir /home/zytest01/tools-p

[root@NFS-Server data]# cd  /home/zytest01/tools -p       

[root@NFS-Servertools]#wget   http://github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz

[root@NFS-Server tools]# ll

total 352

-rw-r--r-- 1 root root 358772 Mar 14  2010 inotify-tools-3.14.tar.gz

[root@NFS-Server tools]# tar zxfinotify-tools-3.14.tar.gz

[root@NFS-Server tools]# ls

inotify-tools-3.14 inotify-tools-3.14.tar.gz

[root@NFS-Server tools]# cd inotify-tools-3.14

[root@NFS-Server inotify-tools-3.14]# echo $?            

0

[root@NFS-Server inotify-tools-3.14]# cd ../

[root@NFS-Server tools]# ln -s/usr/local/inotify-tools-3.14 /usr/local/inotify 目的是方便使用

[root@NFS-Server tools]# ls -l /usr/local/|grepinotify

lrwxrwxrwx  1root root   29 Nov  5 15:16 inotify ->/usr/local/inotify-tools-3.14

drwxr-xr-x  6root root 4096 Nov  5 15:14inotify-tools-3.14

 

[root@NFS-Server tools]# ls -l /usr/local/inotify-tools-3.14/

total 16

drwxr-xr-x 2 root root 4096 Nov  5 15:14 bin

drwxr-xr-x 3 root root 4096 Nov  5 15:14 include

drwxr-xr-x 2 root root 4096 Nov  5 15:14 lib

drwxr-xr-x 4 root root 4096 Nov  5 15:14 share

 

#!/bin/bash

/usr/bin/inotifywait -mrq  --format '%w%f' -e create,close_write,delete/backup \

|while read file

do

  cd /backup&&

  rsync -az./ --delete [email protected]::backup \

 --password-file=/etc/rsync.password

done

 

#!/bin/bash

/usr/bin inotifywait -mrq  --format '%w%f' -e create,close_write,dele

te /backup \

| while read file

  do

    rsync -az"$file" --delete [email protected]::backup--password-file=/etc/rsync.password

  done  腳本2

以上兩個腳本只同步變化的文件


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章