add bug closure to changelog
[debian/amanda] / server-src / amstatus.pl
index be2b8fe40467e647bdb53201dcae2b9d1051ba5a..443e7e503f43bea075b8f53c50db38432cab8c51 100644 (file)
@@ -6,13 +6,13 @@ eval '(exit $?0)' && eval 'exec @PERL@ -S $0 ${1+"$@"}'
         & eval 'exec @PERL@ -S $0 $argv:q'
                if 0;
 
-require "newgetopt.pl";
 use warnings;
 use lib '@amperldir@';
 use Time::Local;
 use Text::ParseWords;
 use Amanda::Util;
 use Amanda::Process;
+use Getopt::Long;
 
 delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV', 'PATH'};
 $ENV{'PATH'} = "/bin:/usr/bin:/usr/sbin:/sbin";       # force known path
@@ -33,26 +33,52 @@ $STATUS_MISSING =  8;
 $STATUS_TAPE    = 16;
 $exit_status    =  0;
 
-$result = &NGetOpt (   "summary",
-                       "stats|statistics",
-                       "dumping|d",
-                       "waitdumping|wdumping",
-                       "waittaper|wtaper",
-                       "dumpingtape|dtape",
-                       "writingtape|wtape",
-                       "finished",
-                       "failed|error",
-                       "estimate",
-                       "gestimate|gettingestimate",
-                       "date",
-                       "config|c:s",
-                       "file:s",
-                       "locale-independent-date-format",
-                       );
-if($result !=1 ) {
-       &usage();
+my $opt_summary;
+my $opt_stats;
+my $opt_dumping;
+my $opt_waitdumping;
+my $opt_waittaper;
+my $opt_dumpingtape;
+my $opt_writingtape;
+my $opt_finished;
+my $opt_failed;
+my $opt_estimate;
+my $opt_gestimate;
+my $opt_date;
+my $opt_config;
+my $opt_file;
+my $opt_locale_independent_date_format;
+
+sub usage() {
+       print "amstatus [--file amdump_file]\n";
+       print "         [--summary] [--dumping] [--waitdumping] [--waittaper]\n";
+       print "         [--dumpingtape] [--writingtape] [--finished] [--failed]\n";
+       print "         [--estimate] [--gestimate] [--stats] [--date]\n";
+       print "         [--locale-independent-date-format]\n";
+       print "         [--config] <config>\n";
+       exit 0;
 }
 
+Getopt::Long::Configure(qw{ bundling });
+GetOptions(
+    'summary'                        => \$opt_summary,
+    'stats|statistics'               => \$opt_stats,
+    'dumping|d'                      => \$opt_dumping,
+    'waitdumping|wdumping'           => \$opt_waitdumping,
+    'waittaper|wtaper'               => \$opt_waittaper,
+    'dumpingtape|dtape'              => \$opt_dumpingtape,
+    'writingtape|wtape'              => \$opt_writingtape,
+    'finished'                       => \$opt_finished,
+    'failed|error'                   => \$opt_failed,
+    'estimate'                       => \$opt_estimate,
+    'gestimate|gettingestimate'      => \$opt_gestimate,
+    'date'                           => \$opt_date,
+    'config|c:s'                     => \$opt_config,
+    'file:s'                         => \$opt_file,
+    'locale-independent-date-format' => \$opt_locale_independent_date_format,
+    ) or usage();
+
+
 if( defined $opt_config ) {
        $conf = $opt_config;
 }
@@ -233,8 +259,8 @@ while($lineX = <AMDUMP>) {
                        $dump_started{$hostpart}=-1;
                        $level{$hostpart}=$line[5];
                        $error{$hostpart}="planner: " . $line[6];
-       } elsif($line[1] eq "time") {
-               if($line[3] eq "got") {
+       } elsif($line[1] eq "time") {
+               if($line[3] eq "got") {
                                if($line[4] eq "result") {
                                        $host = $line[7];
                                        $partition = $line[9];
@@ -384,6 +410,7 @@ while($lineX = <AMDUMP>) {
                                        }
                                        $running_dumper{$dumper} = $hostpart;
                                        $error{$hostpart}="";
+                                       $taper_error{$hostpart}="";
                                        $size{$hostpart} = 0;
                                        $dumpers_active++;
                                        if(! defined($dumpers_active[$dumpers_active])) {
@@ -457,6 +484,7 @@ while($lineX = <AMDUMP>) {
                                        $taper_started{$hostpart}=1;
                                        $taper_finished{$hostpart}=0;
                                        $taper_time{$hostpart}=$current_time;
+                                       $taper_error{$hostpart}="";
                                        $ntchunk_size = 0;
                                }
                                elsif($line[6] eq "PORT-WRITE") {
@@ -472,6 +500,7 @@ while($lineX = <AMDUMP>) {
                                        $taper_started{$hostpart}=1;
                                        $taper_finished{$hostpart}=0;
                                        $taper_time{$hostpart}=$current_time;
+                                       $taper_error{$hostpart}="";
                                        $size{$hostpart} = 0;
                                        $ntchunk_size = 0;
                                }
@@ -492,10 +521,12 @@ while($lineX = <AMDUMP>) {
                                                $dump_finished{$hostpart}=-3;
                                        }
                                        $busy_time{$line[5]}+=($current_time-$dump_time{$hostpart});
-                             $running_dumper{$line[5]} = "0";
-                             $dump_time{$hostpart}=$current_time;
-                             $error{$hostpart}="dumper: $error";
-                             $dumpers_active--;
+                                       $running_dumper{$line[5]} = "0";
+                                       $dump_time{$hostpart}=$current_time;
+                                       if (!$taper_error{$hostpart}) {
+                                               $error{$hostpart}="dumper: $error";
+                                       }
+                                       $dumpers_active--;
 
                                }
                                elsif($line[6] eq "DONE") {
@@ -571,15 +602,16 @@ while($lineX = <AMDUMP>) {
                        }
                        elsif($line[5] eq "taper") {
                                if($line[6] eq "DONE" || $line[6] eq "PARTIAL") {
-                                       #7:handle 8:label 9:filenum 10:errstr
+                                       #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];
-                                       $label=$line[8];
+
                                        $status_taper = "Idle";
                                        $hostpart=$serial{$serial};
                                        $line[10] =~ /sec (\S+) (kb|bytes) (\d+) kps/;
                                        if ($2 eq 'kb') {
                                                $size=$3 / $unitdivisor;
-                                  } else {
+                                       } else {
                                                $size=$3 / ( $unitdivisor * 1024);
                                        }
                                        $taper_finished{$hostpart}=1;
@@ -598,6 +630,10 @@ while($lineX = <AMDUMP>) {
                                        }
                                        if ($line[6] eq "PARTIAL") {
                                                $partial{$hostpart} = 1;
+                                               if ($line[9] eq "TAPE-ERROR") {
+                                                       $error{$hostpart} = "taper: $line[12]";
+                                                       $taper_error{$hostpart} = "taper: $line[12]";
+                                               }
                                        }
                                        else {
                                                $partial{$hostpart} = 0;
@@ -907,7 +943,7 @@ foreach $host (sort @hosts) {
                                                $taper_started{$hostpart}==1 &&
                                                $dump_finished{$hostpart}!=-3) {
                                        if(defined $dump_started{$hostpart} &&
-                                               $dump_started{$hostpart} == 1 &&
+                                               $dump_started{$hostpart} == 1 &&
                                                        $dump_finished{$hostpart} == -1) {
                                                if(defined $opt_failed) {
                                                        printf "%8s ", $datestamp if defined $opt_date;
@@ -920,7 +956,7 @@ foreach $host (sort @hosts) {
                                                $fpartition++;
                                                $fsize+=$esize{$hostpart};
                                        } elsif(defined $dump_started{$hostpart} &&
-                                               $dump_started{$hostpart} == 1 &&
+                                               $dump_started{$hostpart} == 1 &&
                                                        $dump_finished{$hostpart} == 0 &&
                                                        $taper_started{$hostpart} == 1) {
                                                if( defined $opt_dumpingtape ||
@@ -969,6 +1005,7 @@ foreach $host (sort @hosts) {
                                                                $exit_status |= $STATUS_FAILED;
                                                        }
                                                        if($in_flush == 0) {
+                                                               print " dump done," if defined $dump_finished{$hostpart} && $dump_finished{$hostpart} == 1;
                                                                print " writing to tape";
                                                        }
                                                        else {
@@ -1039,6 +1076,7 @@ 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;
                                                        if($in_flush == 0) {
                                                                print " failed to tape";
                                                        }
@@ -1046,7 +1084,7 @@ foreach $host (sort @hosts) {
                                                                print " failed to flush";
                                                        }
                                                        print ": ",$error{$hostpart} if defined $error{$hostpart};
-                                               
+
                                                        print " (will retry)" unless $taper_finished{$hostpart} < -1;
                                                        if( defined $starttime ) {
                                                                print " (", &showtime($taper_time{$hostpart}), ")";
@@ -1566,12 +1604,3 @@ sub busytime() {
        return $result;
 }
 
-sub usage() {
-       print "amstatus [--file amdump_file]\n";
-       print "         [--summary] [--dumping] [--waitdumping] [--waittaper]\n";
-       print "         [--dumpingtape] [--writingtape] [--finished] [--failed]\n";
-       print "         [--estimate] [--gestimate] [--stats] [--date]\n";
-       print "         [--locale-independent-date-format]\n";
-       print "         [--config] <config>\n";
-       exit 0;
-}