无法通过 sftp 进行 rsync 工作

Pat*_*rik 6 ubuntu network-attached-storage rsync sftp synology

我正在尝试使用 rsync 和 sftp 设置从 Ubuntu 服务器到 Synology NAS (DS413j) 的备份系统。

我为此创建了一个用户,我们可以将其称为 ubuntu-backup。我在 ubuntu-backup 主目录中有一个名为 www 的目录,用于保存备份。我在 DSM 中启用了网络备份用户 ubuntu-backup 对其主目录具有完全访问权限

这是我在 Synology NAS 上的 rsync 配置文件:

#motd file = /etc/rsyncd.motd
#log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
use chroot = no
[NetBackup]
path = /var/services/NetBackup
comment = Network Backup Share
uid = root
gid = root
read only = no
list = yes
charset = utf-8
auth users = root
secrets file = /etc/rsyncd.secrets

[ubuntu-backup]
path = /volume1/homes/ubuntu-backup/www
comment = Ubuntu Backup
uid = ubuntu-backup
gid = users
read only = false
auth users = ubuntu-backup
secrets file = /etc/rsyncd.secrets
Run Code Online (Sandbox Code Playgroud)

/volume1/homes/ubuntu-backup/www 的权限是 ubuntu-backup:users 777

这是我正在运行的命令。

rsync -aHvhiPb  /var/www/ ubuntu-backup@backup.example.com:./
Run Code Online (Sandbox Code Playgroud)

结果:

sending incremental file list
ERROR: module is read only
rsync error: syntax or usage error (code 1) at main.c(1034) [Receiver=3.0.9]
rsync: connection unexpectedly closed (9 bytes received so far) [sender]
rsync error: error in rsync protocol data stream (code 12) at io.c(605) [sender=3.0.9]
Run Code Online (Sandbox Code Playgroud)

如果我运行这个:

rsync -aHvhiPb  /var/www/ ubuntu-backup@backup.example.com
Run Code Online (Sandbox Code Playgroud)

它看起来像它的发送文件。没有错误。但是我在NAS上找不到任何东西。

Jen*_*y D 9

rsync 不执行 SFTP。从手册页:

   There  are  two  different  ways for rsync to contact a remote system:
   using a remote-shell program as the transport (such as ssh or rsh)  or
   contacting  an rsync daemon directly via TCP. 
Run Code Online (Sandbox Code Playgroud)

SFTP 没有给你一个 shell,因此它不适用于 rsync。您将需要一个 SSH 连接。

一旦您允许 SSH 连接,您可能需要专门告诉 rsync 使用 SSH。有几种方法可以做到这一点:

rsync -aHvhiPb --rsh=ssh  /var/www/ ubuntu-backup@backup.example.com:./
Run Code Online (Sandbox Code Playgroud)

或者

rsync -aHvhiPb  "ssh -l ubuntu-backup"  /var/www/ backup.example.com:./
Run Code Online (Sandbox Code Playgroud)

rsync 的手册页中有更多示例。

在第二个示例中,它将文件同步到位于 direct 中名为 ubuntu-backup@backup.example.com 的目录中。为了指定远程服务器,您应该在规范中的某处使用冒号。