AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / unix / 问题 / 740532
Accepted
Ole Tange
Ole Tange
Asked: 2023-03-22 06:10:14 +0800 CST2023-03-22 06:10:14 +0800 CST 2023-03-22 06:10:14 +0800 CST

rsync 文件`a`b

  • 772

是的,我知道你在想什么:“到底是谁命名他们的文件`a`b?”

但是让我们假设您确实有一个名为`a`b(可能是由疯狂的 Mac 用户制作的 - 显然不是您制作的)的文件,并且您想要rsync那个。显而易见的解决方案:

rsync server:'./`a`b' ./.;
rsync 'server:./`a`b' ./.;

给出:

bash: line 1: a: command not found
rsync: [sender] link_stat "/home/tange/b" failed: No such file or directory (2)
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1865) [Receiver=3.2.7]
rsync: [Receiver] write error: Broken pipe (32)

甚至:

$ rsync 'server:./\`a\`b' ./.;
bash: line 3: a\: command not found
rsync: [sender] link_stat "/home/tange/\b" failed: No such file or directory (2)
:

rsync我应该运行的命令是什么?

$ rsync --version
rsync  version 3.2.7  protocol version 31
rsync
  • 3 3 个回答
  • 1557 Views

3 个回答

  • Voted
  1. Best Answer
    Chris Down
    2023-03-22T07:29:53+08:002023-03-22T07:29:53+08:00

    手动平分后,这是 rsync 中的一个错误,由提交 5c93dedf4538(“向 SHELL_CHARS 添加反引号”)修复,它将出现在即将推出的 rsync 3.2.8(尚未发布)中。它被commit 6b8db0f6440b ("Add an arg-protection idiom using backslash-escapes")打破,它在 3.2.4 中。

    作为缓解措施,存在使用旧 arg 解析行为 ( ) 的选项--old-args:

    rsync --old-args 'server:./\`a\`b' .
    
    • 32
  2. Ole Tange
    2023-03-22T06:59:21+08:002023-03-22T06:59:21+08:00

    这是一个版本问题。它似乎不依赖于服务器版本,而是依赖于客户端。

    v3.2.3 和 v3.2.7 之间出现了一些问题。

    好的:

    $ rsync-v3.2.3 --rsync-path=rsync-v3.2.7  'server:./\`a\`b' ./.;
    $ rsync-v3.2.3 --rsync-path=rsync-v3.2.3  'server:./\`a\`b' ./.;
    $ rsync-v3.2.3 --rsync-path=rsync-v3.2.3  server:./"'"'`a`'"'"b ./.;
    

    失败:

    $ rsync-v3.2.7 --rsync-path=rsync-v3.2.7  'server:./\`a\`b' ./.;
    bash: line 3: a\: command not found
    rsync: [sender] link_stat "/home/tange/\b" failed: No such file or directory (2)
    $ rsync-v3.2.7 --rsync-path=rsync-v3.2.3  'server:./\`a\`b' ./.;
    bash: line 3: a\: command not found
    rsync: [sender] link_stat "/home/tange/\b" failed: No such file or directory (2)
    $ rsync-v3.2.3 --rsync-path=rsync-v3.2.3  'server:./`a`b' ./.;
    bash: line 1: a: command not found
    rsync: [sender] link_stat "/home/tange/b" failed: No such file or directory (2)
    $ rsync-v3.2.3 --rsync-path=rsync-v3.2.7  'server:./`a`b' ./.;
    bash: line 1: a: command not found
    rsync: [sender] link_stat "/home/tange/b" failed: No such file or directory (2)
    

    但严重的是:这似乎是一场等待发生的灾难,你需要引用`两次。

    感谢@dhag 指出问题。

    不幸的是,它没有回答如何使用 v3.2.7 版本进行传输。

    • 12
  3. Stéphane Chazelas
    2023-03-24T22:56:25+08:002023-03-24T22:56:25+08:00

    如果您不必支持rsync3.0.0 之前的版本,请使用--secluded-argsaka -s,以前称为--protect-args,然后您不必担心远程用户的登录 shell(可能是任何东西)如何解释文件名,因此在通过 rsh/ssh 执行 rsync 时,正确地进行引用/转义几乎是不可能的)。来自手册(此处为 3.2.7):

      --secluded-args, -s
             This  option  sends all filenames and most options to the remote
             rsync via the protocol (not the remote shell command line) which
             avoids  letting the remote shell modify them.  Wildcards are ex‐
             panded on the remote host by rsync instead of a shell.
    
             This is similar to the default backslash-escaping of  args  that
             was  added  in 3.2.4 (see --old-args) in that it prevents things
             like space splitting  and  unwanted  special-character  side-ef‐
             fects.  However, it has the drawbacks of being incompatible with
             older rsync versions (prior to 3.0.0) and of  being  refused  by
             restricted shells that want to be able to inspect all the option
             values for safety.
    
             This option is useful for those times that you  need  the  argu‐
             ment's character set to be converted for the remote host, if the
             remote shell is incompatible with the default backslash-escpaing
             method, or there is some other reason that you want the majority
             of the options and arguments to bypass the command-line  of  the
             remote shell.
    
             If you combine this option with --iconv, the args related to the
             remote side will be translated from  the  local  to  the  remote
             character-set.   The  translation  happens before wild-cards are
             expanded.  See also the --files-from option.
    
             You may also control this setting via the RSYNC_PROTECT_ARGS en‐
             vironment  variable.   If  it has a non-zero value, this setting
             will be enabled by default, otherwise it will be disabled by de‐
             fault.  Either state is overridden by a manually specified posi‐
             tive or negative version of this option (note  that  --no-s  and
             --no-secluded-args are the negative versions).  This environment
             variable is also superseded by a non-zero RSYNC_OLD_ARGS export.
    
             This option conflicts with the --old-args option.
    
             This option used to be called --protect-args (before 3.2.6)  and
             that older name can still be used (though specifying it as -s is
             always the easiest and most compatible choice).
    
    • 3

相关问题

  • rsync - 使用 shell 脚本将每个 JPG/jpg 文件从一个硬盘驱动器移动到一个目录

  • tar 目录只发送修改过的文件块

  • 如何复制具有相对重复符号链接的目录树?

  • rsync 排除问题

  • rsync 端口 22 和 873 使用

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    模块 i915 可能缺少固件 /lib/firmware/i915/*

    • 3 个回答
  • Marko Smith

    无法获取 jessie backports 存储库

    • 4 个回答
  • Marko Smith

    如何将 GPG 私钥和公钥导出到文件

    • 4 个回答
  • Marko Smith

    我们如何运行存储在变量中的命令?

    • 5 个回答
  • Marko Smith

    如何配置 systemd-resolved 和 systemd-networkd 以使用本地 DNS 服务器来解析本地域和远程 DNS 服务器来解析远程域?

    • 3 个回答
  • Marko Smith

    dist-upgrade 后 Kali Linux 中的 apt-get update 错误 [重复]

    • 2 个回答
  • Marko Smith

    如何从 systemctl 服务日志中查看最新的 x 行

    • 5 个回答
  • Marko Smith

    Nano - 跳转到文件末尾

    • 8 个回答
  • Marko Smith

    grub 错误:你需要先加载内核

    • 4 个回答
  • Marko Smith

    如何下载软件包而不是使用 apt-get 命令安装它?

    • 7 个回答
  • Martin Hope
    user12345 无法获取 jessie backports 存储库 2019-03-27 04:39:28 +0800 CST
  • Martin Hope
    Carl 为什么大多数 systemd 示例都包含 WantedBy=multi-user.target? 2019-03-15 11:49:25 +0800 CST
  • Martin Hope
    rocky 如何将 GPG 私钥和公钥导出到文件 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Evan Carroll systemctl 状态显示:“状态:降级” 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim 我们如何运行存储在变量中的命令? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S 为什么 /dev/null 是一个文件?为什么它的功能不作为一个简单的程序来实现? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 如何从 systemctl 服务日志中查看最新的 x 行 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - 跳转到文件末尾 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla 为什么真假这么大? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis 在一个巨大的(70GB)、一行、文本文件中替换字符串 2017-12-30 06:58:33 +0800 CST

热门标签

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve