0

I am using GNU tar to create multi-volume archives:

DIR=~/temp
BLOCKSIZE=500M
tar cMf multi-0001.tar --new-volume-script=volume-script.sh --tape-length=$BLOCKSIZE $DIR

I want to create a file listing that shows the contents of each volume. I have tried adding multiple --verbose options, and while that does give me a list of all the files that are being archived, it does not tell me which volume they are in.

I am aware that I could run each volume through tar again using the --list command, but I would prefer to avoid having to process all my data twice.

(For reference, the content of volume-script.sh is as follows; I do not believe it is relevant to the question

#! /bin/bash
echo multi-$(printf "%04d" $TAR_VOLUME).tar >&$TAR_FD

)

EDIT: Question withdrawn

This question contains a false assumption. It is confirmed in the answer to this followup question that --list is a perfectly acceptable way of creating index files on seekable media. My solution now looks like this:

DIR=~/temp
BLOCKSIZE=500M
tar cMf multi-0001.tar --new-volume-script=volume-script.sh --tape-length=$BLOCKSIZE $DIR

for i in *.tar;
 do echo q | tar --list -M -f $i --verbose --verbose > $i.index.txt 2>/dev/null;
done
1

I think what you are asking for is just: tar tvf filename

That creates a list of what's in the tar file without opening it. You'll have to run it after you create the tar archive, but it should give you what you need.

You can simply chain that off the back of your tar command by doing this: tar cMf multi-0001.tar --new-volume-script=volume-script.sh --tape-length=$BLOCKSIZE $DIR ; tar tvf multi-0001.tar > multi-001-listing.txt

| improve this answer | |
0

There may be a simple way to do this that I'm overlooking but I think you can have your volume script extract the new names from the verbose index output. Something like this (untested):

export templisting=$(mktemp)
export tempoffset=$(mktemp)
DIR=~/temp
BLOCKSIZE=500M
tar cvMf multi-0001.tar --index-file=$templisting --new-volume-script=volume-script.sh --tape-length=$BLOCKSIZE $DIR
rm $templisting $tempoffset

In volume-script.sh (uses logtail, can be done without):

#! /bin/bash
echo multi-$(printf "%04d" $TAR_VOLUME).tar >&$TAR_FD
listingfile= #however you want to name listing files.
logtail -f$templisting -o$tempoffset > $listingfile
| improve this answer | |
  • Thanks - neat idea. This has two problems. Firstly, in your example the volume script will not be run for the last member of the volume set. This can be worked around easily by adding another logtail command at the end of the main script, and passing the "next volume name" back via a variable. The second issue (which I have no workaround for) is that the verbose output does not indicate when a file is split across multiple volumes. For example, a 1.2GB file split across three 500MB volumes will be mentioned in the index of the first volume only. The index for the other two vols will be blank. – jl6 Sep 1 '16 at 21:31

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.