3 # whatsthis : just read an ID off the tape and display it to the user.
4 # Peter Maydell <pmaydell@chiark.greenend.org.uk>
5 # First rough hack; mostly just code nabbed from full.
6 # --list assumes the dump type was 'zafio', which is a bit bogus.
8 # whatsthis : no args => just print tapeid
9 # whatsthis --list [n] : print tapeid then list archive n (if n omitted,
10 # 0 is assumed.) Note that archives are numbered from zero!
16 require "$etc/settings.pl";
17 require 'backuplib.pl';
21 # This isn't intended to be run automatically, so don't bother
22 # with setting status.
24 # If we are run with the argument --list then list the backup to
25 # stdout. Otherwise just print the tape ID.
26 $listing = 0; # default : don't list
27 $listing = 1 if ($ARGV[0] eq '--list');
29 $listarchive = $ARGV[1] if defined $ARGV[1];
31 print "Trying to read tape ID from currently inserted tape...\n";
34 system "mt -f $ntape setblk $blocksizebytes"; $? and die $?;
35 system "dd if=$ntape bs=${blocksize}b count=10 | tar -b$blocksize -vvxf - TAPEID";
36 $? and stopandsay "Failed to read TAPEID.\n";
38 if (!open(T, "TAPEID"))
40 stopandsay "Tape has no ID label.\n";
43 # OK, there's a TAPEID file, read the ID and check for sanity.
45 if ($tapeid =~ m/[^0-9a-zA-Z]/)
47 stopandsay "Tape has a bad (non-alphanumeric) TAPEID ($&).\n";
49 elsif (! $tapeid =~ m/[0-9a-zA-Z]/)
51 stopandsay "Empty TAPEID.\n";
54 print "TAPEID is $tapeid.\n";
57 # If we aren't listing the tape contents, we can just rewind the tape
65 # List the contents of archive $listarchive on the tape.
66 # We are already at the right place for the first archive
68 # For any other archive, we skip forwards to the start of that archive.
71 system "mt -f $ntape fsf $listarchive";
72 $? and stopandsay "Couldn't skip forward to archive $listarchive.";
75 # Use file to figure out what the archive type is
76 # This doesn't seem to work too well, so I'm disabling it -- PMM
77 #$ftype = `dd if=$ntape ibs=$blocksizebytes | file -`;
78 #$? and stopandsay "couldn't determine file type: $?";
81 # What we want to do here is roughly:
82 # dd if=$ntape ibs=$blocksizebytes | readbuffer | afio ???
84 # where the afio options are such as to list an archive created with
85 # afio -b $softblocksizebytes -Zvo
87 if ($ftype =~ /POSIX tar/) {
88 # POSIX tar archive; we read it with cpio
89 $reader = "cpio -it -C$softblocksizebytes -Hustar";
90 } elsif ($ftype =~ /ASCII cpio/) {
91 $reader = "afio -b $softblocksizebytes -Zt -";
92 } elsif ($ftype =~ /dump file/) {
93 stopandsay "sorry: can't list dump files yet";
95 stopandsay "listing failed: unknown archive type";
98 # Now back up so we can read the file again properly
99 #system "mt -f $ntape bsf 1"; $? and stopandsay "couldn't backspace tape: $?";
101 system "dd if=$ntape ibs=$blocksizebytes | /usr/local/lib/backup/readbuffer | $reader";
102 $? and stopandsay "listing failed: $?";
104 # All's well, stop here.
105 print "Listing complete.\n";
113 system "mt -f $tape rewind"; $? and die $?;
116 # Print the given message, rewind the tape and exit failure.