Amanda-Users

Re: New version of amandatape script.

2006-02-17 11:07:07
Subject: Re: New version of amandatape script.
From: Josef Wolf <jw AT raven.inka DOT de>
To: amanda-users AT amanda DOT org
Date: Fri, 17 Feb 2006 16:38:02 +0100
On Tue, Feb 14, 2006 at 10:25:07PM +0100, Josef Wolf wrote:
> On Tue, Feb 14, 2006 at 10:10:51PM +0100, Josef Wolf wrote:

> Here comes a new version of the amandatape program I posted about two years
> ago.

Here's a patch to fix following problems:

- Sort logfiles correctly when more than 10 logifles were generated in a
  single day.
- Always ignore log.error.X files.
- When using the -d option, search backwards for tapecycle from given date
  instead of date of newest logfile.
- Fix filemark counting when output is restricted to specific DLEs.

Please find the patch attached below.  Have fun.

Index: bin/amandatape
===================================================================
--- bin/amandatape      (Revision 1396)
+++ bin/amandatape      (Arbeitskopie)
@@ -2,7 +2,7 @@
 
 # amandatape -- a utility to print amanda tape labels for DAT and CD.
 #
-# 2004-02-12 Josef Wolf  (jw AT raven.inka DOT de)
+# 2005-02-15 Josef Wolf  (jw AT raven.inka DOT de)
 #
 # Portions of this program which I authored may be used for any purpose
 # so long as this notice is left intact.
@@ -295,10 +295,10 @@
 sub log_bydate ($$) {
     my ($a, $b) = @_;
 
-    $a=~s!^.*?/log.([^/]+)$!$1!;
-    $b=~s!^.*?/log.([^/]+)$!$1!;
+    my ($ad, $anr) = $a=~m!^.*?/log\.(\d+)\.(\d+)$!;
+    my ($bd, $bnr) = $b=~m!^.*?/log\.(\d+)\.(\d+)$!;
 
-    return $a cmp $b;
+    return $ad <=> $bd || $anr <=> $bnr;
 }
 
 sub add_dumping {
@@ -327,14 +327,18 @@
     my %labels;    # which tape labels we already have seen
     my $lastvol=-1;
 
-    my @logs=reverse sort log_bydate (<$LOGDIR/log.*>, <$LOGDIR/oldlog/log.*>);
+    my @logs=reverse sort log_bydate (<$LOGDIR/log.[0-9.]*>,
+                                      <$LOGDIR/oldlog/log.[0-9.]*>);
     splice @logs, 0, $ignore if defined $ignore;
 
     FILE: foreach my $logfile (@logs) {
-        if (defined $dignore && &log_bydate("$dignore.0", $logfile) > 0) {
-           $dignore = undef;
-           splice @logfiles, -$lastvol, $lastvol if $lastvol>0;
-           $lastvol = -1;
+        if (defined $dignore) {
+            if (&log_bydate("/$dignore.0", $logfile) >= 0) {
+                $dignore = undef;
+                splice @logfiles, -$lastvol, $lastvol if $lastvol>0;
+                $lastvol = -1;
+            }
+            next;
        }
        open (IN, $logfile) or die "$logfile: $!";
        foreach my $l (reverse <IN>) {
@@ -414,7 +418,6 @@
             my ($host, $filesystem, $date, $chunk, $level, $rest) =
                 $2=~/(\S+) (\S+) (\S+) (\S+)? ?(\S+) (\[.*)/;
             my $dle="$host:$filesystem";
-            next unless &wantdle ($dle);
             $dle{$dle} = 1;
             $date=~s/(....)(..)(..)/$1-$2-$3/;
             $nr++ if $#curchunk<0 || defined $chunk;
@@ -424,11 +427,13 @@
             push (@curchunk, $h);
             unless (defined $chunk) {
                 $taper{$dle}{$date}=[] unless exists $taper{$dle}{$date};
-                push (@{$taper{$dle}{$date}}, [@curchunk]);
+                push (@{$taper{$dle}{$date}}, [@curchunk]) if &wantdle ($dle);
                 @curchunk = ();
             }
-           $tape{$label}{"kb"} += $h->{"kb"};
-           $tape{$label}{"count"}{$level}++;
+            if (&wantdle ($dle)) {
+                $tape{$label}{"kb"} += $h->{"kb"};
+                $tape{$label}{"count"}{$level}++;
+            }
        }
         if ($line=~/^INFO taper tape (.*)/) {
             my ($t, $d2, $kb, $d3, $fm, $rest) = split (/\s+/, $1, 6);

<Prev in Thread] Current Thread [Next in Thread>