Imported Upstream version 2.5.1
[debian/amanda] / server-src / amoverview.pl.in
index 15a943d1cc3c0ca2541acbd8ad8813645874daa7..9f4ce99b71864faa3abe4fe4321d6e62d8cb81c4 100644 (file)
@@ -9,12 +9,13 @@ require 5.001;
 
 use FileHandle;
 use Getopt::Long;
+use Text::ParseWords;
 use Carp;
 use POSIX;
 
 sub Usage {
     print STDERR <<END;
-Usage: $0 [[-config] CONFIG] [-hostwidth width] [-diskwidth width] [-verbose]
+Usage: $0 [[-config] CONFIG] [-hostwidth width] [-diskwidth width] [-skipmissed] [-last] [-num0] [-togo0] [-verbose]
 
 This script generates to standard output an overview of the filesystems
 dumped over time and the type of dump done on a particular day, such as
@@ -55,11 +56,19 @@ my $amadmin = "$sbindir/amadmin$suf";
 my $opt_config         = "$config";
 my $opt_hostwidth      = 8;
 my $opt_diskwidth      = 20;
+my $opt_skipmissed     = 0;
+my $opt_last           = 0;
+my $opt_num0           = 0;
+my $opt_togo0          = 0;
 my $opt_verbose                = 0;
 
 GetOptions('config=s'          => \$opt_config,
           'hostwidth=i'        => \$opt_hostwidth,
           'diskwidth=i'        => \$opt_diskwidth,
+          'skipmissed'         => \$opt_skipmissed,
+          'last'               => \$opt_last,
+          'num0'               => \$opt_num0,
+          'togo0'              => \$opt_togo0,
           'verbose'            => \$opt_verbose)
 or Usage();
 
@@ -70,6 +79,15 @@ elsif($#ARGV > 0) {
   Usage();
 }
 
+#untaint user input $ARGV[0]
+
+if ($opt_config =~ /^([\w.-]+)$/) {          # $1 is untainted
+   $opt_config = $1;
+} else {
+    die "filename '$opt_config' has invalid characters.\n";
+}
+
+
 -d "$confdir/$opt_config" or
        die "$0: directory `$confdir/$opt_config' does not exist.\n";
 
@@ -103,10 +121,12 @@ my $fh = new FileHandle "$amadmin $opt_config find|" or
     die "$0: error in opening `$amadmin $opt_config find' pipe: $!\n";
 <$fh>;
 while (<$fh>) {
+print "'$_'\n";
     chomp;
     next if /found Amanda directory/;
     next if /skipping cruft directory/;
-    ($date, $host, $disk, $level, $tape, $file, $status) = split ' ', $_;
+    next if /skip-incr/;
+    ($date, $host, $disk, $level, $tape, $file, $part, $status) = quotewords(" ", 0, $_);
     next if $date eq 'date';
     next if $date eq 'Warning:';
     next if $date eq 'Scanning';
@@ -124,6 +144,56 @@ while (<$fh>) {
 $fh->close or
     die "$0: error in closing `$amadmin $opt_config find|' pipe: $!\n";
 
+# Process the status to arrive at a "last" status
+if ($opt_last) {
+    for $host (sort keys %disks) {
+        for $disk (sort keys %{$disks{$host}}) {
+           $level{$host}{$disk}{"0000-LA-ST"} = '';
+           for $date (sort keys %dates) {
+               if ($level{$host}{$disk}{$date} eq "E"
+                    && $level{$host}{$disk}{"0000-LA-ST"} =~ /^\d/ ) {
+                   $level{$host}{$disk}{"0000-LA-ST"} .= $level{$host}{$disk}{$date};
+               } elsif ($level{$host}{$disk}{$date} eq "") {
+                   $level{$host}{$disk}{"0000-LA-ST"} =~ s/E//;
+               } else {
+                   $level{$host}{$disk}{"0000-LA-ST"} = $level{$host}{$disk}{$date};
+               }
+           }
+        }
+    }
+}
+
+# Number of level 0 backups
+if ($opt_num0) {
+    for $host (sort keys %disks) {
+        for $disk (sort keys %{$disks{$host}}) {
+            $level{$host}{$disk}{'0000-NM-L0'} = 0;
+            for $date (sort keys %dates) {
+                if ($level{$host}{$disk}{$date} =~ /0/) {
+                    $level{$host}{$disk}{'0000-NM-L0'} += 1;
+                }
+            }
+        }
+    }
+}
+
+# Runs to the last level 0
+if ($opt_togo0) {
+    for $host (sort keys %disks) {
+        for $disk (sort keys %{$disks{$host}}) {
+            $level{$host}{$disk}{'0000-TO-GO'} = 0;
+            my $togo=0;
+            for $date (sort keys %dates) {
+                if ($level{$host}{$disk}{$date} =~ /0/) {
+                    $level{$host}{$disk}{'0000-TO-GO'} = $togo;
+                }
+                $togo++;
+            }
+        }
+    }
+}
+
+unless ($opt_skipmissed)
 # touch all the dates just in case whole days were missed.
 {
     my ($start, $finish) = 
@@ -138,7 +208,15 @@ $fh->close or
        $start += 86400;
     }
 }
-    
+
+#Add the "last" entry    
+$dates{"0000-LA-ST"}=1 if ($opt_last);
+
+#Add the "Number of Level 0s" entry
+$dates{"0000-NM-L0"}=1 if ($opt_num0);
+
+#Add the "Runs to go" entry
+$dates{"0000-TO-GO"}=1 if ($opt_togo0);
 
 # make formats