How do you verify a tar archive that is already written?

GNU tar has a --compare option. See the Comparing Archive Members with the File System section of the documentation for details.


You can't use W with t.

mkdir tmp
echo bdb > tmp/a
echo bdb > tmp/b

tar cvf archive.tar tmp
tmp/
tmp/a
tmp/b

ls -l archive.tar
-rw-r--r-- 1 tony tony 10240 Jun 23 05:57 archive.tar

tar tvf archive.tar
drwxr-sr-x tony/tony         0 2011-06-23 05:57 tmp/
-rw-r--r-- tony/tony         4 2011-06-23 05:57 tmp/a
-rw-r--r-- tony/tony         4 2011-06-23 05:57 tmp/b

tar tvWf archive.tar
tar: This does not look like a tar archive
tar: Skipping to next header
tar: Exiting with failure status due to previous errors

I believe t alone is enough to test the archive.


Joerg Schillings star sports a diff option, which is able to compare files in a tar archive with their original. You can state what should be recognized as difference.

0 1 newt pts/1 ~ 17> :> tmp/testfile
0 1 newt pts/1 ~ 19> star -cz tmp > tmp.tar
0 1 newt pts/1 ~ 19> echo bla > tmp/testfile
0 1 newt pts/1 ~ 20> star -z -diff diffopts=not,times < tmp.tar
diffopts=perm,symperm,type,nlink,uid,gid,uname,gname,size,data,rdev,hardlink,symlink,sympath,sparse,dir,acl,xattr,fflags
tmp/testfile: different size,data
star: 115 blocks + 0 bytes (total of 1177600 bytes = 1150.00k).

Note that it mentioned testfile as being of different size and data. If I hadn't excluded times (including access time!) it would have stated the access time as well, and also list all files whose times had changed just by looking at them.

Since the demise of BerliOS, star can be found at sourceforge. It is highly portable, and compiles painlessly on most unixoid systems and unixoid look-alikes.

Tags:

Tar