【问题标题】:Scp multiple files created in last one day from server to local fails过去一天从服务器到本地创建的 scp 多个文件失败
【发布时间】:2020-02-12 05:43:58
【问题描述】:

我想获取过去 1 天生成的多个文件,从服务器到本地。我正在使用以下命令,上面写着“没有这样的文件或目录”。

find username@server.xyz.com:/path-from-which-files-need-to-be-copied/ -type f -ctime -1 | xargs -ILIST scp LIST /Users/abcUser/Documents/test/

错误 查找:username@server.xyz.com:/path-from-which-files-need-to-be-copied/:没有这样的文件或目录

PS:我可以从该位置访问此位置并 scp 以获取具有文件名的单个文件。

【问题讨论】:

  • find 实用程序查看本地文件系统。它无法通过 ssh 连接(如果这是您想要的)并在远程服务器上列出文件。您可能希望将 rsync 视为更好的解决方案。
  • 谢谢。会调查的。
  • 同时,由于这个问题是基于一个错误的前提,并且与编程无关,您可能希望将其删除以使 SO 问题队列更清晰。
  • 其实用 find 是可行的。我的要求特别要求我提供最近 1 天的文件。而且我实际上无法在处理后将所有文件存储在本地。所以 rync 不会工作。因为 rsync 仅适用于增量。

标签: bash unix scp xargs


【解决方案1】:

find 只能找到本地文件。所以在远程服务器上运行find,类似的东西:

ssh username@server.xyz.com find /path-from-which-files-need-to-be-copied/ -type f -ctime -1 |
xargs -ILIST scp username@server.xyz.com:LIST /Users/abcUser/Documents/test/

注意xargs 默认解析\ 并以自己的方式引用。传递find 的结果的最佳方法是使用零终止流:

ssh username@server.xyz.com find /path-from-which-files-need-to-be-copied/ -type f -ctime -1 -print0 |
xargs -0 -ILIST scp username@server.xyz.com:LIST /Users/abcUser/Documents/test/   

但是xargs 将为每个文件调用单独的scp 会话,这将非常慢。因此,通过为所有文件运行单个 scp 来优化它,我认为您可以这样做:

ssh username@server.xyz.com find /path-from-which-files-need-to-be-copied/ -type f -ctime -1 -printf 'username@server.xyz.com:%p\\0' |
xargs -0 sh -c 'scp "$@" "$0"' /Users/abcUser/Documents/test/

【讨论】:

    猜你喜欢
    • 2015-03-01
    • 2014-11-24
    • 2021-08-13
    • 1970-01-01
    • 2019-07-21
    • 2011-04-15
    • 1970-01-01
    • 2019-03-28
    • 2014-11-18
    相关资源
    最近更新 更多