This file is indexed.

/usr/sbin/amtoc is in amanda-server 1:3.5.1-1build2.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
#!/usr/bin/perl -w

use strict;
use warnings;

# create a TOC (Table Of Content) file for an amanda dump

# Author: Nicolas.Mayencourt@cui.unige.ch

# release 3.1.4

# HISTORY
# 1.0 19??-??-?? nicolas@cui.unige.ch
#	don't remember :-)
# 2.0 1996-??-?? nicolas@cui.unige.ch
#	amanda 2.2.6 support
# 3.0 1999-02-17 Nicolas.Mayencourt@cui.unige.ch
#	major rewrite, incompatible with release 2.0, amanda 2.4 support
# 3.0.1 1999-02-17 oliva@dcc.unicamp.br
#	minor fixes for multi-tape runs
# 3.0.2 1999-02-28 martineau@IRO.UMontreal.CA
#	output the datestamp of each dump
# 3.0.3 1999-09-01 jrj@purdue.edu
#	allow multiple -s entries
# 3.0.4 1999-09-15 jrj@purdue.edu
#	handle an image failing on one tape...
# 3.1.0 1999-10-06 Nicolas.Mayencourt@cui.unige.ch
#	add new options (-i -t)
# 3.1.1 1999-10-08 Nicolas.Mayencourt@cui.unige.ch
#	print original size, instead of size-on-tape
# 3.1.2 1999-10-11 Nicolas.Mayencourt@cui.unige.ch
#	really print original size, instead of size-on-tape
# 3.1.3 Nicolas.Mayencourt@cui.unige.ch
#	correct a bug for total report
# 3.1.4 2000-01-14 dhw@whistle.com
#	Add a flag (-w) for vertical whitespace

my %lines;
my %dates;
my %labels;
my $IF;
my $OF;
my $tabular;
my $fnbr;
my $hstprt;
my $dt;
my $lvl;
my $sz;
my $ch;
my $s;
my @subs;
my $dir;
my $i;
my $info;
my $tocfilename;
my $vwspace;
my $logfile;
my $filenumber;
my $tot_or_size;
my $line;
my $host;
my $disk;
my %osize;
my %fail;
my $flash_mode;
my $storage;
my $pool;
my $label;
my $filenum;
my $date;
my $chunk;
my $level;
my $mysize;
my $note;
my $size;

#--------------------------------------------------------
sub pr($$$$$$$) { 
# you can update these proc if you want another formating
# format: filenumber  host:part  date  level  size
# If you use tabular option, modifie the format at the end of the code
  if (defined($tabular)) {
	$fnbr=$_[0];
	$hstprt=$_[1] . ":" . $_[2];
	$dt=$_[3];
	$lvl=$_[4];
	$sz=$_[5];
	$ch=$_[6];
    write($OF);
  } else {
    print $OF "$_[0]  $_[1]:$_[2]  $_[3]  $_[4]  $_[5]  $_[6]\n";
  }
}
#--------------------------------------------------------



#--------------------------------------------------------
sub tfn($) {
  # calculate tocfilename
  $_ = $_[0];
  foreach $s (@subs) {
    eval $s;
  }
  return $dir . $_ ;
}
#--------------------------------------------------------


#--------------------------------------------------------
sub usage($) {
  print STDERR "@_\n\n";
  print STDERR "usage: amtoc [-a] [-i] [-t] [-f file] [-s subs] [-w] [--] logfile\n";
  print STDERR "         -a      : file output to `label`.toc\n";
  print STDERR "         -i      : Start TOC with a small help message\n";
  print STDERR "         -t      : tabular output\n";
  print STDERR "         -f file : output to file\n";
  print STDERR "         -s subs : output file name evaluated to `eval \$subs`\n";
  print STDERR "         -w      : add vertical whitespace after each tape\n";
  print STDERR "         --      : last option\n";
  print STDERR "         logfile : input file ('-' for stdin)\n";
  exit;
}
#--------------------------------------------------------

