Inotify + rsync

博客已经搬家,请访问如下地址:http://www.czhphp.com

Inotify + rsync:

需求:
rsync3.x
inotify-tools

条件:
需要实时同步的两台主机:

10.3.0.173  server

10.3.0.215  分发服务器

 

同步的网站目录: /home/rsync/

 

 

1 install:

 

# cd /usr/local/src
# wget http://www.samba.org/ftp/rsync/s ... nc-3.0.6pre1.tar.gz
# wget http://jaist.dl.sourceforge.net/ ... y-tools-3.13.tar.gz

 

Server安装:

# tar zxvf rsync-3.0.6pre1.tar.gz
# cd rsync-3.0.6pre1
# ./configure --prefix=/usr && make && make install

 

分发安装:
# tar zxvf inotify-tools-3.13.tar.gz
# cd inotify-tools-3.13
# ./configure && make && make install

# ln -sv /usr/local/lib/libinotify* /usr/lib/

Server配置文件:

Vim /etc/rsyncd.conf

 

 

Chmod 600 /etc/rsyncd.conf 

 

分发脚本:

Vim /etc/rsync.pass

 

 

 

Chmod 600 /etc/rsync.pass

 

 

Vim /etc/inotify.sh

 

  1 #!/bin/sh                                                                                                                              

  2 src=/home/wwwroot/rsync/

  3 des=log

  4 ip=10.3.0.173

  5

  6 /usr/local/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format  '%T %w%f' \

  7 -e modify,delete,create,attrib \

  8 ${src} \

  9 | while read files

 10     do

 11    rsync -vzrtopg --delete --progress --password-file=/etc/rsync.pass ${src} root@${ip}::${des}

 12         echo "${src} was rsynced"

 13         echo "-----------------------------------------------------"

 14     done

~              

 

chmod a+x /etc/inotify.sh

 

/etc/inotify.sh &

 

echo “/etc/inotify.sh &” >> /etc/rc.local

博客已经搬家,请访问如下地址:http://www.czhphp.com

posted @ 2012-05-25 17:15  曹振华  阅读(309)  评论(0编辑  收藏  举报