Merge tag 'upstream/3.3.3'
[debian/amanda] / server-src / amstatus.pl
index 443e7e503f43bea075b8f53c50db38432cab8c51..2dc19f9e5fcebd268b65260c33995aa3d144f065 100644 (file)
@@ -191,7 +191,7 @@ else {
 open(AMDUMP,"<$errfile") || die("$errfile: $!");
 print "Using $errfile\n";
 
-my $taper_status_file;
+my %taper_status_file;
 
 $start_degraded_mode = 0;
 
@@ -397,6 +397,7 @@ while($lineX = <AMDUMP>) {
                                        $partition = $line[11];
                                        $hostpart=&make_hostpart($host,$partition,$gdatestamp);
                                        $serial=$line[7];
+                                       $dumper_to_serial{$line[5]} = $serial;
                                        $dump_started{$hostpart}=1;
                                        $dump_time{$hostpart}=$current_time;
                                        $dump_finished{$hostpart}=0;
@@ -427,6 +428,7 @@ while($lineX = <AMDUMP>) {
                                        $partition=$line[11];
                                        $hostpart=&make_hostpart($host,$partition,$gdatestamp);
                                        $serial=$line[7];
+                                       $chunker_to_serial{$line[5]} = $serial;
                                        $serial{$serial}=$hostpart;
                                        $holding_file{$hostpart}=$line[8];
                                        #$chunk_started{$hostpart}=1;
@@ -466,6 +468,7 @@ while($lineX = <AMDUMP>) {
                                }
                                elsif($line[6] eq "FILE-WRITE") {
                                        #7:name 8:handle 9:filename 10:host 11:disk 12:level 13:datestamp 14:splitsize
+                                       $name=$line[7];
                                        $serial=$line[8];
                                        $host=$line[10];
                                        $partition=$line[11];
@@ -485,10 +488,13 @@ while($lineX = <AMDUMP>) {
                                        $taper_finished{$hostpart}=0;
                                        $taper_time{$hostpart}=$current_time;
                                        $taper_error{$hostpart}="";
-                                       $ntchunk_size = 0;
+                                       $taper_name{$hostpart} = $name;
+                                       $worker_to_serial{$name} = $serial;
+                                   $tapedsize{$hostpart} = 0;
                                }
                                elsif($line[6] eq "PORT-WRITE") {
                                        #7:name 8:handle 9:host 10:disk 11:level 12:datestamp 13:splitsize 14:diskbuffer 15:fallback_splitsize
+                                       $name=$line[7];
                                        $serial=$line[8];
                                        $host=$line[9];
                                        $partition=$line[10];
@@ -501,8 +507,22 @@ while($lineX = <AMDUMP>) {
                                        $taper_finished{$hostpart}=0;
                                        $taper_time{$hostpart}=$current_time;
                                        $taper_error{$hostpart}="";
+                                       $taper_name{$hostpart} = $name;
+                                       $worker_to_serial{$name} = $serial;
+                                   $tapedsize{$hostpart} = 0;
                                        $size{$hostpart} = 0;
-                                       $ntchunk_size = 0;
+                               }
+                               elsif($line[6] eq "TAKE-SCRIBE-FROM") {
+                                       #7:name1 #8:handle #9:name2
+                                       $name1=$line[7];
+                                       $serial=$line[8];
+                                       $name2=$line[9];
+                                       $hostpart=$serial{$serial};
+                                       $taper_nb{$name1} = $taper_nb{$name2};
+                                       $taper_nb{$name2} = 0;
+                                       if (defined $hostpart) {
+                                               $error{$hostpart} = $olderror{$hostpart};
+                                       }
                                }
                        }
                }
@@ -510,6 +530,11 @@ while($lineX = <AMDUMP>) {
                        #print "result: " , $line[5] . " " . $line[6] . " " . $line[7] . "\n" if defined $line[5] && defined $line[6] && defined $line[7];
                        $current_time = $line[3];
                        if($line[5] =~ /dumper\d+/) {
+                               if($line[6] eq "(eof)") {
+                                       $line[6] = "FAILED";
+                                       $line[7] = $dumper_to_serial{$line[5]};
+                                       $line[8] = "dumper CRASH";
+                               }
                                if($line[6] eq "FAILED" || $line[6] eq "TRY-AGAIN") {
                                        #7:handle 8:message
                                        $serial = $line[7];
@@ -561,6 +586,11 @@ while($lineX = <AMDUMP>) {
                                }
                        }
                        elsif($line[5] =~ /chunker\d+/) {
+                               if($line[6] eq "(eof)") {
+                                       $line[6] = "FAILED";
+                                       $line[7] = $chunker_to_serial{$line[5]};
+                                       $line[8] = "chunker CRASH";
+                               }
                                if($line[6] eq "DONE" || $line[6] eq "PARTIAL") {
                                        #7:handle 8:size
                                        $serial=$line[7];
@@ -601,7 +631,24 @@ while($lineX = <AMDUMP>) {
                                }
                        }
                        elsif($line[5] eq "taper") {
-                               if($line[6] eq "DONE" || $line[6] eq "PARTIAL") {
+                               if($line[6] eq "(eof)") {
+                                       # all worker fail
+                                       foreach $worker (keys %worker_to_serial) {
+                                               $serial = $worker_to_serial{$worker};
+                                               $hostpart=$serial{$serial};
+                                               if(defined $hostpart) {
+                                                       $error= "taper CRASH";
+                                                       $taper_finished{$hostpart} = -2;
+                                                       $status_taper = $error;
+                                                       $busy_time{"taper"}+=($current_time-$taper_time{$hostpart});
+                                                       $taper_time{$hostpart}=$current_time;
+                                                       $error{$hostpart}="$error";
+                                                       undef $worker_to_serial{$worker};
+                                               }
+                                               undef $taper_status_file{$hostpart};
+                                       }
+                               }
+                               elsif($line[6] eq "DONE" || $line[6] eq "PARTIAL") {
                                        #DONE:    7:handle 8:label 9:filenum 10:errstr
                                        #PARTIAL: 7:handle 8:INPUT-* 9:TAPE-* 10:errstr 11:INPUT-MSG 12:TAPE-MSG
                                        $serial=$line[7];
@@ -620,14 +667,8 @@ while($lineX = <AMDUMP>) {
                                        if(!defined $size{$hostpart}) {
                                                $size{$hostpart}=$size;
                                        }
-                                       $ntpartition{$nb_tape}++;
-                                       $ntsize{$nb_tape} += $size{$hostpart} - $ntchunk_size;
-                                       if(defined $esize{$hostpart} && $esize{$hostpart} > 1) {
-                                               $ntesize{$nb_tape} += $esize{$hostpart} - $ntchunk_size;
-                                       }
-                                       else {
-                                               $ntesize{$nb_tape} += $size{$hostpart} - $ntchunk_size;
-                                       }
+                                       $ntape = $taper_nb{$taper_name{$hostpart}};
+                                       $ntpartition{$ntape}++ if defined $ntape;
                                        if ($line[6] eq "PARTIAL") {
                                                $partial{$hostpart} = 1;
                                                if ($line[9] eq "TAPE-ERROR") {
@@ -638,10 +679,8 @@ while($lineX = <AMDUMP>) {
                                        else {
                                                $partial{$hostpart} = 0;
                                        }
-                                       if ($ntchunk_size > 0) {
-                                               $ntchunk{$nb_tape}++;
-                                       }
-                                       undef $taper_status_file;
+                                       undef $taper_status_file{$hostpart};
+                                       undef $worker_to_serial{$taper_name{$hostpart}};
                                }
                                elsif($line[6] eq "PARTDONE") {
                                        #7:handle 8:label 9:filenum 10:ksize 11:errstr
@@ -651,10 +690,10 @@ while($lineX = <AMDUMP>) {
                                        #$size=$1 / $unitdivisor;
                                        $size=$line[10] / $unitdivisor;
                                        $tapedsize{$hostpart} += $size;
-                                       $ntchunk{$nb_tape}++;
-                                       $ntsize{$nb_tape} += $size;
-                                       $ntesize{$nb_tape} += $size;
-                                       $ntchunk_size += $size;
+                                       $ntape = $taper_nb{$taper_name{$hostpart}};
+                                       $ntchunk{$ntape}++;
+                                       $ntsize{$ntape} += $size;
+                                       $ntesize{$ntape} += $size;
                                }
                                elsif($line[6] eq "REQUEST-NEW-TAPE") {
                                        #7:serial
@@ -662,7 +701,8 @@ while($lineX = <AMDUMP>) {
                                        $old_status_taper = $status_taper;
                                        $status_taper = "Asking for a new tape";
                                        $hostpart=$serial{$serial};
-                                       if (defined $hostpart) {
+                                       if (defined $hostpart and
+                                               !defined($olderror{$hostpart})) {
                                                $olderror{$hostpart} = $error{$hostpart};
                                                $error{$hostpart} = "waiting for a new tape";
                                        }
@@ -672,6 +712,13 @@ while($lineX = <AMDUMP>) {
                                        $serial=$line[7];
                                        $status_taper = $old_status_taper;
                                        $hostpart=$serial{$serial};
+                                       $nb_tape++;
+                                       $taper_nb{$taper_name{$hostpart}} = $nb_tape;
+                                       $label = $line[8];
+                                       $ntlabel{$nb_tape} = $label;
+                                       $ntpartition{$nb_tape} = 0;
+                                       $ntsize{$nb_tape} = 0;
+                                       $ntesize{$nb_tape} = 0;
                                        if (defined $hostpart) {
                                                $error{$hostpart} = $olderror{$hostpart};
                                        }
@@ -685,20 +732,26 @@ while($lineX = <AMDUMP>) {
                                        $error=$line[8];
                                        $status_taper = $error;
                                        $exit_status |= $STATUS_TAPE;
-                                       undef $taper_status_file;
+                                       undef $taper_status_file{$hostpart};
                                }
                                elsif($line[6] eq "FAILED") {
                                        #7:handle 8:INPUT- 9:TAPE- 10:input_message 11:tape_message
-                                  $serial=$line[7];
+                                       $serial=$line[7];
                                        $hostpart=$serial{$serial};
                                        if(defined $hostpart) {
                                                if($line[9] eq "TAPE-ERROR") {
                                                        $error=$line[11];
                                                        $taper_finished{$hostpart} = -2;
                                                        $status_taper = $error;
-                                               }
-                                               else {
-                                                       $error=$line[10];
+                                               } elsif($line[9] eq "TAPE-CONFIG") {
+                                                       $tape_config{$hostpart} = $error;
+                                                       $error=$line[11];
+                                                       $tape_config{$hostpart} = $error;
+                                                       $taper_finished{$hostpart} = -2;
+                                                       $status_taper = $error;
+                                               } else { # INPUT-ERROR
+                                                       $error = $line[10];
+                                                       $error = $error{$hostpart} if defined $error{$hostpart};
                                                        $taper_finished{$hostpart} = -1;
                                                        $status_taper = "Idle";
                                                }
@@ -706,7 +759,8 @@ while($lineX = <AMDUMP>) {
                                                $taper_time{$hostpart}=$current_time;
                                                $error{$hostpart}="$error";
                                        }
-                                       undef $taper_status_file;
+                                       undef $taper_status_file{$hostpart};
+                                       undef $worker_to_serial{$taper_name{$hostpart}};
                                }
                        }
                }
@@ -757,7 +811,7 @@ while($lineX = <AMDUMP>) {
                                }
                        }
                }
-          elsif($line[1] eq "FINISHED") {
+               elsif($line[1] eq "FINISHED") {
                        $driver_finished = 1;
                }
        }
@@ -775,16 +829,21 @@ while($lineX = <AMDUMP>) {
        elsif($line[0] eq "taper") {
                if($line[1] eq "wrote") {
                        #1:"wrote" 2:"label" 3:label
-                       $nb_tape++;
-                       $label = $line[3];
-                       $ntlabel{$nb_tape} = $label;
-                       $ntpartition{$nb_tape} = 0;
-                       $ntsize{$nb_tape} = 0;
-                       $ntesize{$nb_tape} = 0;
+                       #$nb_tape++;
+                       #$label = $line[3];
+                       #$ntlabel{$nb_tape} = $label;
+                       #$ntpartition{$nb_tape} = 0;
+                       #$ntsize{$nb_tape} = 0;
+                       #$ntesize{$nb_tape} = 0;
                }
                elsif($line[1] eq "status" && $line[2] eq "file") {
                        #1:"status" #2:"file:" #3:hostname #4:diskname #5:filename
-                       $taper_status_file = $line[5];
+                       #$host = $line[3];
+                       #$partition = $line[4];
+                       #Which datestamp to use?
+                       #$hostpart=&make_hostpart($host,$partition,$datestamp);
+                       #assume $hostpart is already set.
+                       $taper_status_file{$hostpart} = $line[5];
                }
        }
        elsif($line[0] eq "splitting" &&
@@ -798,7 +857,6 @@ while($lineX = <AMDUMP>) {
                $ntchunk{$nb_tape}++;
                $ntsize{$nb_tape} += $size / $unitdivisor;
                $ntesize{$nb_tape} += $size / $unitdivisor;
-               $ntchunk_size += $size / $unitdivisor;
        }
        else {
                #print "Ignoring: $lineX\n";
@@ -940,8 +998,7 @@ foreach $host (sort @hosts) {
                                        $in_flush=1;
                                }
                                if(defined $taper_started{$hostpart} &&
-                                               $taper_started{$hostpart}==1 &&
-                                               $dump_finished{$hostpart}!=-3) {
+                                               $taper_started{$hostpart}==1) {
                                        if(defined $dump_started{$hostpart} &&
                                                $dump_started{$hostpart} == 1 &&
                                                        $dump_finished{$hostpart} == -1) {
@@ -970,8 +1027,8 @@ foreach $host (sort @hosts) {
                                                        }
                                                        print " dumping to tape";
                                                        $size = $tapedsize{$hostpart};
-                                                       if ($taper_status_file && -f $taper_status_file &&
-                                                               open FF, "<$taper_status_file") {
+                                                       if ($taper_status_file{$hostpart} && -f $taper_status_file{$hostpart} &&
+                                                               open FF, "<$taper_status_file{$hostpart}") {
                                                                $line = <FF>;
                                                                if (defined $line) {
                                                                        chomp $line;
@@ -1005,15 +1062,24 @@ foreach $host (sort @hosts) {
                                                                $exit_status |= $STATUS_FAILED;
                                                        }
                                                        if($in_flush == 0) {
-                                                               print " dump done," if defined $dump_finished{$hostpart} && $dump_finished{$hostpart} == 1;
+                                                               if (defined $dump_finished{$hostpart}) {
+                                                                       if ($dump_finished{$hostpart} == 1) {
+                                                                               print " dump done,";
+                                                                       } else {
+                                                                               $exit_status |= $STATUS_FAILED;
+                                                                               print " dump failed: ", $error{$hostpart}, ",";
+                                                                               $fpartition++;
+                                                                               $fsize+=$esize{$hostpart};
+                                                                       }
+                                                               }
                                                                print " writing to tape";
                                                        }
                                                        else {
                                                                print " flushing to tape";
                                                        }
                                                        $size = $tapedsize{$hostpart};
-                                                       if ($taper_status_file &&  -f $taper_status_file &&
-                                                               open FF, "<$taper_status_file") {
+                                                       if ($taper_status_file{$hostpart} &&  -f $taper_status_file{$hostpart} &&
+                                                               open FF, "<$taper_status_file{$hostpart}") {
                                                                $line = <FF>;
                                                                if (defined $line) {
                                                                        chomp $line;
@@ -1024,14 +1090,16 @@ foreach $host (sort @hosts) {
                                                                }
                                                                close FF;
                                                        }
-                                                       if(defined($size)) {
+                                                       if(defined($size) and defined($size{$hostpart}) and $size{$hostpart} > 0) {
                                                                printf " (%d$unit done (%0.2f%%))", $size, 100.0 * $size/$size{$hostpart};
                                                        }
                                                        if( defined $starttime ) {
                                                                print " (", &showtime($taper_time{$hostpart}), ")";
                                                        }
                                                        print ", ", $error{$hostpart} if (defined($error{$hostpart}) &&
-                                                                                                                                           $error{$hostpart} ne "");
+                                                                                                                         $error{$hostpart} ne "" &&
+                                                                                                                         (!defined $dump_finished{$hostpart} ||
+                                                                                                                          $dump_finished{$hostpart} != -3));
                                                        print "\n";
                                                }
                                                $tapartition++;
@@ -1076,12 +1144,20 @@ foreach $host (sort @hosts) {
                                                        printf "%8s ", $datestamp if defined $opt_date;
                                                        printf "%-${maxnamelength}s%2d ", "$host:$qpartition", $level{$hostpart};
                                                        printf "%9d$unit", $xsize;
-                                                   print " dump done," if defined $dump_finished{$hostpart} && $dump_finished{$hostpart} == 1;
+                                                       print " dump done," if defined $dump_finished{$hostpart} && $dump_finished{$hostpart} == 1;
                                                        if($in_flush == 0) {
-                                                               print " failed to tape";
+                                                               if ($tape_config{$hostpart}) {
+                                                                       print " taping delayed because of config";
+                                                               } else {
+                                                                       print " failed to tape";
+                                                               }
                                                        }
                                                        else {
-                                                               print " failed to flush";
+                                                               if ($tape_config{$hostpart}) {
+                                                                       print " flushing delayed because of config";
+                                                               } else {
+                                                                       print " failed to flush";
+                                                               }
                                                        }
                                                        print ": ",$error{$hostpart} if defined $error{$hostpart};
 
@@ -1122,6 +1198,12 @@ foreach $host (sort @hosts) {
                                                        printf "%-${maxnamelength}s%2d ", "$host:$qpartition", $level{$hostpart};
                                                        printf "%9d$unit", $size{$hostpart};
                                                        if($in_flush == 0) {
+                                                               if (defined $dump_finished{$hostpart} && $dump_finished{$hostpart} == -3) {
+                                                                       $exit_status |= $STATUS_FAILED;
+                                                                       print " dump failed: ", $error{$hostpart}, ",";
+                                                                       $fpartition++;
+                                                                       $fsize+=$esize{$hostpart};
+                                                               }
                                                                print " finished";
                                                        }
                                                        else {
@@ -1571,12 +1653,29 @@ sub set_starttime() {
 
 
 sub showtime() {
-       my($delta)=shift;
-       my($oneday)=24*60*60;
+       my($delta) = shift;
+       my($oneday) = 24*60*60;
+
+       my @starttime = localtime($starttime);
+       my @now = localtime($starttime+$delta);
+       $now_yday = $now[7];
+
+       # leap year
+       if ($starttime[5] < $now[5]) {
+               my $days_in_year = 364;
+               my $startime1 = $starttime;
+               while ($startime1 < $starttime+$delta) {
+                       my @starttime1 = localtime($starttime);
+                       if ($starttime1[7] > $days_in_year) {
+                               $days_in_year = $starttime1[7];
+                       }
+                       $startime1 += $oneday;
+               }
+               $now_yday += $days_in_year+1;
+       }
 
-       @now=localtime($starttime+$delta);
-       if($delta > $oneday) {
-               $result=sprintf("%d+",$delta/$oneday);
+       if ($starttime[7] < $now_yday) {
+               $result=sprintf("%d+", $now_yday - $starttime[7]);
        } else {
                $result="";
        }