#--------------------------------------------------------
sub init() {
  &usage("amtoc required at least 'logfile' parameter.") if ($#ARGV==-1) ;

  @subs = ();
  for ($i=0;$i<=$#ARGV;$i++) {
    if ($ARGV[$i] eq '-a') {
        push (@subs, "s/\$/.toc/");
      }
    elsif ($ARGV[$i] eq '-i') {
        $info=1;
      }
    elsif ($ARGV[$i] eq '-t') {
        $tabular=1;
      }
    elsif ($ARGV[$i] eq '-f') {
        $i++;
        &usage("'-f' option require 'file' parameter.")  if ($i > $#ARGV);
        $tocfilename=$ARGV[$i];
      }
    elsif ($ARGV[$i] eq '-s') {
        $i++;
        &usage("'-s' option require 'subs' parameter.")  if ($i > $#ARGV);
        push (@subs, $ARGV[$i]);
      }
    elsif ($ARGV[$i] eq '-w') {
        $vwspace=1;
      }
    elsif ($ARGV[$i] eq '--') {
      # no more options: next arg == logfile
        $i++;
        &usage("amtoc required at least 'logfile' parameter.") if ($i > $#ARGV);
        $logfile=$ARGV[$i];
        &usage("too many parameters.") unless ($i == $#ARGV);
      }
    else {
        $logfile=$ARGV[$i];
        &usage("too many parameters.") unless ($i == $#ARGV);
      }
  }
  &usage("amtoc required at least 'logfile' parameter.") unless ($logfile);
}

#--------------------------------------------------------

&init;

delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV', 'PATH'};
$ENV{'PATH'} = "/usr/bin:/usr/sbin:/sbin:/bin";

$dir=$logfile;
$dir =~ s/[^\/]*$//;


if ($logfile eq '-') {$IF=*STDIN} else 
  {die ("Cannot open logfile $logfile") unless open ($IF,"$logfile");}

$filenumber=0;
$tot_or_size=0;

while ( <$IF> ) {
  $line = $_;
  if ( /^FAIL dumper (\S+) (\S+)/ ) {
    next;
  }
  if ( /^SUCCESS dumper (\S+) (\S+)/ ) {
    $host = $1;
    $disk = $2;
    $line =~ /orig-kb (\d+)/;
    $osize{$host}{$disk} = $1;
    $tot_or_size += $osize{$host}{$disk};
    $fail{$host}{$disk} = 0;
    next;
  }
  if ( /^START amflush/ ) {
    $flash_mode = 1;
    next;
  }
  if ( ! /^([A-Z]+) taper \S+ \S+ (\S+) (\S+) (\S+) (\S+) (\S+)/) { next;}
  # $_ = $1;
  if (/PART taper/) {
    if (/^([A-Z]+) taper ("ST:\S+") ("POOL:\S+") (\S+) (\S+) (\S+) (\S+) (\S+) (\S+) (\S+)/) {
        $storage = $2;
        $pool = $3;
        $label = $4;
        $filenum = $5;
        $host = $6;
        $disk = $7;
        $date = $8;
        $chunk = $9;
        $level = $10;
	$labels{$storage}{$pool}{$host}{$disk}{$date} = $label;
    } else {
        /^([A-Z]+) taper (\S+) (\S+) (\S+) (\S+) (\S+) (\S+) (\S+)/;
        $label = $2;
        $filenum = $3;
        $host = $4;
        $disk = $5;
        $date = $6;
        $chunk = $7;
        $level = $8;
    }
    if ($filenum != $filenumber) {
      # This should not be possible */
      $filenumber = $filenum;
    }
  } elsif (/START taper/) {
    if (/^([A-Z]+) taper (\S+) (\S+) ("ST:\S+") ("POOL:\S+") (\S+) (\S+) (\S+)/) {
        $date = $3;
        $storage = $4;
        $pool = $5;
        $label = $7;
        $level = $7;
    } else {
        /^([A-Z]+) taper (\S+) (\S+) (\S+) (\S+) (\S+)/;
        $date = $3;
        $label = $4;
        $level = $5;
    }
  } else {
    if (/^([A-Z]+) taper ("ST:\S+") ("POOL:\S+") (\S+) (\S+) (\S+) (\S+) (\S+)/) {
        $storage = $2;
        $pool = $3;
        $host = $4;
        $disk = $5;
        $date = $6;
        $chunk = $7;
        $level = $8;
	$label = $labels{$storage}{$pool}{$host}{$disk}{$date};
    } else {
        /^([A-Z]+) taper (\S+) (\S+) (\S+) (\S+) (\S+)/;
        $host = $2;
        $disk = $3;
        $date = $4;
        $chunk = $5;
        $level = $6;
    }
  }
  switch: {
    /START taper/ && do {
      $tocfilename=&tfn($label) if ($#subs >= 0);
      if (!$tocfilename || ($tocfilename eq '-')) {$OF=*STDOUT;}
      else {
          die ("Cannot open tocfile $tocfilename") unless open($OF,">$tocfilename");
        }

	print $OF "\f" if ($vwspace && $filenumber);
	if (defined($info)) {
	  print $OF "AMANDA: To restore:\n";
	  print $OF "    position tape at start of file and run:\n";
	  print $OF "        dd if=<tape> bs=32k skip=1 [ | zcat ] | restore -...f\n";
	  print $OF "    or run: amrestore -p <tape> [host [partition]] | restore -...f\n";
	  print $OF "\n";
	}



      $filenumber=0;
#      &pr("#","Server","/partition","date", "level","size[Kb]","part");
#      &pr("$filenumber","$label","","$date","-","-","-");
      $dates{$label} = $date;
      last switch; };
    /^(?:SUCCESS|CHUNK|PART|DONE) taper/ && do {
      if(/SUCCESS/){
	$level = $chunk;
	$chunk = "-";
      }
      $filenum = $filenumber;
      if (/DONE/) {
	$chunk = "-";
	$filenumber--;
	$filenum = " ";
      }
      my $mysize = 0;
      if(/ kb (\d+) /){
	$mysize = $1;
      } elsif(/ bytes (\d+) /){
	$mysize = int($1/1024);
      }
      if ( $fail{$host}{$disk} ) {
	my @line = ($filenum, $host, $disk, $date, $level, "FAIL", $chunk);
	push @{$lines{$label}}, \@line;
      } else {
	if (defined($flash_mode)) {
	  my @line = ($filenum, $host, $disk, $date, $level, "$mysize", $chunk);
	  push @{$lines{$label}}, \@line;
	} else {
	  if (defined($osize{$host}{$disk}) && !/^CHUNK/ && !/^PART/) {
	    my @line = ($filenum, $host, $disk, $date, $level, "$osize{$host}{$disk}", $chunk);
	    push @{$lines{$label}}, \@line;
	  } else {
	    $note = "";
	    if(!/^CHUNK/ && !/^PART/){
		# this case should never happend: 
	    } else {
	      $note = "*";
	    }
	    my @line = ($filenum, $host, $disk, $date, $level, "$note$mysize", $chunk);
	    push @{$lines{$label}}, \@line;
	  }
	}
      }
      last switch;};
    /INFO taper retrying/ && do {
      --$filenumber;
      last switch; };
    /INFO taper tape (\S+) .* \[OK\]/ && do {
      $label = $1;
      $line =~ / kb (\d+) /;
      $size = $1;
      $line =~ / fm (\d+) /;
      my @line = ($1, "total", "on_tape", "-", "-", "$size", "-");
      push @{$lines{$label}}, \@line;
      last switch; };
    /FAIL taper/ && do { next; };
  }
  $filenumber += 1;
}
close $IF;

foreach my $label (sort keys %lines) {
    $tocfilename=&tfn($label) if ($#subs >= 0);
    if (!$tocfilename || ($tocfilename eq '-')) {$OF=*STDOUT;}
    else {
        die ("Cannot open tocfile $tocfilename") unless open($OF,">$tocfilename");
    }
    my $ofh = select($OF);
    $~ = "OF";
    select($ofh);

    print $OF "\f" if $vwspace;
    pr("#","Server","/partition","date", "level","size[Kb]","part");
    pr("0","$label","","$dates{$label}","-","-","-");
    foreach my $line (@{$lines{$label}}) {
	&pr(@{$line});
    }

    print "\n\n" if ($vwspace);
    if ($tocfilename && $tocfilename ne '-') {
        close $OF;
    }
}
#if (defined($flash_mode)) {
#    pr("-","total","origin","-","not","available","-");
#} else {
#    pr("-","total","origin","-","-","$tot_or_size","-");
#}


format OF =
@>>  @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<< @>> @>>>>>>>>
$fnbr,$hstprt,$dt,$lvl,$sz
.

format STDOUT =
@>>  @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<< @>> @>>>>>>>> @>>>
$fnbr,$hstprt,$dt,$lvl,$sz,$ch
.