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 #--------------------------------------------------------
136 if ($logfile eq '-') {$IF=STDIN} else
137 {die ("Cannot open logfile $logfile") unless open (IF,"$logfile");$IF=IF;}
144 if ( /^FAIL dumper (\S+) (\S+)/ ) {
147 if ( /^SUCCESS dumper (\S+) (\S+)/ ) {
150 $line =~ /orig-kb (\d+)/;
151 $osize{$host}{$disk} = $1;
152 $tot_or_size += $osize{$host}{$disk};
153 $fail{$host}{$disk} = 0;
156 if ( /^START amflush/ ) {
160 if ( ! /^([A-Z]+) taper (\S+) (\S+) (\S+) (\S+) (\S+)/) { next;}
168 /START taper/ && do {
169 $tocfilename=&tfn($chunk) if ($#subs >= 0);
170 if (!$tocfilename || ($tocfilename eq '-')) {$OF=STDOUT;}
172 die ("Cannot open tocfile $tocfilename") unless open(OF,">$tocfilename");
176 print $OF "\f" if ($vwspace && $filenumber);
177 if (defined($info)) {
178 print $OF "AMANDA: To restore:\n";
179 print $OF " position tape at start of file and run:\n";
180 print $OF " dd if=<tape> bs=32k skip=1 [ | zcat ] | restore -...f\n";
181 print $OF " or run: amrestore -p <tape> [host [partition]] | restore -...f\n";
188 &pr("#","Server","/partition","date", "level","size[Kb]","part");
189 &pr("$filenumber","$chunk","","$disk","-","-","-");
191 /^(?:SUCCESS|CHUNK) taper/ && do {
200 if ( $fail{$host}{$disk} ) {
201 &pr("$filenumber","${host}","${disk}","${date}","${level}","FAIL","${chunk}");
203 if (defined($flash_mode)) {
204 &pr("$filenumber","${host}","${disk}","${date}","${level}","$mysize","${chunk}");
206 if (defined($osize{$host}{$disk}) && !/^CHUNK/) {
207 &pr("$filenumber","${host}","${disk}","${date}","${level}","$osize{$host}{$disk}","${chunk}");
211 # this case should never happend:
215 &pr("$filenumber","${host}","${disk}","${date}","${level}","$note$mysize","${chunk}");
220 /INFO taper retrying/ && do {
223 /INFO taper tape .* \[OK\]/ && do {
224 $line =~ / kb (\d+) /;
226 $line =~ / fm (\d+) /;
227 print "\n\n" if ($vwspace);
228 &pr("$1","total","on_tape","-","-","$size","-");
229 if (defined($flash_mode)) {
230 &pr("$1","total","origin","-","not","available","-");
232 &pr("$1","total","origin","-","-","$tot_or_size","-");
234 if (defined($strange)) {
235 &pr("*","size","on_tape","-","-","-","-");
238 /FAIL taper/ && do { next; };
247 @>> @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @<<<<<<<< @>> @>>>>>>>>
248 $fnbr,$hstprt,$dt,$lvl,$sz
252 @>> @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @<<<<<<<< @>> @>>>>>>>> @>>>
253 $fnbr,$hstprt,$dt,$lvl,$sz,$ch