3

Edit 3: For people who will read this question: --verify mysteriously fails with "Warning: Cannot seek: Illegal seek", hence I recommend you look for alternative ways to verify your archives. My original question follows.


Short of restoring it, what is a proper way to ensure the integrity of a .tar.gz backup? I'm using GNU tar.

According to the man page of tar and to what I have read around, tar offers a --verify option while creating an archive and a --diff option to find differences between an existing archive and the file system.

Is a check with --diff redundant right after creating an archive with --verify? Or is --diff more reliable and hence a previous --verify is redundant, unless you want your backup procedure to fail fast?

Should we invoke gzip --test as well to verify the .gz archive, or does tar perform such a check on its own already, both with --verify and --diff? I would say it does.

Thanks for your attention.

Edit: As suggested by Lgeorget, I could store an hash of the archive as well, to check at restoration time that the archive has not been corrupted.

Edit 2: Hence, apparently --verify would be enough. Maybe I could use tar --list to check that the archive is readable and extractable. I also wonder whether --diff checks the contents of files or just their names (and possibly attributes).

2

Yes, a diff after a verify is redundant, and no, there is no point to gzip --test, as the first thing tar has to do to read the archive is ungzip it, so any problems with the compression would cause a failure there.

2

--diff is more intended for backups purposes. For example, to check if it's necessary to tar a directory again when you schedule a periodic backup.

I have no clue about the efficiency of the --verify option. If you have doubt about it, or want to be able to check the integrity of your tar later, you can use a hash.

For example:

> sha1sum etc.tar.gz 
b30d837c623274908de2ebaceb72b07c54037546  etc.tar.gz

Then store this line to a file (let's call it etc.tar.gz.checksum). And when you want to check the integrity, move this file to the directory where etc.tar.gz is and run:

> sha1sum -c etc.tar.gz.checksum 
etc.tar.gz: OK

sha1sum is provided with openssl.

  • Here, I am not concerned about the integrity of an archive: I'm concerned whether its content matches the file-system, while performing backups. Thanks for your suggestion about using an hash, though: I have added it to my question. – Elena Jul 11 '13 at 14:34
  • Well, I suppose I'm being extra careful, here, because most of the guides on backups - that I've read - don't bother to verify the generated archives. – Elena Jul 11 '13 at 14:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.