fix for #693333, hard-coding of amandabackup as user in many scripts and docs
[debian/amanda] / perl / Amanda / DB / Catalog.pm
index f541ac503f312f525f12022216a84ed2cbe38078..dc849da8d2c62aa90a7428019de07aa7d437c94b 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (c) 2008, 2009, 2010 Zmanda, Inc.  All Rights Reserved.
+# Copyright (c) 2008-2012 Zmanda, Inc.  All Rights Reserved.
 #
 # This program is free software; you can redistribute it and/or modify it
 # under the terms of the GNU General Public License version 2 as published
@@ -101,6 +101,10 @@ have an associated dump row.
 
 (integer) -- number of successful parts in this dump
 
+=item bytes
+
+(integer) -- size (in bytes) of the dump on disk, 0 if the size is not known.
+
 =item kb
 
 (integer) -- size (in kb) of the dump on disk
@@ -397,11 +401,10 @@ TODO: add_dump
 
 =cut
 
-use Amanda::Logfile qw( :constants match_disk match_host
-                       match_datestamp match_level );
+use Amanda::Logfile qw( :constants );
 use Amanda::Tapelist;
 use Amanda::Config qw( :init :getconf config_dir_relative );
-use Amanda::Util qw( quote_string weaken_ref );
+use Amanda::Util qw( quote_string weaken_ref match_disk match_host match_datestamp match_level);
 use File::Glob qw( :glob );
 use warnings;
 use strict;
@@ -646,9 +649,10 @@ sub get_parts_and_dumps {
                    # the rest of these params are unknown until we see a taper
                    # DONE, PARTIAL, or FAIL line, although we count nparts
                    # manually instead of relying on the logfile
-                   nparts => 0,
-                   kb => -1,
-                   sec => -1,
+                   nparts => 0, # $find_result->{'totalparts'}
+                   bytes => -1, # $find_result->{'bytes'}
+                   kb => -1,    # $find_result->{'kb'}
+                   sec => -1,   # $find_result->{'sec'}
                };
            }
 
@@ -679,6 +683,7 @@ sub get_parts_and_dumps {
                );
                # and fix up the dump, too
                $dump->{'status'} = $find_result->{'status'} || 'FAILED';
+               $dump->{'bytes'} = $find_result->{'bytes'};
                $dump->{'kb'} = $find_result->{'kb'};
                $dump->{'sec'} = $find_result->{'sec'};
            }
@@ -723,20 +728,33 @@ sub get_parts_and_dumps {
 
            # now extract the appropriate info; luckily these log lines have the same
            # format, more or less
-           my ($hostname, $diskname, $dump_timestamp, $nparts, $level, $secs, $kb, $message);
+           my ($hostname, $diskname, $dump_timestamp, $nparts, $level, $secs, $kb, $bytes, $message);
            ($hostname, $str) = Amanda::Util::skip_quoted_string($str);
            ($diskname, $str) = Amanda::Util::skip_quoted_string($str);
            ($dump_timestamp, $str) = Amanda::Util::skip_quoted_string($str);
            if ($status ne 'FAIL' and $type != $L_SUCCESS) { # nparts is not in SUCCESS lines
-               ($nparts, $str) = Amanda::Util::skip_quoted_string($str);
+               ($nparts, my $str1) = Amanda::Util::skip_quoted_string($str);
+               if (substr($str1, 0,1) ne '[') {
+                   $str = $str1;
+               } else { # nparts is not in all PARTIAL lines
+                   $nparts = 0;
+               }
+               
            } else {
                $nparts = 0;
            }
            ($level, $str) = Amanda::Util::skip_quoted_string($str);
            if ($status ne 'FAIL') {
                my $s = $str;
-               ($secs, $kb, $str) = ($str =~ /^\[sec ([-0-9.]+) kb (\d+).*\] ?(.*)$/)
+               my $b_unit;
+               ($secs, $b_unit, $kb, $str) = ($str =~ /^\[sec ([-0-9.]+) (kb|bytes) ([-0-9]+).*\] ?(.*)$/)
                    or die("'$s'");
+               if ($b_unit eq 'bytes') {
+                   $bytes = $kb;
+                   $kb /= 1024;
+               } else {
+                   $bytes = 0;
+               }
                $secs = 0.1 if ($secs <= 0);
            }
            if ($status ne 'OK') {
@@ -812,9 +830,11 @@ sub get_parts_and_dumps {
 
            $dump->{'message'} = $message;
            if ($status eq 'FAIL') {
+               $dump->{'bytes'} = 0;
                $dump->{'kb'} = 0;
                $dump->{'sec'} = 0.0;
            } else {
+               $dump->{'bytes'} = $bytes+0;
                $dump->{'kb'} = $kb+0;
                $dump->{'sec'} = $secs+0.0;
            }
@@ -882,7 +902,7 @@ sub sort_dumps {
        for my $key (@$keys) {
            my ($rev, $k) = ($key =~ /^(-?)(.*)$/);
 
-           if ($k =~ /^(nparts|level)$/) {
+           if ($k =~ /^(nparts|level|filenum)$/) {
                # compare dump components numerically
                $res = $a->{$k} <=> $b->{$k};
            } else { # ($k =~ /^(hostname|diskname|write_timestamp|dump_timestamp)$/)