rsync使用系统账号在服务器之间同步文件时,默认一般是22端口,一般建议加上-e参数指定端口,特别是使用非22端口时,如:
rsync -avuz -e 'ssh -p 2222' user@remote-server:/path/to/remote/folder /path/to/local/folder

rsync以服务方式运行时,默认监听端口是873,而且一般是创建虚拟用户,而非使用系统用户。

参考:rsync服务介绍和配置 https://www.cnblogs.com/cocowool/p/6548476.html

 

其他参考——传输大文件报错:

https://serverfault.com/questions/570837/how-to-fix-corrupt-packet-error-for-with-rsync-for-relatively-large-files

问题:
尝试使用rsync命令更新服务器上的文件:
rsync -ravq -e "ssh -o ConnectTimeout=2 -o ServerAliveInterval=2 -ServerAliveCountMax=2" --delete ./local_dir user@$SERVER:/dest_dir
数据包损坏的错误不断被抛出,具体来说:
rsync: writefd_unbuffered failed to write 4092 bytes to socket [sender]: Broken pipe (32)
rsync: connection unexpectedly closed (11337 bytes received so far) [sender]
rsync error: unexplained error (code 255) at /home/lapo/package/rsync-3.0.9-1/src/rsync-3.0.9/io.c(605) [sender=3.0.9]

这可能与ssh超时有关,因为它似乎发生在大(r)文件中。此外,我使用WinSCP持续出现超时。这只发生在我身上,使用这个服务器的几个人没有同样的问题.

在Windows 7中使用Cygwin终端的rsync,对接Centos 6.3服务器。

评论:
我不确定是什么可能导致数据包损坏从而丢失连接,但你可能会发现rsync的–partial或–partial-dir选项在传输大文件时很有用,这样当你重新启动传输时它将继续从上次中断处接着传输而不必重新开始发送整个文件:
--partial-DIR=.rsync-partial

所以你可以像这样修改原始命令:

rsync -rav --progress --partial -e "ssh -o ConnectTimeout=2 -o ServerAliveInterval=2 -ServerAliveCountMax=2" --delete ./local_dir user@$SERVER:/dest_dir
或者
rsync -rav --progress --partial-dir=.rsync-partial -e "ssh -o ConnectTimeout=2 -o ServerAliveInterval=2 -ServerAliveCountMax=2" --delete ./local_dir user@$SERVER:/dest_dir

请注意,对于此示例,我删除了-q(--quiet)选项,并在第一个示例中添加了--progress选项,在第二个示例中添加了--partial-dir=.rsync-partial。

--partial和--partial-dir=.rsync-partial之间的区别在于,后者会创建一个目录,使得未完成的文件与完成传输的文件分开(如果这对你的接收(服务器端)端很重要的话)。

rsync manpage(http://rsync.samba.org/ftp/rsync/rsync.html)将进一步详细解释这一点,但我还要从手册页中指出一个重要的安全说明:
IMPORTANT: the --partial-dir should not be writable by other users or it is a security risk. E.g. AVOID “/tmp”.

posted on 2020-08-31 16:43  51core  阅读(951)  评论(0编辑  收藏  举报