您的位置:首页 > 其它

rsync + inotify 实时备份

2016-04-01 14:27 274 查看
rsync配置步骤
服务器端
1. 安装rsync
yum install rsync
2. 修改配置文件
vim /etc/rsyncd.conf #默认不存在需要自己创建
##############################
uid=rsync
gid=rsync
use chroot =no
max connections=200
timeout=600
pid file=/var/run/rsyncd.pid
lock file =/var/run/rsyncd.lock
log file =/var/log/rysncd.log
[zq]
path=/zq
ignore errors
read only=no
list =no
hosts allow=192.168.1.0/24
auth user=zq
secrets file=/etc/web.passwd
3. 创建登陆用户和密码
echo zq:123456 >/etc/web.passwd
客户端
1. 创建密码文件
echo 123456 >/etc/web.passwd
2.安装inotify-tools
wget http://120.52.73.47/tenet.dl.sourceforge.net/project/inotify-tools/inotify-tools/3.13/inotify-tools-3.13.tar.gz tar xf inotify-tools-3.13.tar.gz
cd inotify-tools-3.13
./configure --prefix=/usr/local/inotify-tools/
make && make install
3. 创建监控监控和复制脚本
####inotify脚本####
#!/bin/sh
src=/backup
des=zq
rsync_passwd=/etc/web.passwd
ip=192.168.1.127
user=zq
cd ${src}
/usr/local/inotify-tools/bin/inotifywait -mrq --format '%w%f' -e modify,create,delete,attrib,close_write,move ./ |while read line
do
rsync -avzR --timeout 100 --password-file=${rsync_passwd} $line ${user}@${ip}::${des} &>/dev/null
done
4. 设置inotify脚本执行权限:
chmod a+x /rsync.sh
5. 把脚本加入到开机自动启动文件
echo "/root/inotify.sh &">> /etc/rc.local

完成
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  rsync inotify