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 $?
[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
/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、
以上兩個腳本隻同步變化的檔案
本文轉自 wjw555 51CTO部落格,原文連結:http://blog.51cto.com/wujianwei/1962472