inotify:监控文件目录变化
rsync:实现文件增量同步备份
主服务器,安装rsync客户端及inotify
[root@node1 ~]# cat rsync.sh
#!/bin/bash
host=192.168.128.131 #备份服务器IP
src=/tmp/
des=web #备份服务器 rsyncd.config模块一致
user=trsync #备份服务器 rsyncd.config用户一致
/usr/local/inotify/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f%e' -e modify,delete,create,attrib $src | while read files #实时检测/tmp/主服务器目录文件的变换
do
rsync -avzL --password-file=/root/rsync.passwd $src $user@$host::$des #将/tmp/主服务器目录文件增量备份到备份服务器
echo "${files} was rsynced" >>/root/rsync.log 2>&1
done
创建password-file
[root@node1 ~]# cat /root/rsync.passwd
rsync-pwd #此密码跟备份服务器中的 rsyncd.config密码一致
备份服务器:安装rsync服务端,并配置rsyncd.config
[root@node2 tmp]# vi /etc/rsyncd.conf
uid = root
gid = root
use chroot = no
max connections = 10
strict modes = yes
pid file = /var/run/rsyncd.pid
hosts allow=192.168.128.132 #主服务器IP
hosts only=yes
[web]
path = /tmp/
comment = web file
ignore errors
read only = no
write only = no
list = false
auth users = trsync
secrets file = /etc/rsync.passwd 配置密码
启动rsyncd
rsync --daemon --config=/etc/rsyncd.conf
[root@node2 tmp]# cat /etc/rsync.passwd 创建
trsync:rsync-pwd
阅读(1467) | 评论(0) | 转发(0) |