如何打开使用 tar 管道传输到 gzip 创建的 tar gz 文件

如何打开使用 tar 管道传输到 gzip 创建的 tar gz 文件

我想生成一个压缩率最高的 tar gz 文件,我按照以下解决方案进行操作https://superuser.com/a/546509/461740

tar cv /path/to/directory | gzip -9 > file.tar.gz

但是现在,我无法解压缩该文件,出现以下错误:

tar: This does not look like a tar archive
tar: Skipping to next header
tar: Archive contains ‘23241_at',16’ where numeric off_t value expected 

我用 Google 搜索了这个错误,大多数情况下它是由“双重” gzip 压缩引起的,我尝试了针对此问题提出的解决方案,但它似乎与我的问题不符。

有什么办法可以修复它吗?

编辑:值得注意的是,当我file在未压缩的文件(应该是一个 tar 文件)上调用该命令时,我得到了结果:data

编辑:结果head -c512 file.tar | hexdump -C

00000000  73 71 6c 5f 64 75 6d 70  2f 0a 73 71 6c 5f 64 75  |sql_dump/.sql_du|
00000010  6d 70 2f 62 67 65 65 46  6f 72 65 69 67 6e 4b 65  |mp/bgeeForeignKe|
00000020  79 2e 73 71 6c 0a 73 71  6c 5f 64 75 6d 70 2f 00  |y.sql.sql_dump/.|
00000030  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000080  00 00 00 00 00 00 00 00  00 00 30 30 30 30 37 35  |..........000075|
00000090  35 00 30 30 30 37 36 34  33 00 30 30 31 31 33 30  |5.0007643.001130|
000000a0  30 00 30 30 30 30 30 30  30 30 30 30 30 00 31 32  |0.00000000000.12|
000000b0  35 33 35 31 36 30 34 34  34 00 30 31 32 37 30 33  |535160444.012703|
000000c0  00 20 35 00 00 00 00 00  00 00 00 00 00 00 00 00  |. 5.............|
000000d0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000120  00 00 00 00 00 00 00 75  73 74 61 72 20 20 00 66  |.......ustar  .f|
00000130  62 61 73 74 69 61 6e 00  00 00 00 00 00 00 00 00  |bastian.........|
00000140  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 75  |...............u|
00000150  6e 69 6c 64 65 65 00 00  00 00 00 00 00 00 00 00  |nildee..........|
00000160  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000200

按照@kasperd 命令尝试修复我的文件,tail -c+39 file.tar > repaired.tar前 512 个字节的十六进制转储:

00000000  73 71 6c 5f 64 75 6d 70  2f 00 00 00 00 00 00 00  |sql_dump/.......|
00000010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000060  00 00 00 00 30 30 30 30  37 35 35 00 30 30 30 37  |....0000755.0007|
00000070  36 34 33 00 30 30 31 31  33 30 30 00 30 30 30 30  |643.0011300.0000|
00000080  30 30 30 30 30 30 30 00  31 32 35 33 35 31 36 30  |0000000.12535160|
00000090  34 34 34 00 30 31 32 37  30 33 00 20 35 00 00 00  |444.012703. 5...|
000000a0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000100  00 75 73 74 61 72 20 20  00 66 62 61 73 74 69 61  |.ustar  .fbastia|
00000110  6e 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |n...............|
00000120  00 00 00 00 00 00 00 00  00 75 6e 69 6c 64 65 65  |.........unildee|
00000130  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000200

tar -tvf“修复” tar的结果:

drwxr-xr-x username  0 2015-06-08 02:26 sql_dump/
-rw-r--r-- username 19123 2015-06-08 02:25 sql_dump/bgeeForeignKey.sql
tar: Skipping to next header
tar: Archive contains `688_x_at\',1' where numeric off_t value expected
tar: Archive contains `y\',\'not ' where numeric mode_t value expected
tar: Archive contains `725,\'ENSG' where numeric time_t value expected
tar: Archive contains `excluded' where numeric uid_t value expected
tar: Archive contains `\'),(\'208' where numeric gid_t value expected
tar: Archive contains `excluded' where numeric uid_t value expected
tar: Archive contains `\'),(\'208' where numeric gid_t value expected
?rwsrwsrwt 4294967295/4294967295 18446744073709551615 1970-01-01 00:59 ty','not excluded'),('208686_s_at',13725,'ENSG00000204256',7.73,'present',15097863,NULL,'high qualit unknown file type `\''
tar: Skipping to next header
tar: Archive contains `ent\'),(31801' where numeric off_t value expected
tar: Archive contains `no data\'' where numeric mode_t value expected
tar: Archive contains `347,\'ENSG' where numeric time_t value expected
tar: Archive contains `,\'no dat' where numeric uid_t value expected
tar: Archive contains `a\',\'desc' where numeric gid_t value expected
tar: Archive contains `,\'no dat' where numeric uid_t value expected
tar: Archive contains `a\',\'desc' where numeric gid_t value expected
?rwsrwsrwt 4294967295/4294967295 18446744073709551615 1970-01-01 00:59 ,'descent'),(31801346,'ENSG00000104375','UBERON:0007625','HsapDv:0000095','no data','poor quality',' unknown file type `\''
tar: Skipping to next header
tar: Exiting with failure status due to previous errors

输出dd if=repaired.tar skip=39 count=2 | hexdump -C

