inotify+rsync将服务器CentOS文件定时增量备份到Windows

背景

公司现在有一个需求,需要将服务器CentOS的文件定时增量到Windows服务器,Windows服务器连接了存储服务器磁盘阵列,空间比较大。基于这样的需求,我们采用inotify+rsync增量备份的解决方案。

服务器配置

IP地址系统
192.168.1.100CentOS7.x
192.168.1.101Windows Server 2012 r2

Windows

1. 安装cwRsyncServer

inotify+rsync将服务器CentOS文件定时增量备份到Windows

  • 双击安装
  • 设置服务名和密码
注意:这里的服务器名和密码用于后面配置项目中,默认用户名:SvcCWRSYNC,密码设置为admin123

inotify+rsync将服务器CentOS文件定时增量备份到Windows

  • 配置文件

inotify+rsync将服务器CentOS文件定时增量备份到Windows

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
  • 新建rsync.passwd文件,填写如下
SvcCWRSYNC:admin123
  • 添加目录cdbid-pro1.0-backup目录访问权限,如果没有SvcCWRSYNC用户,点击高级添加

inotify+rsync将服务器CentOS文件定时增量备份到Windows

  • 启动服务

inotify+rsync将服务器CentOS文件定时增量备份到Windows

Linux

1. 安装rsync

yum install rsync -y

2. 新建/etc/rsync.passwd,内容如下,注意客户端rsync只需要密码

admin123

3. 更改权限

chmod 600 /etc/rsync.passwd

4. 安装inotify

inotify-tools工具监测文件增加、删除和修改,同时同步到备份服务器windows
yum install inotify-tools -y

5. 启动脚本inotify_start.sh

#!/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

6. 测试

# 测试命令
/usr/bin/rsync -vzrtopg --delete --progress --password-file=/etc/rsync.passwd /root/test SvcCWRSYNC@192.168.1.101::rsyncdata

inotify+rsync将服务器CentOS文件定时增量备份到Windows

7. 后台运行启动脚本

inotify_start.sh &

转载请注明:溜爸 » inotify+rsync将服务器CentOS文件定时增量备份到Windows

相关推荐