云计算和大数据 2019-11-05
公司现在有一个需求,需要将服务器CentOS的文件定时增量到Windows服务器,Windows服务器连接了存储服务器磁盘阵列,空间比较大。基于这样的需求,我们采用inotify+rsync增量备份的解决方案。
IP地址 | 系统 |
---|---|
192.168.1.100 | CentOS7.x |
192.168.1.101 | Windows Server 2012 r2 |
注意:这里的服务器名和密码用于后面配置项目中,默认用户名:SvcCWRSYNC,密码设置为admin123
use chroot = false strict modes = false hosts allow = * log file = rsyncd.log uid = 0 # 需要配置此项,不然连接报错 gid = 0 # 需要配置此项,不然连接报错 # Module definitions # Remember cygwin naming conventions : c:\work becomes /cygwin/c/work # #[test] #path = /cygdrive/c/work #read only = false #transfer logging = yes [rsyncdata] path = /cygdrive/e/cdbid-pro1.0-backup/57 read only = false # 只读属性为false list = no hosts allow = * auth users = SvcCWRSYNC # 对应配置用户名 secrets file = /cygdrive/e/cdbid-pro1.0-backup/rsync.passwd
SvcCWRSYNC:admin123
yum install rsync -y
admin123
chmod 600 /etc/rsync.passwd
inotify-tools工具监测文件增加、删除和修改,同时同步到备份服务器windows
yum install inotify-tools -y
#!/bin/bash host=192.168.1.101 src=/home des=rsyncdata user=SvcCWRSYNC inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f%e' -e modify,delete,create,attrib $src | while read files do /usr/bin/rsync -vzrtopg --delete --progress --password-file=/etc/rsync.passwd $src $user@$host::$des echo "${files} was rsynced" >>/tmp/rsync.log 2>&1 done
# 测试命令 /usr/bin/rsync -vzrtopg --delete --progress --password-file=/etc/rsync.passwd /root/test [email protected]::rsyncdata
inotify_start.sh &