Rsync常见问题

简介: rsync 在父目录不存在的时候直接同步子目录会报错,默认不会自动递归创建目录。

Rsync常见问题

客户端待同步目录如下:

.
`-- today
    `-- subdir
        `-- test-dirs

2 directories, 1 file

一、同步文件报错 @ERROR Unknown module test

报错日志

@ERROR Unknown module test
rsync error:error starting client-server protocol(code 5) at main.c(1503)[sender=3.0.6]

解决办法

在服务端配置文件rsyncd.conf中添加如下配置:

[test]
path = /mnt/source/test
comment = web
ignore errors
read only = no
list = no
transfer logging = no

二、服务端目录配置只读,无法写入文件

rsync -av --stats -u /home/test/ rsync://root@11.11.11.102/test --password-file=/etc/rsyncd.passwd

报错日志

sending incremental file list
rsync: read error: Connection reset by peer (104)
rsync error: error in socket IO (code 10) at io.c(785) [sender=3.1.2]

解决过程

1. 在rsyncd.conf中配置rsync daemon日志文件:

log file = /opt/var/log/rsync.log

2. 重启服务, tail /opt/var/log/rsync.log

2019/05/31 03:05:49 [12180] rsync to test/ from master (11.11.11.101)
2019/05/31 03:05:49 [12180] ERROR: module is read only
2019/05/31 03:05:49 [12180] rsync error: syntax or usage error (code 1) at main.c(994) [Receiver=3.1.2]

三、服务端today不存在,同步/today/subdir下文件报错

将客户端/home/test/today/subdir下文件同步到 root@11.11.11.102/test/today/subdir

rsync -av --stats -u /home/test/today/subdir/ rsync://root@11.11.11.102/test/today/subdir --password-file=/etc/rsyncd.passwd

报错日志

sending incremental file list
rsync: mkdir "today/subdir" (in test) failed: No such file or directory (2)
rsync error: error in file IO (code 11) at main.c(657) [Receiver=3.1.2]

解决办法

cd /home/test && rsync -avR --stats -u today/subdir  rsync://root@11.11.11.102/test --password-file=/etc/rsyncd.passwd
  • -R使用相对路径
  • 自动创建today目录,不存在的话

image

-R:不管加不加”/”,都会同相对路径,没有则自动创建,所以在写命令时一定要注意。

相关实践学习
日志服务之使用Nginx模式采集日志
本文介绍如何通过日志服务控制台创建Nginx模式的Logtail配置快速采集Nginx日志并进行多维度分析。
相关文章
|
网络安全 数据安全/隐私保护 网络协议
|
网络协议 网络安全 数据安全/隐私保护
|
Web App开发 监控 Shell
|
算法 数据安全/隐私保护 Shell
|
网络协议 Shell 应用服务中间件
|
知识图谱 数据安全/隐私保护 Unix
|
网络协议 开发工具 数据安全/隐私保护