Merge tag 'upstream/3.3.1'
[debian/amanda] / server-src / amstatus.pl
index 79803c1d2ae3b440d71f20aad3ca0887173e6f72..7192e181e1605b63b5e8b0ccd2ba381851708385 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;
 }
@@ -419,8 +445,8 @@ while($lineX = <AMDUMP>) {
                        }
                        elsif($line[5] =~ /taper/) {
                                if($line[6] eq "START-TAPER") {
-                                       #7:timestamp
-                                       $gdatestamp=$line[7];
+                                       #7:name 8:timestamp
+                                       $gdatestamp=$line[8];
                                        if(!defined $datestamp{$gdatestamp}) {
                                                $datestamp{$gdatestamp} = 1;
                                                push @datestamp, $gdatestamp;
@@ -428,21 +454,22 @@ while($lineX = <AMDUMP>) {
                                        $status_taper = "Searching for a new tape";
                                }
                                elsif($line[6] eq "NEW-TAPE") {
+                                       #7:name 8:handle
                                        $status_taper = "Searching for a new tape";
                                }
                                elsif($line[6] eq "NO-NEW-TAPE") {
-                                       #7:handle 8:errmsg
-                                       $serial=$line[7];
-                                       $error=$line[8];
+                                       #7:name 8:handle 9:errmsg
+                                       $serial=$line[8];
+                                       $error=$line[9];
                                        $status_taper = $error;
                                }
                                elsif($line[6] eq "FILE-WRITE") {
-                                       #7:handle 8:filename 9:host 10:disk 11:level 12:datestamp 13:splitsize
-                                       $serial=$line[7];
-                                       $host=$line[9];
-                                       $partition=$line[10];
-                                       $level=$line[11];
-                                       $ldatestamp=$line[12];
+                                       #7:name 8:handle 9:filename 10:host 11:disk 12:level 13:datestamp 14:splitsize
+                                       $serial=$line[8];
+                                       $host=$line[10];
+                                       $partition=$line[11];
+                                       $level=$line[12];
+                                       $ldatestamp=$line[13];
                                        $status_taper = "Writing $host:$partition";
                                        if(!defined $datestamp{$ldatestamp}) {
                                                $datestamp{$ldatestamp} = 1;
@@ -459,12 +486,12 @@ while($lineX = <AMDUMP>) {
                                        $ntchunk_size = 0;
                                }
                                elsif($line[6] eq "PORT-WRITE") {
-                                       #7:handle 8:host 9:disk 10:level 11:datestamp 12:splitsize 13:diskbuffer 14:fallback_splitsize
-                                       $serial=$line[7];
-                                       $host=$line[8];
-                                       $partition=$line[9];
-                                       $level=$line[10];
-                                       $ldatestamp=$line[11];
+                                       #7:name 8:handle 9:host 10:disk 11:level 12:datestamp 13:splitsize 14:diskbuffer 15:fallback_splitsize
+                                       $serial=$line[8];
+                                       $host=$line[9];
+                                       $partition=$line[10];
+                                       $level=$line[11];
+                                       $ldatestamp=$line[12];
                                        $status_taper = "Writing $host:$partition";
                                        $hostpart=&make_hostpart($host,$partition,$ldatestamp);
                                        $serial{$serial}=$hostpart;
@@ -575,8 +602,12 @@ while($lineX = <AMDUMP>) {
                                        $label=$line[8];
                                        $status_taper = "Idle";
                                        $hostpart=$serial{$serial};
-                                       $line[10] =~ /sec (\S+) kb (\d+) kps/;
-                                       $size=$2 / $unitdivisor;
+                                       $line[10] =~ /sec (\S+) (kb|bytes) (\d+) kps/;
+                                       if ($2 eq 'kb') {
+                                               $size=$3 / $unitdivisor;
+                                  } else {
+                                               $size=$3 / ( $unitdivisor * 1024);
+                                       }
                                        $taper_finished{$hostpart}=1;
                                        $busy_time{"taper"}+=($current_time-$taper_time{$hostpart});
                                        $taper_time{$hostpart}=$current_time;
@@ -636,22 +667,14 @@ while($lineX = <AMDUMP>) {
                                        }
                                }
                                elsif($line[6] eq "TAPER-OK") {
+                                       #7:name #8:label
                                        $status_taper = "Idle";
                                }
-                               elsif($line[6] eq "TRY-AGAIN" || $line[6] eq "TAPE-ERROR") {
-                                       #7:handle 8:errstr
-                                       $serial=$line[7];
+                               elsif($line[6] eq "TAPE-ERROR") {
+                                       #7:name 8:errstr
                                        $error=$line[8];
                                        $status_taper = $error;
-                                       $hostpart=$serial{$serial};
-                                       if(defined $hostpart) {
-                                               $taper_finished{$hostpart}= $line[6] eq 'TAPE-ERROR' ? -2 : -1;
-                                               $busy_time{"taper"}+=($current_time-$taper_time{$hostpart});
-                                               $taper_time{$hostpart}=$current_time;
-                                               $error{$hostpart}="taper: $error";
-                                       } else {
-                                               $exit_status |= $STATUS_TAPE;
-                                       }
+                                       $exit_status |= $STATUS_TAPE;
                                        undef $taper_status_file;
                                }
                                elsif($line[6] eq "FAILED") {
@@ -740,31 +763,10 @@ while($lineX = <AMDUMP>) {
                }
        }
        elsif($line[0] eq "taper") {
-               if($line[1] eq "slot") {
-                       #2:slot 3:"wrote" 4:"label" 5:corrupted...
-                       $nb_tape++;
-                       $lineX =~ /wrote label `(\S*)'/;
-                       $label = $1;
-                       $ntlabel{$nb_tape} = $label;
-                       $ntpartition{$nb_tape} = 0;
-                       $ntsize{$nb_tape} = 0;
-                       $ntesize{$nb_tape} = 0;
-               }
-               elsif($line[1] eq "wrote") {
-                       #1:"wrote" 2:"label" 3:corrupted
+               if($line[1] eq "wrote") {
+                       #1:"wrote" 2:"label" 3:label
                        $nb_tape++;
-                       $lineX =~ /wrote label `(\S*)'/;
-                       $label = $1;
-                       $ntlabel{$nb_tape} = $label;
-                       $ntpartition{$nb_tape} = 0;
-                       $ntsize{$nb_tape} = 0;
-                       $ntesize{$nb_tape} = 0;
-               }
-               elsif($line[1] eq "using") {
-                       #1:"using" #2:"label" #3:`label' #4:date #5 `timestamp'
-                       $nb_tape++;
-                       $lineX =~ /using label `(\S*)'/;
-                       $label = $1;
+                       $label = $line[3];
                        $ntlabel{$nb_tape} = $label;
                        $ntpartition{$nb_tape} = 0;
                        $ntsize{$nb_tape} = 0;
@@ -1590,10 +1592,3 @@ sub busytime() {
        return $result;
 }
 
-sub usage() {
-       print "amstatus [--config] config [--file amdump_file]\n";
-       print "         [--summary] [--dumping] [--waitdumping] [--waittaper]\n";
-       print "         [--dumpingtape] [--writingtape] [--finished] [--failed]\n";
-       print "         [--estimate] [--gestimate] [--stats] [--date] [--locale-independent-date-format]\n";
-       exit 0;
-}