两个远程主机之间的压缩和解压缩
tarring and untarring between two remote hosts
我有两个系统,我在这两个系统之间拆分处理,我试图找到在两个系统之间移动数据的最有效方法。我已经弄清楚如何 tar 和 gzip 到第一台服务器 ("serverA") 上的存档,然后使用 rsync 复制到远程主机 ("serverB")。但是,当我 untar/unzip 那里的数据时,它会保存包含来自原始服务器的完整路径名的存档。因此,如果在服务器 A 上,我的数据位于:
/serverA/directory/a/lot/of/subdirs/myData/*
并且,使用这个命令:
tar -zcvf /serverA/directory/a/lot/of/subdirs/myData-archive.tar.gz /serverA/directory/a/lot/of/subdirs/myData/
.../myData 中的所有内容都已成功tar红色并压缩到 myData-archive.tar.gz
但是,复制存档后,当我尝试在第二台主机上untar/unzip时(我在这里手动登录完成处理,第一步是untar/unzip)使用这个命令:
tar -zxvf /serverB/current/directory/myData-archive.tar.gz
它取消tar我当前目录 (serverB/current/directory/) 中的所有内容,但它看起来像这样:
/serverB/current/directory/serverA/directory/a/lot/of/subdirs/myData/Data*ext
我应该如何制定这两个 tar 命令,以便我的数据最终位于名为
的目录中
/serverB/current/directory/dataHERE/
?
我知道我需要 -C 标志来取消 tar 到不同的目录(在我的例子中, /serverB/current/directory/dataHERE ),但我仍然不知道如何以便在存档变为 untarred 时不包括整个路径。我看过类似的帖子,但我看到的 none 讨论了在不同主机之间移动时如何执行此操作。
更新:根据 this question 中的一个答案,我将命令更改为:
服务器 A 上的 tar/zip:
tar -zcvf /serverA/directory/a/lot/of/subdirs/myData-archive.tar.gz serverA/directory/a/lot/of/subdirs/myData/ -C /serverA/directory/a/lot/of/subdirs/ myData
并且,untar/unzip:
tar -zxvf /serverB/current/directory/myData-archive.tar.gz -C /serverB/current/directory/dataHERE
现在,它不仅 untar/unzip 数据到:
/serverB/current/directory/dataHERE/
就像我想要的那样,但它还在此处放置了另一个数据副本:
/serverB/current/directory/serverA/directory/a/lot/of/subdirs/myData/
我不想要。我需要如何修复我的命令,以便它只将数据放在首位?
在serverA
做
( cd /serverA/directory/a/lot/of/subdirs; tar -zcvf myData-archive.tar.gz myData; )
经过一番折腾,我想出了如何实现我想要的:
到服务器 A 上的 tar:
tar -zcvf /serverA/directory/a/lot/of/subdirs/myData-archive.tar.gz -C /serverA/directory/a/lot/of/subdirs/ myData
然后在 serverB 上取消 tar:
tar -zxvf /serverB/current/directory/myData-archive.tar.gz -C /serverB/current/directory/dataHERE
我有两个系统,我在这两个系统之间拆分处理,我试图找到在两个系统之间移动数据的最有效方法。我已经弄清楚如何 tar 和 gzip 到第一台服务器 ("serverA") 上的存档,然后使用 rsync 复制到远程主机 ("serverB")。但是,当我 untar/unzip 那里的数据时,它会保存包含来自原始服务器的完整路径名的存档。因此,如果在服务器 A 上,我的数据位于:
/serverA/directory/a/lot/of/subdirs/myData/*
并且,使用这个命令:
tar -zcvf /serverA/directory/a/lot/of/subdirs/myData-archive.tar.gz /serverA/directory/a/lot/of/subdirs/myData/
.../myData 中的所有内容都已成功tar红色并压缩到 myData-archive.tar.gz
但是,复制存档后,当我尝试在第二台主机上untar/unzip时(我在这里手动登录完成处理,第一步是untar/unzip)使用这个命令:
tar -zxvf /serverB/current/directory/myData-archive.tar.gz
它取消tar我当前目录 (serverB/current/directory/) 中的所有内容,但它看起来像这样:
/serverB/current/directory/serverA/directory/a/lot/of/subdirs/myData/Data*ext
我应该如何制定这两个 tar 命令,以便我的数据最终位于名为
的目录中/serverB/current/directory/dataHERE/
?
我知道我需要 -C 标志来取消 tar 到不同的目录(在我的例子中, /serverB/current/directory/dataHERE ),但我仍然不知道如何以便在存档变为 untarred 时不包括整个路径。我看过类似的帖子,但我看到的 none 讨论了在不同主机之间移动时如何执行此操作。
更新:根据 this question 中的一个答案,我将命令更改为:
-
服务器 A 上的
tar/zip:
tar -zcvf /serverA/directory/a/lot/of/subdirs/myData-archive.tar.gz serverA/directory/a/lot/of/subdirs/myData/ -C /serverA/directory/a/lot/of/subdirs/ myData
并且,untar/unzip:
tar -zxvf /serverB/current/directory/myData-archive.tar.gz -C /serverB/current/directory/dataHERE
现在,它不仅 untar/unzip 数据到:
/serverB/current/directory/dataHERE/
就像我想要的那样,但它还在此处放置了另一个数据副本:
/serverB/current/directory/serverA/directory/a/lot/of/subdirs/myData/
我不想要。我需要如何修复我的命令,以便它只将数据放在首位?
在serverA
做
( cd /serverA/directory/a/lot/of/subdirs; tar -zcvf myData-archive.tar.gz myData; )
经过一番折腾,我想出了如何实现我想要的:
到服务器 A 上的 tar:
tar -zcvf /serverA/directory/a/lot/of/subdirs/myData-archive.tar.gz -C /serverA/directory/a/lot/of/subdirs/ myData
然后在 serverB 上取消 tar:
tar -zxvf /serverB/current/directory/myData-archive.tar.gz -C /serverB/current/directory/dataHERE