如何制作远程目录的本地tar文件

all*_*ije 9 linux ssh scp tar

链接描述了如何复制 tarred 文件以最大程度地减少通过网络发送的数据量。我正在尝试做一些稍微不同的事情。

我在不同的子目录级别上有许多远程文件:

remote:/directory/subdir1/file1.ext
remote:/directory/subdir1/subsubdir11/file11.ext
remote:/directory/subdir2/subsubdir21/file21.ext
Run Code Online (Sandbox Code Playgroud)

我有一个文件列出了所有这些:

remote:/directory/allfiles.txt
Run Code Online (Sandbox Code Playgroud)

为了最有效地复制它们,我可以在远程站点上做

tar zcvf allfiles.tgz `cat /directory/allfiles.txt`
Run Code Online (Sandbox Code Playgroud)

但没有足够的空间来做到这一点。

我的本地磁盘上确实有足够的存储空间。有没有办法tar从远程服务器(使用scpssh传输)传入流?

就像/localdir$ tar zc - | ssh remote `cat /directory/allfiles.txt` 我猜的那样 - 但这只会列出本地主机上的远程文件。

小智 7

你几乎是对的,只需在远程主机上而不是本地运行 tar。该命令应如下所示:

ssh remote_host tar cvfz - -T /directory/allfiles.txt > remote_files.tar.gz
Run Code Online (Sandbox Code Playgroud)