rsync命令给出错误没有这样的文件或目录(2)

时间:2017-07-15 20:08:19

标签: unix rsync

我正在尝试使用远程桌面传输文件,这将在指定的远程桌面中创建目录树。我正在使用下面的命令,但当远程服务器中不存在目录时它无法正常工作。

rsync -avzhe ssh --progress /root/BP/temp/temp.txt root@host2:/root/BP/temp2

/root/BP/temp/temp.txt在本地可用但/root/BP/temp2此路径在远程服务器中不存在。

我收到以下错误:

rsync: change_dir#3 "/root/BP" failed: No such file or directory (2)
rsync error: errors selecting input/output files, dirs (code 3) at main.c(625) [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]

1 个答案:

答案 0 :(得分:0)

如果需要将文件移动到远程服务器上不存在的路径,则必须:

  1. 在本地对路径和文件结构进行建模,并同步一个共同的"祖先"。
    • 这只需要一步
  2. 在本地创建缺少的目录并首先同步它们然后同步文件。
    • 这需要两个步骤
  3. 使用OP的具体例子:

    rsync -avzhe ssh --progress /root/BP/temp/temp.txt root@host2:/root/BP/temp2
    

    你会改为:

    # assuming that /root already exists on the remote server
    mkdir -p /root/BP/temp/or_wherever/BP/temp2
    mv /root/BP/temp/temp.txt /root/BP/temp/or_wherever/BP/temp2
    rsync -avzhe ssh --progress /root/BP/temp/or_wherever/BP root@host2:/root/
    

    但如果由于某种原因您无法移动相关文件,则必须使用第二个选项:

    # assuming that /root already exists on the remote server
    mkdir -p /root/BP/temp/or_wherever/BP/temp2
    # Notice there is no `/` after the       `or_wherever/BP` in the next command
    rsync -avzhe ssh --progress /root/BP/temp/or_wherever/BP root@host2:/root/
    rsync -avzhe ssh --progress /root/BP/temp/temp.txt root@host2:/root/BP/temp2/