rsync备份同步(包含群晖NAS与开源同步)

1 环境介绍

备份服务器IP:10.186.102.115rsync客户端
被备份服务器IP:10.186.103.99rsync服务器端

备注:备份服务器及被备份服务器都需要关闭selinux.

2 rsync安装

(客户端及服务器端均安装)

yum install rsync -y

3 rsync服务器配置

编辑/etc/rsyncd.conf,增加以下内容:

uid = root
gid = root
use chroot = no
max connections = 4
exclude = lost+found/
transfer logging = yes
timeout = 900
ignore nonreadable = yes
dont compress = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb .bz2

[test]   #可以写多个,想要备份的不同业务
   path = /harbor-data/demo1115
   comment = test
   ignore errors
   read only = no
   write only = no
   list= yes
   auth user= root   #一个存在于服务器端的用户,如有多个逗号隔开,并且要求具有对需同步目录下的文件的读和执行权限。
   secrets file = /etc/rsyncd.passwd  #存放用户名和密码的地方
   hosts allow = *  #*代表允许所有的地址,安全起见,最好是客户端的地址。

增加文件/etc/rsyncd.passwd,编辑账号及密码:

root:123456

修改权限:

chmod 600 /etc/rsyncd.passwd

启动服务

systemctl enable rsyncd --now 

4 客户端配置

增加文件/etc/rsyncd.passwd,编辑账号及密码, 里面必须有和服务器一样的账号及密码

root:123456

备注:客户端不需要启动服务。

修改权限:

chmod 600 /etc/rsyncd.passwd 

5 执行同步

客户端端操作

rsync -vzrtopg --progress root@10.186.103.99::test  /root/demo1115 --password-file=/etc/rsyncd.passwd

test为服务器端配置文件的[test], /root/demo1115为本地备份目录。

log显示:

# rsync -vzrtopg --progress root@10.186.103.99::test  /root/demo1115 --password-file=/etc/rsyncd.passwd
receiving incremental file list

sent 24 bytes  received 82 bytes  212.00 bytes/sec
total size is 7  speedup is 0.07

加入计划任务

crontab -e
*/2 * * * * rsync -vzrtopg --progress root@10.186.103.99::test /root/demo1115 --password-file=/etc/rsyncd.passwd

6 故障处理

6.1 客户端同步报错一

receiving incremental file list

skipping non-regular file “vendor/bin/doctrine”

skipping non-regular file “vendor/bin/doctrine.php”

sent 1990 bytes received 489209 bytes 327466.00 bytes/sec total size is 182515746 speedup is 371.57

原因并解决:

原因:source源文件有软链接。
解决方法:修改为 rsync -va,其中 -a == -rlptgoD (no -H,-A,-X) 或者 rsync -rvltOD 也可以。

6.2 客户端同步报错二

rsync: send_files failed to open "/busidecisionrpt-ms/nohup.out" (in dc-report-server-1): Permission denied (13)
rsync: send_files failed to open "/dataexchange-c-ms/application-prd.yml" (in dc-report-server-1): Permission denied (13)
rsync: send_files failed to open "/dataexchange-c-ms/application-prd.yml.20220321.bak" (in dc-report-server-1): Permission denied (13)
rsync: send_files failed to open "/dataexchange-c-ms/application-prd.yml.bak.20210902" (in dc-report-server-1): Permission denied (13)
rsync: send_files failed to open "/dataexchange-c-ms/application-prod.yml.bak" (in dc-report-server-1): Permission denied (13)
rsync: send_files failed to open "/dcp-app-usrportrait-ms/application-prd.yaml" (in dc-report-server-1): Permission denied (13)
rsync: send_files failed to open "/dcp-app-usrportrait-ms/application.yml" (in dc-report-server-1): Permission denied (13)
rsync: send_files failed to open "/dcp-app-usrportrait-ms/logback.xml.bak" (in dc-report-server-1): Permission denied (13)
rsync: send_files failed to open "/dcp-app-wecom-customer/application-dev.yml" (in dc-report-server-1): Permission denied (13)
rsync: send_files failed to open "/dcp-app-wecom-customer/application-prd.yml" (in dc-report-server-1): Permission denied (13)

原因并解决:

以下修改/etc/rsyncd.conf 的 uid = root gid = root

6.3 客户端同步报错三

receiving incremental file list
rsync: readlink_stat("/application.properties" (in dcp-bigdata-schedule-1-xxl-job)) failed: Permission denied (13)
rsync: readlink_stat("/logback.xml" (in dcp-bigdata-schedule-1-xxl-job)) failed: Permission denied (13)

原因并解决:

selinux开启着,关闭selinux恢复正常。

7 群晖NAS rsync配置

7.1 群晖开启ssh

第一步:
在这里插入图片描述
第二步:
在这里插入图片描述

第三步:
勾选
在这里插入图片描述

7.2 配置rsync并启动服务器端

ssh登录,用账号登录,用普通账号登录,需要sudo -i,这时候有可能需要输入管理员admin密码

Synology strongly advises you not to run commands as the root user, who has
the highest privileges on the system. Doing so may cause major damages
to the system. Please note that if you choose to proceed, all consequences are
at your own risk.

Could not chdir to home directory /var/services/homes/wangjinxiong: No such file or directory
wangjinxiong@k8s-san:/$ sudo -i
Password: 
root@k8s-san:~# 

设置rsync密码并修改配置文件

echo "rsync:123456" >> /etc/rsyncd.secrets
mv /etc/rsyncd.conf /etc/rsyncd.conf.bak
vi /etc/rsyncd.conf
#修改内容如下:
uid = root
gid = root
use chroot = no
max connections = 4
exclude = lost+found/
transfer logging = yes
timeout = 900
ignore nonreadable = yes
dont compress = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb .bz2

[test0611]   #可以写多个,想要备份的不同业务
   path = /volume1/test0611  #群晖目录,默认是volume1下面的目录
   comment = test0611
    ignore errors
    read only = no
    write only = no
    list= yes
    auth user= root  
    secrets file = /etc/rsyncd.secrets 
    hosts allow = *

启动服务:

systemctl start rsyncd

7.3 客户端同步数据

客户端配置账号及密码:

echo "rsync:123456" >> /etc/rsyncd.secrets

客户端同步数据:

rsync -va --progress rsync@192.168.3.231::test0611  /mnt --password-file=/etc/rsyncd.passwd
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值