如何修复“tar:无法验证压缩档案”错误?

如何修复“tar:无法验证压缩档案”错误?

我想将一个目录压缩成.tar.xz格式并在写入后验证它,所以我写了这样的命令:

tar --xz --create --verbose --verify --file myArchive.tar.xz /patch/to/my/dir

但它没有创建存档,我得到了这两行错误:

    tar: Cannot verify compressed archives 
    try 'tar --help' or 'tar --usage' for more information.

我尝试使用tar.gzformat 代替,tar.xz但得到了完全相同的结果,问题是什么以及如何解决?

答案1

tar 手册第 9.8 节说:

9.8 Verifying Data as It is Stored
==================================

`-W'
`--verify'
     Attempt to verify the archive after writing.

   This option causes `tar' to verify the archive after writing it.
Each volume is checked after it is written, and any discrepancies are
recorded on the standard error output.

   Verification requires that the archive be on a back-space-able
medium.  This means pipes, some cartridge tape drives, and some other
devices cannot be verified.

压缩存档不能退格,因此在尝试混合这两个选项时会收到错误。

接下来的段落提到--compare,您应该使用它:

   One can explicitly compare an already made archive with the file
system by using the `--compare' (`--diff', `-d') option, instead of
using the more automatic `--verify' option.  *Note compare::.

   Note that these two options have a slightly different intent.  The
`--compare' option checks how identical are the logical contents of some
archive with what is on your disks, while the `--verify' option is
really for checking if the physical contents agree and if the recording
media itself is of dependable quality.  So, for the `--verify'
operation, `tar' tries to defeat all in-memory cache pertaining to the
archive, while it lets the speed optimization undisturbed for the
`--compare' option.  If you nevertheless use `--compare' for media
verification, you may have to defeat the in-memory cache yourself,
maybe by opening and reclosing the door latch of your recording unit,
forcing some doubt in your operating system about the fact this is
really the same volume as the one just written or read.

   The `--verify' option would not be necessary if drivers were indeed
able to detect dependably all write failures.  This sometimes require
many magnetic heads, some able to read after the writes occurred.  One
would not say that drivers unable to detect all cases are necessarily
flawed, as long as programming is concerned.

用于--compare验证,您可以执行以下操作:

tar --xz --create --verbose --file myArchive.tar.xz /patch/to/my/dir
tar --compare --file myArchive.tar.xz /patch/to/my/dir

相关内容