<pre name="code" class="sql">1. 部署
v-lhb-db01:/usr/local# tar xvf inotify-tools.tar
inotify-tools/
或者 源码包安装:
# tar xzvf inotify-tools-3.14.tar.gz
# cd inotify-tools-3.13
# ./configure --prefix=/usr/local/inotify
# make
# make install
2.
/usr/local/inotify-tools/bin/inotifywait -mrq --timefmt %Y/%m/%d %H:%M --format %T %w%f%e -e close_write,create,move,delete,modify /var/www/zjzc-web-frontEnd/news/
v-lhb-db01:/usr/local# cat rsync_inotify.sh
#!/bin/bash
INOTIFY_RSYNC_LOG_DIR=/var/log/inotify_rsync
if [ -d "$INOTIFY_RSYNC_LOG_DIR" ]
then
:
else
mkdir -p $INOTIFY_RSYNC_LOG_DIR
fi
INOTIFY_RSYNC_LOG_FILE=$INOTIFY_RSYNC_LOG_DIR/inotify_rsync_contract.log
echo >$INOTIFY_RSYNC_LOG_FILE
INWT=/usr/local/inotify-tools/bin/inotifywait
RSYNC=/usr/local/rsync/bin/rsync
SRC_FS1=/var/www/zjzc-web-frontEnd/news/
DES_HOST1=192.168.32.119
DES_USER=root
DES_MODULE1=contract
$INWT -mrq --timefmt '%Y/%m/%d %H:%M' --format '%T %w%f%e' -e close_write,create,move,delete,modify $SRC_FS1 | while read FILES
do
$RSYNC -avz --password-file=/etc/rsyncd.secrets $SRC_FS1 ${DES_USER}@${DES_HOST1}::${DES_MODULE1}
echo "$FILES was rsynced" >>$INOTIFY_RSYNC_LOG_FILE 2>&1
done
v-lhb-db01:/usr/local# mkdir -p /var/log/inotify_rsync
v-lhb-db01:/usr/local# sh ./rsync_inotify.sh
sending incremental file list
./
4
sent 114 bytes received 30 bytes 288.00 bytes/sec
total size is 96 speedup is 0.67
sending incremental file list
sent 66 bytes received 8 bytes 49.33 bytes/sec
total size is 96 speedup is 1.30
sending incremental file list
sent 66 bytes received 8 bytes 13.45 bytes/sec
total size is 96 speedup is 1.30
sending incremental file list
4
sent 111 bytes received 33 bytes 288.00 bytes/sec
total size is 93 speedup is 0.65
sending incremental file list
sent 66 bytes received 8 bytes 148.00 bytes/sec
total size is 93 speedup is 1.26
sending incremental file list
sent 66 bytes received 8 bytes 148.00 bytes/sec
total size is 93 speedup is 1.26