3 # create a TOC (Table Of Content) file for an amanda dump
5 # Author: Nicolas.Mayencourt@cui.unige.ch
10 # 1.0 19??-??-?? nicolas@cui.unige.ch
12 # 2.0 1996-??-?? nicolas@cui.unige.ch
13 # amanda 2.2.6 support
14 # 3.0 1999-02-17 Nicolas.Mayencourt@cui.unige.ch
15 # major rewrite, incompatible with release 2.0, amanda 2.4 support
16 # 3.0.1 1999-02-17 oliva@dcc.unicamp.br
17 # minor fixes for multi-tape runs
18 # 3.0.2 1999-02-28 martineau@IRO.UMontreal.CA
19 # output the datestamp of each dump
20 # 3.0.3 1999-09-01 jrj@purdue.edu
21 # allow multiple -s entries
22 # 3.0.4 1999-09-15 jrj@purdue.edu
23 # handle an image failing on one tape...
24 # 3.1.0 1999-10-06 Nicolas.Mayencourt@cui.unige.ch
25 # add new options (-i -t)
26 # 3.1.1 1999-10-08 Nicolas.Mayencourt@cui.unige.ch
27 # print original size, instead of size-on-tape
28 # 3.1.2 1999-10-11 Nicolas.Mayencourt@cui.unige.ch
29 # really print original size, instead of size-on-tape
30 # 3.1.3 Nicolas.Mayencourt@cui.unige.ch
31 # correct a bug for total report
32 # 3.1.4 2000-01-14 dhw@whistle.com
33 # Add a flag (-w) for vertical whitespace
36 #--------------------------------------------------------
38 # you can update these proc if you want another formating
39 # format: filenumber host:part date level size
40 # If you use tabular option, modifie the format at the end of the code
41 if (defined($tabular)) {
43 $hstprt=$_[1] . ":" . $_[2];
50 print $OF "$_[0] $_[1]:$_[2] $_[3] $_[4] $_[5] $_[6]\n";
53 #--------------------------------------------------------
57 #--------------------------------------------------------
59 # calculate tocfilename
66 #--------------------------------------------------------
69 #--------------------------------------------------------
71 print STDERR "@_\n\n";
72 print STDERR "usage: amtoc [-a] [-i] [-t] [-f file] [-s subs] [-w] [--] logfile\n";
73 print STDERR " -a : file output to `label`.toc\n";
74 print STDERR " -i : Start TOC with a small help message\n";
75 print STDERR " -t : tabular output\n";
76 print STDERR " -f file : output to file\n";
77 print STDERR " -s subs : output file name evaluated to `eval \$subs`\n";
78 print STDERR " -w : add vertical whitespace after each tape\n";
79 print STDERR " -- : last option\n";
80 print STDERR " logfile : input file ('-' for stdin)\n";
83 #--------------------------------------------------------
85 #--------------------------------------------------------
87 &usage("amtoc required at least 'logfile' parameter.") if ($#ARGV==-1) ;
90 for ($i=0;$i<=$#ARGV;$i++) {
91 if ($ARGV[$i] eq '-a') {
92 push (@subs, "s/\$/.toc/");
94 elsif ($ARGV[$i] eq '-i') {
97 elsif ($ARGV[$i] eq '-t') {
100 elsif ($ARGV[$i] eq '-f') {
102 &usage("'-f' option require 'file' parameter.") if ($i > $#ARGV);
103 $tocfilename=$ARGV[$i];
105 elsif ($ARGV[$i] eq '-s') {
107 &usage("'-s' option require 'subs' parameter.") if ($i > $#ARGV);
108 push (@subs, $ARGV[$i]);
110 elsif ($ARGV[$i] eq '-w') {
113 elsif ($ARGV[$i] eq '--') {
114 # no more options: next arg == logfile
116 &usage("amtoc required at least 'logfile' parameter.") if ($i > $#ARGV);
118 &usage("too many parameters.") unless ($i == $#ARGV);
122 &usage("too many parameters.") unless ($i == $#ARGV);
125 &usage("amtoc required at least 'logfile' parameter.") unless ($logfile);
128 #--------------------------------------------------------
132 delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV', 'PATH'};
133 $ENV{'PATH'} = "/usr/bin:/usr/sbin:/sbin:/bin";
139 if ($logfile eq '-') {$IF=STDIN} else
140 {die ("Cannot open logfile $logfile") unless open (IF,"$logfile");$IF=IF;}
147 if ( /^FAIL dumper (\S+) (\S+)/ ) {
150 if ( /^SUCCESS dumper (\S+) (\S+)/ ) {
153 $line =~ /orig-kb (\d+)/;
154 $osize{$host}{$disk} = $1;
155 $tot_or_size += $osize{$host}{$disk};
156 $fail{$host}{$disk} = 0;
159 if ( /^START amflush/ ) {
163 if ( ! /^([A-Z]+) taper (\S+) (\S+) (\S+) (\S+) (\S+)/) { next;}
166 /^([A-Z]+) taper (\S+) (\S+) (\S+) (\S+) (\S+) (\S+) (\S+)/;
173 if ($filenum != $filenumber) {
174 # This should not be possible */
175 $filenumber = $filenum;
178 /^([A-Z]+) taper (\S+) (\S+) (\S+) (\S+) (\S+)/;
186 /START taper/ && do {
187 $tocfilename=&tfn($chunk) if ($#subs >= 0);
188 if (!$tocfilename || ($tocfilename eq '-')) {$OF=STDOUT;}
190 die ("Cannot open tocfile $tocfilename") unless open(OF,">$tocfilename");
194 print $OF "\f" if ($vwspace && $filenumber);
195 if (defined($info)) {
196 print $OF "AMANDA: To restore:\n";
197 print $OF " position tape at start of file and run:\n";
198 print $OF " dd if=<tape> bs=32k skip=1 [ | zcat ] | restore -...f\n";
199 print $OF " or run: amrestore -p <tape> [host [partition]] | restore -...f\n";
206 &pr("#","Server","/partition","date", "level","size[Kb]","part");
207 &pr("$filenumber","$chunk","","$disk","-","-","-");
209 /^(?:SUCCESS|CHUNK|PART|DONE) taper/ && do {
214 $filenum = $filenumber;
224 if ( $fail{$host}{$disk} ) {
225 &pr("$filenum","${host}","${disk}","${date}","${level}","FAIL","${chunk}");
227 if (defined($flash_mode)) {
228 &pr("$filenum","${host}","${disk}","${date}","${level}","$mysize","${chunk}");
230 if (defined($osize{$host}{$disk}) && !/^CHUNK/ && !/^PART/) {
231 &pr("$filenum","${host}","${disk}","${date}","${level}","$osize{$host}{$disk}","${chunk}");
234 if(!/^CHUNK/ && !/^PART/){
235 # this case should never happend:
239 &pr("$filenum","${host}","${disk}","${date}","${level}","$note$mysize","${chunk}");
244 /INFO taper retrying/ && do {
247 /INFO taper tape .* \[OK\]/ && do {
248 $line =~ / kb (\d+) /;
250 $line =~ / fm (\d+) /;
251 print "\n\n" if ($vwspace);
252 &pr("$1","total","on_tape","-","-","$size","-");
254 /FAIL taper/ && do { next; };
258 if (defined($flash_mode)) {
259 &pr("-","total","origin","-","not","available","-");
261 &pr("-","total","origin","-","-","$tot_or_size","-");
268 @>> @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<< @>> @>>>>>>>>
269 $fnbr,$hstprt,$dt,$lvl,$sz
273 @>> @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<< @>> @>>>>>>>> @>>>
274 $fnbr,$hstprt,$dt,$lvl,$sz,$ch