2+0 records in
2+0 records out
1024 bytes (1.0 kB) copied00000000  64 64 20 66 6f 72 65 69  67 6e 20 6b 65 79 20 28  |dd foreign key (|
00000010  64 69 66 66 65 72 65 6e  74 69 61 6c 45 78 70 72  |differentialExpr|
00000020  65 73 73 69 6f 6e 49 64  29 20 72 65 66 65 72 65  |essionId) refere|
00000030  6e 63 65 73 20 64 69 66  66 65 72 65 6e 74 69 61  |nces differentia|
00000040  6c 45 78 70 72 65 73 73  69 6f 6e 28 64 69 66 66  |lExpression(diff|
, 6.9324e-05 s, 14.8 MB/s
00000050  65 72 65 6e 74 69 61 6c  45 78 70 72 65 73 73 69  |erentialExpressi|
00000060  6f 6e 49 64 29 20 6f 6e  20 64 65 6c 65 74 65 20  |onId) on delete |
00000070  73 65 74 20 6e 75 6c 6c  3b 0a 2f 2a 21 34 30 30  |set null;./*!400|
00000080  30 30 20 41 4c 54 45 52  20 54 41 42 4c 45 20 60  |00 ALTER TABLE `|
00000090  64 65 61 52 4e 41 53 65  71 53 75 6d 6d 61 72 79  |deaRNASeqSummary|
000000a0  60 20 45 4e 41 42 4c 45  20 4b 45 59 53 20 2a 2f  |` ENABLE KEYS */|
000000b0  3b 0a 0a 00 00 00 00 00  00 00 00 00 00 00 00 00  |;...............|
000000c0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000200  73 71 6c 5f 64 75 6d 70  2f 52 45 41 44 4d 45 2e  |sql_dump/README.|
00000210  74 78 74 0a 73 71 6c 5f  64 75 6d 70 2f 62 67 65  |txt.sql_dump/bge|
00000220  65 49 6e 64 65 78 2e 73  71 6c 0a 73 71 6c 5f 64  |eIndex.sql.sql_d|
00000230  75 6d 70 2f 64 75 6d 70  5f 62 67 65 65 5f 76 31  |ump/dump_bgee_v1|
00000240  33 5f 31 2e 73 71 6c 0a  73 71 6c 5f 64 75 6d 70  |3_1.sql.sql_dump|
00000250  2f 52 45 41 44 4d 45 2e  74 78 74 00 00 00 00 00  |/README.txt.....|
00000260  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000002a0  00 00 00 00 00 00 00 00  00 00 00 00 30 30 30 30  |............0000|
000002b0  36 34 34 00 30 30 30 37  36 34 33 00 30 30 31 31  |644.0007643.0011|
000002c0  33 30 30 00 30 30 30 30  30 30 30 32 30 36 34 00  |300.00000002064.|
000002d0  31 32 35 33 35 31 36 30  31 37 34 00 30 31 34 34  |12535160174.0144|
000002e0  30 33 00 20 30 00 00 00  00 00 00 00 00 00 00 00  |03. 0...........|
000002f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000340  00 00 00 00 00 00 00 00  00 75 73 74 61 72 20 20  |.........ustar  |
00000350  00 66 62 61 73 74 69 61  6e 00 00 00 00 00 00 00  |.fbastian.......|
00000360  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000370  00 75 6e 69 6c 64 65 65  00 00 00 00 00 00 00 00  |.unildee........|
00000380  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000400

答案1

如果一切顺利就足够了

tar -zxvf file.tar.gz

压缩时z需要此选项gzip
tar(GNU tar)1.27.1没有它也能工作

tar -xvf Myfile.tar.gz

如果没有特殊原因,您可以直接使用以下命令创建 tarred gzip 文件:

tar -zcvf Myfile.tar.gz  /path/to/directory

或者使用不同的压缩程序

tar -jcvf Myfile.tar.bz  /path/to/directory

要检查要拨号的文件类型,请使用以下命令file

file *.tar.*

Myfile.tar.gz: gzip compressed data, from Unix, last modified:...
Myfile.tar.bz: bzip2 compressed data, block size = 900k

答案2

tar -xvfz file.tar.gz
  • -x 提取
  • -z gunzip
  • -v 详细

更新

也可以尝试这个:

gunzip < file.tar.gz | tar xvf -

答案3

您所说的用于创建存档的命令没有任何问题。您可以使用以下命令列出内容并验证存档的校验和:

tar -tzf file.tar.gz

从你的问题来看,你现在拥有的文件似乎并不是真正的.tar.gz文件。该文件一定发生了一些意外情况,我能想到的可能性是:

  1. 您一开始就输入了错误生成档案的命令。
  2. tar命令或gzip您运行该命令时所包含的命令PATH不是真实版本,而是产生错误输出的其他命令。
  3. 您有一个环境变量覆盖了版本损坏的程序所使用的某些库。
  4. 硬件错误导致数据损坏。
  5. 在您创建文件和尝试提取文件期间,某些程序曾被用来修改该文件。

为了弄清楚这个文件到底出了什么问题以及如何恢复它,我们需要仔细查看该文件的实际内容。

在您更新的问题中提供的十六进制转储中,我注意到许多字段在标头内未正确对齐。与好的 tar 文件相比,我发现您的文件中的字段在文件内的位置太远了 38 个字节。

此外,我注意到您的档案库中的第一个目录的名称很长,甚至在第 38 个字节有一个换行符。

因此,我的结论是,你的文件的内容不仅仅是一个 tar 存档。它是一行文本,后面跟着一个 tar 存档。错误的行显示为

sql_dump/.sql_dump/bgeeForeignKey.sql

我不知道您是如何设法将这一行存储在.tar.gz文件中的。但是如果我们跳过它,第一个目录的名称会更合理sql_dump/。如果这是唯一的损坏,您将能够通过以下命令恢复数据:

tail -c+39 file.tar > repaired.tar

答案4

您忘记减去将 tar 输出重定向到管道:

$ tar cf - /path/to/directory | gzip -9 > file.tar.gz

相关内容