背景
公司现在有一个需求,需要将服务器CentOS的文件定时增量到Windows服务器,Windows服务器连接了存储服务器磁盘阵列,空间比较大。基于这样的需求,我们采用inotify+rsync增量备份的解决方案。
服务器配置
| IP地址 | 系统 |
|---|---|
| 192.168.1.100 | CentOS7.x |
| 192.168.1.101 | Windows Server 2012 r2 |
Windows
1. 安装cwRsyncServer
- 下载地址:https://www.backupassist.com/rsync/

- 双击安装
- 设置服务名和密码
注意:这里的服务器名和密码用于后面配置项目中,默认用户名: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
- 新建rsync.passwd文件,填写如下
SvcCWRSYNC:admin123
- 添加目录cdbid-pro1.0-backup目录访问权限,如果没有SvcCWRSYNC用户,点击高级添加

- 启动服务

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

7. 后台运行启动脚本
inotify_start.sh &
本文介绍了一种利用inotify和rsync实现从CentOS服务器到Windows服务器的文件增量备份方案。通过安装cwRsyncServer并在Windows端配置rsync服务,配合Linux端的rsync和inotify-tools工具,实现文件变动时自动同步更新。


被折叠的 条评论
为什么被折叠?



