Linux下的文件更新触发同步

linux下的文件同步更新方法很多,这里主要是用的rsync和inotifity这两个工具,前者是同步文件到本地或者远程服务器用,后者是监控文件或文件夹的更新,利用这个监控来触发rsync。

一、环境工具:
CentOS 6.3
rsync-3.1.0
inotify-tools-3.14

二、安装
--inotify
wget http://cloud.github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz
tar -zxvf inotify-tools-3.14.tar.gz
cd inotify-tools-3.14
./configure --prefix=/usr/local/inotify
make && make install

--rsync
下载:http://rsync.samba.org/
tar -zxvf rsync-3.1.0.tar.gz
cd rsync-3.1.0
./configure --prefix=/usr/local/rsync
make && make install
三、使用
[root@test kenyon]# more inotify.sh
#!/bin/sh
srcdir="/root/test"
ip="192.168.10.71"
dstdir="/root/tmp"
/usr/local/bin/inotifywait -mrq --timefmt '%d/%m/%y-%H:%M' --format '%T%w%f' -e modify,delete,create,attrib ${srcdir} \
| while read file
do
        for i in $ip
                do
                /usr/bin/rsync -avzc --delete --progress ${srcdir} root@${ip}:${dstdir}
                done
done
四、启动
nohup sh inotify.sh >> inotify.log 2>&1 &
五、参考
http://blog.sina.com.cn/s/blog_7b6fc4c901015ahz.html

转载于:https://my.oschina.net/Kenyon/blog/177265

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值