5 eval '(exit $?0)' && eval 'exec @PERL@ -S $0 ${1+"$@"}'
6 & eval 'exec @PERL@ -S $0 $argv:q'
9 require "newgetopt.pl";
11 use lib '@amperldir@';
17 delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV', 'PATH'};
18 $ENV{'PATH'} = "/bin:/usr/bin:/usr/sbin:/sbin"; # force known path
20 $confdir="@CONFIG_DIR@";
22 $prefix=$prefix; # avoid warnings about possible typo
23 $exec_prefix="@exec_prefix@";
24 $exec_prefix=$exec_prefix; # ditto
27 my $Amanda_process = Amanda::Process->new(0);
28 $Amanda_process->load_ps_table();
36 $result = &NGetOpt ( "summary",
39 "waitdumping|wdumping",
46 "gestimate|gettingestimate",
50 "locale-independent-date-format",
56 if( defined $opt_config ) {
68 #untaint user input $ARGV[0]
70 if ($conf =~ /^([\w.-]+)$/) { # $1 is untainted
73 die "filename '$conf' has invalid characters.\n";
76 if ( ! -e "$confdir/$conf" ) {
77 print "Configuration directory '$confdir/$conf' doesn't exist\n";
80 if ( ! -d "$confdir/$conf" ) {
81 print "Configuration directory '$confdir/$conf' is not a directory\n";
88 chdir "$confdir/$conf";
90 $logdir=`$sbindir/amgetconf logdir`;
93 $errfile="$logdir/amdump";
95 $nb_options = defined( $opt_summary ) +
96 defined( $opt_stats ) +
97 defined( $opt_dumping ) +
98 defined( $opt_waitdumping ) +
99 defined( $opt_waittaper ) +
100 defined( $opt_dumpingtape ) +
101 defined( $opt_writingtape ) +
102 defined( $opt_finished ) +
103 defined( $opt_estimate ) +
104 defined( $opt_gestimate ) +
105 defined( $opt_failed );
107 if($nb_options == 0 ) {
111 $opt_waitdumping = 1;
113 $opt_dumpingtape = 1;
114 $opt_writingtape = 1;
121 $unit=`$sbindir/amgetconf displayunit`;
123 $unit =~ tr/A-Z/a-z/;
128 elsif($unit eq 'm') {
131 elsif($unit eq 'g') {
132 $unitdivisor = 1024*1024;
134 elsif($unit eq 't') {
135 $unitdivisor = 1024*1024*1024;
144 if( defined $opt_file) {
145 if( $opt_file =~ m,^/, ) {
146 $errfile = $opt_file;
148 $errfile = "$pwd/$opt_file";
149 $errfile = "$logdir/$opt_file" if ( ! (-f $errfile ));
153 $errfile="$logdir/amflush" if(! (-f $errfile));
155 if (-f "$logdir/amflush.1" && -f "$logdir/amdump.1" &&
156 -M "$logdir/amflush.1" < -M "$logdir/amdump.1") {
157 $errfile="$logdir/amflush.1";
159 $errfile="$logdir/amdump.1";
165 open(AMDUMP,"<$errfile") || die("$errfile: $!");
166 print "Using $errfile\n";
168 my $taper_status_file;
170 $start_degraded_mode = 0;
172 $label = ""; # -w fodder
173 $origsize = 0; # -w fodder
176 $status_taper = "Searching for a new tape";
180 @dumpers_active = ();
182 $ntpartition{$nb_tape} = 0;
183 $ntsize{$nb_tape} = 0;
184 $ntesize{$nb_tape} = 0;
186 $driver_finished = 0;
187 $generating_schedule = 0;
189 while($lineX = <AMDUMP>) {
191 $lineX =~ s/[:\s]+$//g; #remove separator at end of line
192 next if $lineX eq "";
193 @line = "ewords('[:\s]+', 0, $lineX);
194 next if !defined $line[0];
196 if($line[0] eq "amdump" || $line[0] eq "amflush") {
197 if ($line[1] eq "start" && $line[2] eq "at") {
199 $datestr =~ s/.*start at //g;
200 if (!defined $opt_locale_independent_date_format) {
201 print "From " . $datestr . "\n";
203 } elsif($line[1] eq "datestamp") {
204 $gdatestamp = $line[2];
205 if(!defined $datestamp{$gdatestamp}) {
206 $datestamp{$gdatestamp} = 1;
207 push @datestamp, $gdatestamp;
209 } elsif($line[1] eq "starttime") {
210 $starttime=&set_starttime($line[2]);
211 } elsif($line[1] eq "starttime-locale-independent") {
212 if (defined $opt_locale_independent_date_format) {
213 printf "From " . $line[2] . " " . $line[3] . ":" . $line[4] . ":" . $line[5] . " " . $line[6] . "\n";
216 if($line[0] eq "amflush") {
219 } elsif($line[0] eq "planner") {
220 if($line[1] eq "timestamp") {
221 $gdatestamp = $line[2];
222 if(!defined $datestamp{$gdatestamp}) {
223 $datestamp{$gdatestamp} = 1;
224 push @datestamp, $gdatestamp;
227 elsif($line[1] eq "FAILED") {
228 #2:host 3:disk 4:datestamp 5:level 6:errmsg
232 $hostpart=&make_hostpart($host,$partition,$datestamp);
233 $dump_started{$hostpart}=-1;
234 $level{$hostpart}=$line[5];
235 $error{$hostpart}="planner: " . $line[6];
236 } elsif($line[1] eq "time") {
237 if($line[3] eq "got") {
238 if($line[4] eq "result") {
240 $partition = $line[9];
241 $hostpart=&make_hostpart($host,$partition,$gdatestamp);
242 $estimate{$hostpart}=1;
243 $level{$hostpart}=$line[10];
244 $line[12] =~ /(\d+)K/;
245 $esize{$hostpart}=$1 / $unitdivisor;
246 $partialestimate{$hostpart}=0;
247 $getest{$hostpart} = "";
248 } elsif($line[4] eq "partial") {
250 $partition = $line[10];
251 $hostpart=&make_hostpart($host,$partition,$gdatestamp);
253 $line[13] =~ /(-?\d+)K/;
256 $line[16] =~ /(-?\d+)K/;
259 $line[19] =~ /(-?\d+)K/;
261 if($size1 > 0 || $size2 > 0 || $size3 > 0) {
262 $estimate{$hostpart}=1;
263 $level{$hostpart}=$line[11];
264 $esize{$hostpart}=$size1 / $unitdivisor;
265 $partialestimate{$hostpart}=1;
266 if($size1 > 0) { $getest{$hostpart} =~ s/:$level1://; }
267 if($size2 > 0) { $getest{$hostpart} =~ s/:$level2://; }
268 if($size3 > 0) { $getest{$hostpart} =~ s/:$level3://; }
269 if($getest{$hostpart} eq "") {$partialestimate{$hostpart}=0;}
272 } elsif($line[3] eq "getting" &&
273 $line[4] eq "estimates" &&
274 $line[5] eq "took") {
278 } elsif($line[0] eq "setup_estimate") {
280 $partition = $line[2];
281 $hostpart=&make_hostpart($host,$partition,$gdatestamp);
282 $estimate{$hostpart}=0;
284 $degr_level{$hostpart}=-1;
286 $dump_started{$hostpart}=0;
287 $dump_finished{$hostpart}=0;
288 $taper_started{$hostpart}=0;
289 $taper_finished{$hostpart}=0;
290 $partialestimate{$hostpart}=0;
291 $error{$hostpart}="";
292 if($line[7] eq "last_level") {
293 $getest{$hostpart}="";
297 if($level1 != -1) { $getest{$hostpart} .= ":$level1:" };
298 if($level2 != -1) { $getest{$hostpart} .= ":$level2:" };
299 if($level3 != -1) { $getest{$hostpart} .= ":$level3:" };
301 } elsif($line[0] eq "GENERATING" &&
302 $line[1] eq "SCHEDULE") {
303 $generating_schedule=1;
304 } elsif($line[0] eq "--------") {
305 if ($generating_schedule == 1) {
306 $generating_schedule = 2;
307 } elsif ($generating_schedule == 2) {
308 $generating_schedule = 3;
310 } elsif($line[0] eq "DUMP") {
311 if($generating_schedule == 2 ) {
313 $partition = $line[3];
314 $datestamp = $line[4];
315 $hostpart=&make_hostpart($host,$partition,$datestamp);
316 $level{$hostpart}=$line[6];
317 $esize=$line[14]; #compressed size
318 $esize=32 if $esize<32;
319 $esize{$hostpart}=$esize / $unitdivisor;
320 if(!defined($line[25])) {
321 $degr_level{$hostpart}=-1;
323 $degr_level{$hostpart}=$line[17];
324 $esize=$line[25]; #compressed size
325 $esize=32 if $esize<32;
326 $degr_size{$hostpart}=$esize / $unitdivisor;
329 } elsif($line[0] eq "FLUSH") {
331 $partition = $line[2];
332 $datestamp = $line[3];
334 $holding_file = $line[5];
335 $hostpart=&make_hostpart($host,$partition,$datestamp);
337 $dump_finished{$hostpart}=0;
338 $holding_file{$hostpart}=$holding_file;
339 $level{$hostpart}=$level;
340 } elsif($line[0] eq "driver") {
341 if($line[1] eq "pid") {
343 if (! $Amanda_process->process_alive($pid, "driver")) {
347 elsif($line[1] eq "start" && $line[2] eq "time") {
348 $start_time=$line[3];
349 $current_time=$line[3];
350 $dumpers_active[0]=0;
354 elsif($line[1] eq "tape" && $line[2] eq "size") {
355 $lineX =~ /^driver: start time (\S+)/;
356 $tape_size = $line[3] / $unitdivisor;
358 elsif($line[1] eq "adding" &&
359 $line[2] eq "holding" &&
360 $line[3] eq "disk") {
361 $holding_space += $line[8];
363 elsif($line[1] eq "send-cmd" && $line[2] eq "time") {
364 #print "send-cmd: " , $line[5] . " " . $line[6] . " " . $line[7] . "\n" if defined $line[5] && defined $line[6] && defined $line[7];
365 $current_time = $line[3];
366 if($line[5] =~ /dumper\d*/) {
368 if($line[6] eq "PORT-DUMP") {
369 #7:handle 8:port 9:host 10:amfeatures 11:disk 12:device 13:level ...
371 $partition = $line[11];
372 $hostpart=&make_hostpart($host,$partition,$gdatestamp);
374 $dump_started{$hostpart}=1;
375 $dump_time{$hostpart}=$current_time;
376 $dump_finished{$hostpart}=0;
377 if( $level{$hostpart} != $line[13] &&
378 $degr_level{$hostpart} == $line[13]) {
379 $level{$hostpart}=$degr_level{$hostpart};
380 $esize{$hostpart}=$degr_size{$hostpart};
382 if(! defined($busy_time{$dumper})) {
383 $busy_time{$dumper}=0;
385 $running_dumper{$dumper} = $hostpart;
386 $error{$hostpart}="";
387 $size{$hostpart} = 0;
389 if(! defined($dumpers_active[$dumpers_active])) {
390 $dumpers_active[$dumpers_active]=0;
392 if(! defined($dumpers_held[$dumpers_active])) {
393 $dumpers_held[$dumpers_active]={};
397 elsif($line[5] =~ /chunker\d*/) {
398 if($line[6] eq "PORT-WRITE") {
400 $partition=$line[11];
401 $hostpart=&make_hostpart($host,$partition,$gdatestamp);
403 $serial{$serial}=$hostpart;
404 $holding_file{$hostpart}=$line[8];
405 #$chunk_started{$hostpart}=1;
406 $chunk_time{$hostpart}=$current_time;
407 #$chunk_finished{$hostpart}=0;
408 $size{$hostpart} = 0;
410 elsif($line[6] eq "CONTINUE") {
411 #7:handle 8:filename 9:chunksize 10:use
413 $hostpart=$serial{$serial};
414 if($hostpart ne "") {
415 $dump_roomq{$hostpart}=undef;
416 $error{$hostpart}="";
420 elsif($line[5] =~ /taper/) {
421 if($line[6] eq "START-TAPER") {
423 $gdatestamp=$line[8];
424 if(!defined $datestamp{$gdatestamp}) {
425 $datestamp{$gdatestamp} = 1;
426 push @datestamp, $gdatestamp;
428 $status_taper = "Searching for a new tape";
430 elsif($line[6] eq "NEW-TAPE") {
432 $status_taper = "Searching for a new tape";
434 elsif($line[6] eq "NO-NEW-TAPE") {
435 #7:name 8:handle 9:errmsg
438 $status_taper = $error;
440 elsif($line[6] eq "FILE-WRITE") {
441 #7:name 8:handle 9:filename 10:host 11:disk 12:level 13:datestamp 14:splitsize
444 $partition=$line[11];
446 $ldatestamp=$line[13];
447 $status_taper = "Writing $host:$partition";
448 if(!defined $datestamp{$ldatestamp}) {
449 $datestamp{$ldatestamp} = 1;
450 push @datestamp, $ldatestamp;
452 $hostpart=&make_hostpart($host,$partition,$ldatestamp);
453 $serial{$serial}=$hostpart;
454 if(!defined $level{$hostpart}) {
455 $level{$hostpart} = $level;
457 $taper_started{$hostpart}=1;
458 $taper_finished{$hostpart}=0;
459 $taper_time{$hostpart}=$current_time;
462 elsif($line[6] eq "PORT-WRITE") {
463 #7:name 8:handle 9:host 10:disk 11:level 12:datestamp 13:splitsize 14:diskbuffer 15:fallback_splitsize
466 $partition=$line[10];
468 $ldatestamp=$line[12];
469 $status_taper = "Writing $host:$partition";
470 $hostpart=&make_hostpart($host,$partition,$ldatestamp);
471 $serial{$serial}=$hostpart;
472 $taper_started{$hostpart}=1;
473 $taper_finished{$hostpart}=0;
474 $taper_time{$hostpart}=$current_time;
475 $size{$hostpart} = 0;
480 elsif($line[1] eq "result" && $line[2] eq "time") {
481 #print "result: " , $line[5] . " " . $line[6] . " " . $line[7] . "\n" if defined $line[5] && defined $line[6] && defined $line[7];
482 $current_time = $line[3];
483 if($line[5] =~ /dumper\d+/) {
484 if($line[6] eq "FAILED" || $line[6] eq "TRY-AGAIN") {
488 $hostpart=$serial{$serial};
489 if ($taper_started{$hostpart} == 1) {
490 $dump_finished{$hostpart}=-1;
492 $dump_finished{$hostpart}=-3;
494 $busy_time{$line[5]}+=($current_time-$dump_time{$hostpart});
495 $running_dumper{$line[5]} = "0";
496 $dump_time{$hostpart}=$current_time;
497 $error{$hostpart}="dumper: $error";
501 elsif($line[6] eq "DONE") {
502 #7:handle 8:origsize 9:size ...
504 $origsize=$line[8] / $unitdivisor;
505 $outputsize=$line[9] / $unitdivisor;
506 $hostpart=$serial{$serial};
507 $size{$hostpart}=$outputsize;
508 $dump_finished{$hostpart}=1;
509 $busy_time{$line[5]}+=($current_time-$dump_time{$hostpart});
510 $running_dumper{$line[5]} = "0";
511 $dump_time{$hostpart}=$current_time;
512 $error{$hostpart}="";
515 elsif($line[6] eq "ABORT-FINISHED") {
518 $hostpart=$serial{$serial};
519 $dump_started{$hostpart}=0;
520 if ($taper_started{$hostpart} == 1) {
521 $dump_finished{$hostpart}=-1;
523 $dump_finished{$hostpart}=-3;
525 $busy_time{$line[5]}+=($current_time-$dump_time{$hostpart});
526 $running_dumper{$line[5]} = "0";
527 $dump_time{$hostpart}=$current_time;
528 $error{$hostpart}="dumper: (aborted)";
532 elsif($line[5] =~ /chunker\d+/) {
533 if($line[6] eq "DONE" || $line[6] eq "PARTIAL") {
536 $outputsize=$line[8] / $unitdivisor;
537 $hostpart=$serial{$serial};
538 $size{$hostpart}=$outputsize;
539 if ($line[6] eq "DONE") {
540 $dump_finished{$hostpart}=1;
542 $dump_finished{$hostpart}=-3;
544 $busy_time{$line[5]}+=($current_time-$chunk_time{$hostpart});
545 $running_dumper{$line[5]} = "0";
546 $chunk_time{$hostpart}=$current_time;
547 if ($line[6] eq "PARTIAL") {
548 $partial{$hostpart} = 1;
551 $partial{$hostpart} = 0;
552 $error{$hostpart}="";
555 elsif($line[6] eq "FAILED") {
557 $hostpart=$serial{$serial};
558 $dump_finished{$hostpart}=-1;
559 $busy_time{$line[5]}+=($current_time-$chunk_time{$hostpart});
560 $running_dumper{$line[5]} = "0";
561 $chunk_time{$hostpart}=$current_time;
562 $error{$hostpart}="chunker: " .$line[8] if $error{$hostpart} eq "";
564 elsif($line[6] eq "RQ-MORE-DISK") {
567 $hostpart=$serial{$serial};
568 $dump_roomq{$hostpart}=1;
569 $error{$hostpart}="(waiting for holding disk space)";
572 elsif($line[5] eq "taper") {
573 if($line[6] eq "DONE" || $line[6] eq "PARTIAL") {
574 #7:handle 8:label 9:filenum 10:errstr
577 $status_taper = "Idle";
578 $hostpart=$serial{$serial};
579 $line[10] =~ /sec (\S+) kb (\d+) kps/;
580 $size=$2 / $unitdivisor;
581 $taper_finished{$hostpart}=1;
582 $busy_time{"taper"}+=($current_time-$taper_time{$hostpart});
583 $taper_time{$hostpart}=$current_time;
584 if(!defined $size{$hostpart}) {
585 $size{$hostpart}=$size;
587 $ntpartition{$nb_tape}++;
588 $ntsize{$nb_tape} += $size{$hostpart} - $ntchunk_size;
589 if(defined $esize{$hostpart} && $esize{$hostpart} > 1) {
590 $ntesize{$nb_tape} += $esize{$hostpart} - $ntchunk_size;
593 $ntesize{$nb_tape} += $size{$hostpart} - $ntchunk_size;
595 if ($line[6] eq "PARTIAL") {
596 $partial{$hostpart} = 1;
599 $partial{$hostpart} = 0;
601 if ($ntchunk_size > 0) {
602 $ntchunk{$nb_tape}++;
604 undef $taper_status_file;
606 elsif($line[6] eq "PARTDONE") {
607 #7:handle 8:label 9:filenum 10:ksize 11:errstr
609 $hostpart=$serial{$serial};
610 #$line[11] =~ /.*kb (\d*) kps/;
611 #$size=$1 / $unitdivisor;
612 $size=$line[10] / $unitdivisor;
613 $tapedsize{$hostpart} += $size;
614 $ntchunk{$nb_tape}++;
615 $ntsize{$nb_tape} += $size;
616 $ntesize{$nb_tape} += $size;
617 $ntchunk_size += $size;
619 elsif($line[6] eq "REQUEST-NEW-TAPE") {
622 $old_status_taper = $status_taper;
623 $status_taper = "Asking for a new tape";
624 $hostpart=$serial{$serial};
625 if (defined $hostpart) {
626 $olderror{$hostpart} = $error{$hostpart};
627 $error{$hostpart} = "waiting for a new tape";
630 elsif($line[6] eq "NEW-TAPE") {
633 $status_taper = $old_status_taper;
634 $hostpart=$serial{$serial};
635 if (defined $hostpart) {
636 $error{$hostpart} = $olderror{$hostpart};
639 elsif($line[6] eq "TAPER-OK") {
641 $status_taper = "Idle";
643 elsif($line[6] eq "TAPE-ERROR") {
646 $status_taper = $error;
647 $exit_status |= $STATUS_TAPE;
648 undef $taper_status_file;
650 elsif($line[6] eq "FAILED") {
651 #7:handle 8:INPUT- 9:TAPE- 10:input_message 11:tape_message
653 $hostpart=$serial{$serial};
654 if(defined $hostpart) {
655 if($line[9] eq "TAPE-ERROR") {
657 $taper_finished{$hostpart} = -2;
658 $status_taper = $error;
662 $taper_finished{$hostpart} = -1;
663 $status_taper = "Idle";
665 $busy_time{"taper"}+=($current_time-$taper_time{$hostpart});
666 $taper_time{$hostpart}=$current_time;
667 $error{$hostpart}="$error";
669 undef $taper_status_file;
673 elsif($line[1] eq "finished-cmd" && $line[2] eq "time") {
674 $current_time=$line[3];
675 if($line[4] =~ /dumper\d+/) {
678 elsif($line[1] eq "dump" && $line[2] eq "failed") {
679 #3:handle 4: 5: 6:"too many dumper retry"
681 $hostpart=$serial{$serial};
682 $dump_started{$hostpart}=-1;
683 $dump_finished{$hostpart}=-2;
684 $error{$hostpart} .= "(" . $line[6] . ")";
686 elsif($line[1] eq "tape" && $line[2] eq "failed") {
687 #3:handle 4: 5: 6:"too many dumper retry"
689 $hostpart=$serial{$serial};
690 $taper_started{$hostpart}=-1;
691 $taper_finished{$hostpart}=-2;
692 $error{$hostpart} .= "(" . $line[6] . ")";
694 elsif($line[1] eq "state" && $line[2] eq "time") {
695 #3:time 4:"free" 5:"kps" 6:free 7:"space" 8:space 9:"taper" 10:taper 11:"idle-dumpers" 12:idle-dumpers 13:"qlen" 14:"tapeq" 15:tapeq 16:"runq" 17:runq 18:"roomq" 19:roomq 20:"wakeup" 21:wakeup 22:"driver-idle" 23:driver-idle
696 $current_time=$line[3];
697 $idle_dumpers=$line[12];
699 $free{"kps"} = $line[6];
700 $free{"space"} = $line[8];
701 $qlen{"tapeq"} = $line[15];
702 $qlen{"runq"} = $line[17];
703 $qlen{"roomq"} = $line[19];
705 if(defined($dumpers_active)) {
706 if($status_driver ne "") {
707 $dumpers_active[$dumpers_active_prev]
708 +=$current_time-$state_time_prev;
709 $dumpers_held[$dumpers_active_prev]{$status_driver}
710 +=$current_time-$state_time_prev;
712 $state_time_prev=$current_time;
713 $dumpers_active_prev=$dumpers_active;
714 $status_driver=$line[23];
715 if(! defined($dumpers_held[$dumpers_active]{$status_driver})) {
716 $dumpers_held[$dumpers_active]{$status_driver}=0;
720 elsif($line[1] eq "FINISHED") {
721 $driver_finished = 1;
724 elsif($line[0] eq "dump") {
725 if($line[1] eq "of" &&
726 $line[2] eq "driver" &&
727 $line[3] eq "schedule" &&
728 $line[4] eq "after" &&
729 $line[5] eq "start" &&
730 $line[6] eq "degraded" &&
731 $line[7] eq "mode") {
732 $start_degraded_mode=1;
735 elsif($line[0] eq "taper") {
736 if($line[1] eq "wrote") {
737 #1:"wrote" 2:"label" 3:label
740 $ntlabel{$nb_tape} = $label;
741 $ntpartition{$nb_tape} = 0;
742 $ntsize{$nb_tape} = 0;
743 $ntesize{$nb_tape} = 0;
745 elsif($line[1] eq "status" && $line[2] eq "file") {
746 #1:"status" #2:"file:" #3:hostname #4:diskname #5:filename
747 $taper_status_file = $line[5];
750 elsif($line[0] eq "splitting" &&
751 $line[1] eq "chunk" &&
752 $line[2] eq "that" &&
753 $line[3] eq "started" &&
755 $line[6] eq "after") {
756 $line[7] =~ /(\d*)kb/;
758 $ntchunk{$nb_tape}++;
759 $ntsize{$nb_tape} += $size / $unitdivisor;
760 $ntesize{$nb_tape} += $size / $unitdivisor;
761 $ntchunk_size += $size / $unitdivisor;
764 #print "Ignoring: $lineX\n";
770 if(defined $current_time) {
771 for ($d = 0; $d < $#dumpers_active; $d++) {
772 $the_dumper = "dumper$d";
773 if(defined($running_dumper{$the_dumper}) &&
774 $running_dumper{$the_dumper} ne "0") {
775 $busy_time{$the_dumper}+=($current_time-$dump_time{$running_dumper{$the_dumper}});
819 foreach $host (sort @hosts) {
820 foreach $partition (sort @$host) {
821 foreach $datestamp (sort @datestamp) {
822 $hostpart=&make_hostpart($host,$partition,$datestamp);
823 next if(!defined $estimate{$hostpart} && !defined $flush{$hostpart});
824 if(length("$host:$partition") > $maxnamelength) {
825 $maxnamelength = length("$host:$partition");
831 foreach $host (sort @hosts) {
832 foreach $partition (sort @$host) {
833 $qpartition = Amanda::Util::quote_string($partition);
834 foreach $datestamp (sort @datestamp) {
835 $hostpart=&make_hostpart($host,$partition,$datestamp);
836 next if(!defined $estimate{$hostpart} && !defined $flush{$hostpart});
838 if( (!defined $size{$hostpart} || $size{$hostpart} == 0) &&
839 defined $holding_file{$hostpart}) {
840 $size{$hostpart} = &dump_size($holding_file{$hostpart}) / (1024 * $unitdivisor);
843 if($estimate_done != 1 && !defined $flush{$hostpart}) {
844 if(defined $estimate{$hostpart}) {
845 if($estimate{$hostpart} != 1) {
846 if( defined $opt_gestimate ||
847 defined $opt_failed && $dead_run != 0) {
848 printf "%8s ", $datestamp if defined $opt_date;
849 printf "%-${maxnamelength}s", "$host:$qpartition";
852 print " failed: killed while";
853 $exit_status |= $STATUS_FAILED;
855 print " getting estimate\n";
859 if(defined $opt_estimate ||
860 (defined $opt_gestimate && $partialestimate{$hostpart} == 1) ||
861 (defined $opt_failed && $dead_run != 0 && $partialestimate{$hostpart} == 1)) {
862 printf "%8s ", $datestamp if defined $opt_date;
863 printf "%-${maxnamelength}s", "$host:$qpartition";
864 printf "%2d ", $level{$hostpart};
865 printf "%9d$unit", $esize{$hostpart};
866 if($partialestimate{$hostpart} == 1) {
868 print " failed: killed while";
869 $exit_status |= $STATUS_FAILED;
873 print " estimate done\n";
876 $estsize += $esize{$hostpart};
881 if(defined $estimate{$hostpart}) {
882 if($estimate{$hostpart} == 1) {
884 $estsize += $esize{$hostpart};
886 elsif (!defined $dump_started{$hostpart} || $dump_started{$hostpart} == 0) {
887 if( defined $opt_failed) {
888 printf "%8s ", $datestamp if defined $opt_date;
889 printf "%-${maxnamelength}s%2d ", "$host:$qpartition", $level{$hostpart};
890 printf " no estimate\n";
892 $exit_status |= $STATUS_FAILED;
894 $fsize+=$esize{$hostpart};
899 $flsize += $size{$hostpart};
902 if(defined $taper_started{$hostpart} &&
903 $taper_started{$hostpart}==1 &&
904 $dump_finished{$hostpart}!=-3) {
905 if(defined $dump_started{$hostpart} &&
906 $dump_started{$hostpart} == 1 &&
907 $dump_finished{$hostpart} == -1) {
908 if(defined $opt_failed) {
909 printf "%8s ", $datestamp if defined $opt_date;
910 printf "%-${maxnamelength}s%2d ", "$host:$qpartition", $level{$hostpart};
911 printf "%9d$unit", $esize{$hostpart};
912 print " dump to tape failed: " . $error{$hostpart};
915 $exit_status |= $STATUS_FAILED;
917 $fsize+=$esize{$hostpart};
918 } elsif(defined $dump_started{$hostpart} &&
919 $dump_started{$hostpart} == 1 &&
920 $dump_finished{$hostpart} == 0 &&
921 $taper_started{$hostpart} == 1) {
922 if( defined $opt_dumpingtape ||
923 defined $opt_failed && $dead_run != 0) {
924 printf "%8s ", $datestamp if defined $opt_date;
925 printf "%-${maxnamelength}s%2d ", "$host:$qpartition", $level{$hostpart};
926 printf "%9d$unit", $esize{$hostpart};
928 print " failed: killed while";
929 $exit_status |= $STATUS_FAILED;
931 print " dumping to tape";
932 $size = $tapedsize{$hostpart};
933 if ($taper_status_file && -f $taper_status_file &&
934 open FF, "<$taper_status_file") {
938 $value = $line / ($unitdivisor * 1024);
940 $size = $value if (!defined($size) || $value > $size);
946 printf " (%d$unit done (%0.2f%%))", $size, 100.0 * $size/$esize{$hostpart};
949 if( defined $starttime ) {
950 print " (", &showtime($taper_time{$hostpart}), ")";
955 $dtesize += $esize{$hostpart};
957 elsif($taper_finished{$hostpart} == 0) {
958 if( defined $opt_writingtape ||
959 defined $opt_failed && $dead_run != 0) {
960 printf "%8s ", $datestamp if defined $opt_date;
961 printf "%-${maxnamelength}s%2d ", "$host:$qpartition", $level{$hostpart};
962 printf "%9d$unit", $size{$hostpart};
964 print " failed: killed while";
965 $exit_status |= $STATUS_FAILED;
968 print " writing to tape";
971 print " flushing to tape";
973 $size = $tapedsize{$hostpart};
974 if ($taper_status_file && -f $taper_status_file &&
975 open FF, "<$taper_status_file") {
979 $value = $line / ($unitdivisor * 1024);
981 $size = $value if (!defined($size) || $value > $size);
987 printf " (%d$unit done (%0.2f%%))", $size, 100.0 * $size/$size{$hostpart};
989 if( defined $starttime ) {
990 print " (", &showtime($taper_time{$hostpart}), ")";
992 print ", ", $error{$hostpart} if (defined($error{$hostpart}) &&
993 $error{$hostpart} ne "");
997 $tasize += $size{$hostpart};
998 if(defined $esize{$hostpart}) {
999 $taesize += $esize{$hostpart};
1002 $taesize += $size{$hostpart};
1004 if (defined $dump_finished{$hostpart} && $dump_finished{$hostpart} == 1) {
1006 $dsize += $size{$hostpart};
1007 if(defined $esize{$hostpart} && $esize{$hostpart} > 1) {
1008 $desize += $esize{$hostpart};
1010 $desize += $size{$hostpart};
1014 elsif($taper_finished{$hostpart} < 0) {
1016 if(defined $size{$hostpart}) {
1017 $xsize = $size{$hostpart};
1019 elsif(defined $esize{$hostpart}) {
1020 $xsize = $esize{$hostpart};
1026 if(defined $esize{$hostpart}) {
1027 $exsize += $esize{$hostpart};
1033 if( defined $opt_failed ||
1034 (defined $opt_waittaper && ($taper_finished{$hostpart} == -1))) {
1035 printf "%8s ", $datestamp if defined $opt_date;
1036 printf "%-${maxnamelength}s%2d ", "$host:$qpartition", $level{$hostpart};
1037 printf "%9d$unit", $xsize;
1038 if($in_flush == 0) {
1039 print " failed to tape";
1042 print " failed to flush";
1044 print ": ",$error{$hostpart} if defined $error{$hostpart};
1046 print " (will retry)" unless $taper_finished{$hostpart} < -1;
1047 if( defined $starttime ) {
1048 print " (", &showtime($taper_time{$hostpart}), ")";
1052 $exit_status |= $STATUS_TAPE;
1056 $tfesize += $exsize;
1058 if($in_flush == 0) {
1061 $twesize += $exsize;
1067 if (defined $dump_finished{$hostpart} && $dump_finished{$hostpart} == 1) {
1069 $dsize += $size{$hostpart};
1070 if(defined $esize{$hostpart} && $esize{$hostpart} > 1) {
1071 $desize += $esize{$hostpart};
1073 $desize += $size{$hostpart};
1077 elsif($taper_finished{$hostpart} == 1) {
1078 if( defined $opt_finished ) {
1079 printf "%8s ", $datestamp if defined $opt_date;
1080 printf "%-${maxnamelength}s%2d ", "$host:$qpartition", $level{$hostpart};
1081 printf "%9d$unit", $size{$hostpart};
1082 if($in_flush == 0) {
1088 if( defined $starttime ) {
1089 print " (", &showtime($taper_time{$hostpart}), ")";
1091 if(defined $partial{$hostpart} && $partial{$hostpart} == 1) {
1093 $exit_status |= $STATUS_FAILED;
1097 if (defined $dump_finished{$hostpart} && $dump_finished{$hostpart} == 1) {
1099 $dsize += $size{$hostpart};
1100 if(defined $esize{$hostpart} && $esize{$hostpart} > 1) {
1101 $desize += $esize{$hostpart};
1103 $desize += $size{$hostpart};
1107 $tsize += $size{$hostpart};
1108 if(defined $esize{$hostpart} && $esize{$hostpart} > 1) {
1109 $tesize += $esize{$hostpart};
1112 $tesize += $size{$hostpart};
1116 printf "%8s ", $datestamp if defined $opt_date;
1117 printf "%-${maxnamelength}s%2d ", "$host:$qpartition", $level{$hostpart};
1118 print " unknown state TAPER\n";
1121 elsif(defined $dump_started{$hostpart}) {
1122 if($dump_started{$hostpart} == -1) {
1123 if( defined $opt_failed ) {
1124 printf "%8s ", $datestamp if defined $opt_date;
1125 printf "%-${maxnamelength}s%2d ", "$host:$qpartition", $level{$hostpart};
1126 printf "failed: " . $error{$hostpart} . "\n";
1128 $exit_status |= $STATUS_FAILED;
1131 $fsize+=$esize{$hostpart};
1133 elsif($dump_started{$hostpart} == 0) {
1134 if($estimate{$hostpart} == 1) {
1135 if( defined $opt_waitdumping ) {
1136 printf "%8s ", $datestamp if defined $opt_date;
1137 printf "%-${maxnamelength}s%2d ", "$host:$qpartition", $level{$hostpart};
1138 printf "%9d$unit", $esize{$hostpart};
1140 print " failed: process terminated while";
1141 $exit_status |= $STATUS_FAILED;
1143 print " waiting for dumping $error{$hostpart}\n";
1145 if($driver_finished == 1) {
1146 $exit_status |= $STATUS_MISSING;
1149 $wsize += $esize{$hostpart};
1152 elsif($dump_started{$hostpart} == 1 &&
1153 ($dump_finished{$hostpart} == -1 ||
1154 $dump_finished{$hostpart} == -3)) {
1155 if( defined $opt_failed ) {
1156 printf "%8s ", $datestamp if defined $opt_date;
1157 printf "%-${maxnamelength}s%2d ", "$host:$qpartition", $level{$hostpart};
1158 print "backup failed: ", $error{$hostpart};
1159 if( defined $starttime ) {
1160 print " (", &showtime($dump_time{$hostpart}), ")";
1164 $exit_status |= $STATUS_FAILED;
1166 $fsize+=$esize{$hostpart};
1168 elsif($dump_started{$hostpart} == 1 &&
1169 $dump_finished{$hostpart} == 0) {
1170 if( defined $opt_dumping ||
1171 defined $opt_failed && $dead_run != 0) {
1172 printf "%8s ", $datestamp if defined $opt_date;
1173 printf "%-${maxnamelength}s%2d ", "$host:$qpartition", $level{$hostpart};
1174 printf "%9d$unit", $esize{$hostpart};
1176 print " failed: killed while";
1177 $exit_status |= $STATUS_FAILED;
1179 printf " dumping %8d$unit", $size{$hostpart};
1180 if($size{$hostpart} != 0) {
1181 printf " (%6.2f%%)", (100.0*$size{$hostpart})/$esize{$hostpart};
1183 if( defined $starttime ) {
1184 print " (", &showtime($dump_time{$hostpart}), ")";
1186 if(defined $dump_roomq{$hostpart}) {
1187 print " " . $error{$hostpart};
1192 $dusize += $size{$hostpart};
1193 $duesize += $esize{$hostpart};
1195 elsif($dump_finished{$hostpart} == 1 &&
1196 $taper_started{$hostpart} != 1) {
1197 if( defined $opt_waittaper ) {
1198 printf "%8s ", $datestamp if defined $opt_date;
1199 printf "%-${maxnamelength}s%2d ", "$host:$qpartition", $level{$hostpart};
1200 printf "%9d$unit", $size{$hostpart};
1202 if( defined $starttime ) {
1203 print " (", &showtime($dump_time{$hostpart}), ")";
1207 print " process terminated while";
1209 print " waiting for writing to tape";
1210 if(defined $partial{$hostpart} && $partial{$hostpart} == 1) {
1212 $exit_status |= $STATUS_FAILED;
1217 $dsize += $size{$hostpart};
1218 $desize += $esize{$hostpart};
1220 $twsize += $size{$hostpart};
1221 $twesize += $esize{$hostpart};
1224 printf "%8s ", $datestamp if defined $opt_date;
1225 printf "%-${maxnamelength}s%2d ", "$host:$qpartition", $level{$hostpart};
1226 print " unknown state DUMPER\n";
1229 elsif(defined $flush{$hostpart}) {
1230 if( defined $opt_waittaper ) {
1231 printf "%8s ", $datestamp if defined $opt_date;
1232 printf "%-${maxnamelength}s%2d ", "$host:$qpartition", $level{$hostpart};
1233 printf "%9d$unit", $size{$hostpart};
1235 print " process terminated while";
1237 print " waiting to flush";
1238 if(defined $partial{$hostpart} && $partial{$hostpart} == 1) {
1240 $exit_status |= $STATUS_FAILED;
1245 $wfsize += $size{$hostpart};
1247 elsif(defined $level{$hostpart}) {
1248 printf "%8s ", $datestamp if defined $opt_date;
1249 printf "%-${maxnamelength}s%2d ", "$host:$qpartition", $level{$hostpart};
1250 print " unknown state\n";
1257 if (defined $opt_summary) {
1259 print "SUMMARY part real estimated\n";
1260 print " size size\n";
1261 printf "partition : %3d\n", $nb_partition;
1262 printf "estimated : %3d %20d$unit\n", $epartition , $estsize;
1263 printf "flush : %3d %9d$unit\n", $flpartition, $flsize;
1264 printf "failed : %3d %20d$unit (%6.2f%%)\n",
1265 $fpartition , $fsize,
1266 $estsize ? ($fsize * 1.0 / $estsize) * 100 : 0.0;
1267 printf "wait for dumping: %3d %20d$unit (%6.2f%%)\n",
1268 $wpartition , $wsize,
1269 $estsize ? ($wsize * 1.0 / $estsize) * 100 : 0.0;
1270 if(defined($dtsize)) {
1271 printf "dumping to tape : %3d %9d$unit %9d$unit (%6.2f%%) (%6.2f%%)\n",
1272 $dtpartition, $dtsize, $dtesize,
1273 $dtsize ? ($dtsize * 1.0 / $dtesize) * 100 : 0.0,
1274 $estsize ? ($dtesize * 1.0 / $estsize) * 100 : 0.0;
1276 printf "dumping to tape : %3d %20d$unit (%6.2f%%)\n",
1277 $dtpartition, $dtesize,
1278 $estsize ? ($dtesize * 1.0 / $estsize) * 100 : 0.0;
1280 printf "dumping : %3d %9d$unit %9d$unit (%6.2f%%) (%6.2f%%)\n",
1281 $dupartition, $dusize, $duesize,
1282 $duesize ? ($dusize * 1.0 / $duesize) * 100 : 0.0,
1283 $estsize ? ($dusize * 1.0 / $estsize) * 100 : 0.0;
1284 printf "dumped : %3d %9d$unit %9d$unit (%6.2f%%) (%6.2f%%)\n",
1285 $dpartition , $dsize , $desize,
1286 $desize ? ($dsize * 1.0 / $desize) * 100 : 0.0,
1287 $estsize ? ($dsize * 1.0 / $estsize) * 100 : 0.0;
1288 printf "wait for writing: %3d %9d$unit %9d$unit (%6.2f%%) (%6.2f%%)\n",
1289 $twpartition, $twsize, $twesize,
1290 $twesize ? ($twsize * 1.0 / $twesize) * 100 : 0.0,
1291 $estsize ? ($twsize * 1.0 / $estsize) * 100 : 0.0;
1292 printf "wait to flush : %3d %9d$unit %9d$unit (%6.2f%%) (%6.2f%%)\n",
1293 $wfpartition, $wfsize, $wfsize, 100, 0;
1294 printf "writing to tape : %3d %9d$unit %9d$unit (%6.2f%%) (%6.2f%%)\n",
1295 $tapartition, $tasize, $taesize,
1296 $taesize ? ($tasize * 1.0 / $taesize) * 100 : 0.0,
1297 $estsize ? ($tasize * 1.0 / $estsize) * 100 : 0.0;
1298 printf "failed to tape : %3d %9d$unit %9d$unit (%6.2f%%) (%6.2f%%)\n",
1299 $tfpartition, $tfsize, $tfesize,
1300 $tfesize ? ($tfsize * 1.0 / $tfesize) * 100 : 0.0,
1301 $estsize ? ($tfsize * 1.0 / $estsize) * 100 : 0.0;
1302 printf "taped : %3d %9d$unit %9d$unit (%6.2f%%) (%6.2f%%)\n",
1303 $tpartition , $tsize , $tesize,
1304 $tesize ? ($tsize * 1.0 / $tesize) * 100 : 0.0,
1305 ($estsize+$flsize) ? ($tsize * 1.0 / ($estsize + $flsize)) * 100 : 0.0;
1306 if($nb_tape > 1 || $tape_size != 0) {
1307 for($i=1; $i <= $nb_tape; $i++) {
1308 if($tape_size != 0) {
1309 printf " tape %-3d : %3d %9d$unit %9d$unit (%6.2f%%) %s",
1310 $i, $ntpartition{$i}, $ntsize{$i}, $ntesize{$i}, 100*$ntsize{$i}/$tape_size, $ntlabel{$i};
1313 printf " tape %-3d : %3d %9d$unit %9d$unit %s",
1314 $i, $ntpartition{$i}, $ntsize{$i}, $ntesize{$i}, $ntlabel{$i};
1316 if(defined($ntchunk{$i}) && $ntchunk{$i} > 0) {
1317 printf " (%d chunks)", $ntchunk{$i};
1322 if($idle_dumpers == 0) {
1323 printf "all dumpers active\n";
1326 $c1 = ($idle_dumpers == 1) ? "" : "s";
1327 $c2 = ($idle_dumpers < 10) ? " " : "";
1328 $c3 = ($idle_dumpers == 1) ? " " : "";
1329 printf "%d dumper%s idle%s %s: %s\n", $idle_dumpers, $c1, $c2, $c3, $status_driver;
1332 printf "taper status: $status_taper\n";
1333 if (defined $qlen{"tapeq"}) {
1334 printf "taper qlen: %d\n", $qlen{"tapeq"};
1336 if (defined ($free{"kps"})) {
1337 printf "network free kps: %9d\n", $free{"kps"};
1339 if (defined ($free{"space"})) {
1340 if ($holding_space) {
1341 $hs = ($free{"space"} * 1.0 / $holding_space) * 100;
1345 printf "holding space : %9d$unit (%6.2f%%)\n", ($free{"space"}/$unitdivisor), $hs;
1349 if(defined $opt_stats) {
1350 if(defined($current_time) && $current_time != $start_time) {
1351 $total_time=$current_time-$start_time;
1352 foreach $key (sort byprocess keys %busy_time) {
1353 printf "%8s busy : %8s (%6.2f%%)\n",
1354 $key, &busytime($busy_time{$key}),
1355 ($busy_time{$key} * 1.0 / $total_time) * 100;
1357 for ($d = 0; $d <= $#dumpers_active; $d++) {
1358 $l = sprintf "%2d dumper%s busy%s : %8s (%6.2f%%)",
1359 $d, ($d == 1) ? "" : "s", ($d == 1) ? " " : "",
1360 &busytime($dumpers_active[$d]),
1361 ($dumpers_active[$d] * 1.0 / $total_time) * 100;
1364 $s2 = " " x length($l);
1365 $r = $dumpers_held[$d];
1366 foreach $key (sort valuesort keys %$r) {
1368 unless $dumpers_held[$d]{$key} >= 1;
1369 printf "%s%20s: %8s (%6.2f%%)\n",
1372 &busytime($dumpers_held[$d]{$key}),
1373 ($dumpers_held[$d]{$key} * 1.0 / $dumpers_active[$d]) * 100;
1385 sub make_hostpart() {
1386 local($host,$partition,$datestamp) = @_;
1388 if(! defined($hosts{$host})) {
1393 foreach $pp (sort @$host) {
1394 $new_part = 0 if ($pp eq $partition);
1396 push @$host, $partition if $new_part==1;
1398 my($hostpart) = "$host$partition$datestamp";
1399 if(!defined $datestamp{$datestamp}) {
1400 $datestamp{$datestamp} = 1;
1401 push @datestamp, $datestamp;
1408 my(@tmp_a) = split(/(\d*)$/, $a, 2);
1409 my(@tmp_b) = split(/(\d*)$/, $b, 2);
1410 return ($tmp_a[0] cmp $tmp_b[0]) || ($tmp_a[1] <=> $tmp_b[1]);
1414 $r->{$b} <=> $r->{$a};
1418 local($filename) = @_;
1421 local($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
1422 $atime,$mtime,$ctime,$blksize,$blocks);
1423 while ($filename ne "") {
1424 $filename = "$filename.tmp" if (!(-e "$filename"));
1425 $filename = "/dev/null" if (!(-e "$filename"));
1426 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
1427 $atime,$mtime,$ctime,$blksize,$blocks) = stat($filename);
1428 $size=$size-32768 if $size > 32768;
1430 open(DUMP,$filename);
1433 if(/^CONT_FILENAME=(.*)$/) { $filename = $1; last }
1434 last if /^To restore, position tape at start of file and run/;
1449 @MoY = ('Jan','Feb','Mar','Apr','May','Jun',
1450 'Jul','Aug','Sep','Oct','Nov','Dec');
1452 # Preset an array of values in case some parts are not passed as
1453 # arguments. This lets the date, etc, be omitted and default to
1462 # See if this argument looks like a month name.
1468 $month = $month + 1;
1475 # See if this is a day of the month.
1477 if ($a =~ /^\d+$/ && $a >= 1 && $a <= 32) {
1482 # See if the next argument looks like a time.
1484 if ($a =~ /^(\d+):(\d+)/) {
1487 if ($a =~ /^(\d+):(\d+):(\d+)/) {
1493 # See if this is a year.
1495 if ($a =~ /^\d\d\d\d$/ && $a >= 1900) {
1501 $time = &timelocal (@tl);
1506 sub set_starttime() {
1511 # Preset an array of values in case some parts are not passed as
1512 # arguments. This lets the date, etc, be omitted and default to
1518 $tl[5] = substr($date, 0, 4) if(length($date) >= 4);
1519 $tl[4] = substr($date, 4, 2)-1 if(length($date) >= 6);
1520 $tl[3] = substr($date, 6, 2) if(length($date) >= 8);
1521 $tl[2] = substr($date, 8, 2) if(length($date) >= 10);
1522 $tl[1] = substr($date, 10, 2) if(length($date) >= 12);
1523 $tl[0] = substr($date, 12, 2) if(length($date) >= 14);
1525 $time = &timelocal (@tl);
1533 my($oneday)=24*60*60;
1535 @now=localtime($starttime+$delta);
1536 if($delta > $oneday) {
1537 $result=sprintf("%d+",$delta/$oneday);
1541 $result.=sprintf("%d:%02d:%02d",$now[2],$now[1],$now[0]);
1547 my($oneday)=24*60*60;
1549 if($busy > $oneday) {
1550 $days=int($busy/$oneday);
1551 $result=sprintf("%d+",$busy/$oneday);
1552 $busy-=$days*$oneday;
1556 $hours=int($busy/60/60);
1557 $busy-=$hours*60*60;
1558 $minutes=int($busy/60);
1561 $result.=sprintf("%d:%02d:%02d",$hours,$minutes,$seconds);
1566 print "amstatus [--file amdump_file]\n";
1567 print " [--summary] [--dumping] [--waitdumping] [--waittaper]\n";
1568 print " [--dumpingtape] [--writingtape] [--finished] [--failed]\n";
1569 print " [--estimate] [--gestimate] [--stats] [--date]\n";
1570 print " [--locale-independent-date-format]\n";
1571 print " [--config] <config>\n";