add a changelog entry
[debian/amanda] / server-src / amvault.pl
index 5071d42d3e39fd9e201da50647c2daa21cc7856f..87a43fb95790c2aacf3c5862a2062f37ff6adb51 100644 (file)
@@ -21,11 +21,11 @@ use lib '@amperldir@';
 use strict;
 use warnings;
 
-package main::Interactive;
+package main::Interactivity;
 use POSIX qw( :errno_h );
 use Amanda::MainLoop qw( :GIOCondition );
 use vars qw( @ISA );
-@ISA = qw( Amanda::Interactive );
+@ISA = qw( Amanda::Interactivity );
 
 sub new {
     my $class = shift;
@@ -61,12 +61,12 @@ sub user_request {
        if (!defined $n_read) {
            return if ($! == EINTR);
            $self->abort();
-           return $params{'finished_cb'}->(
+           return $params{'request_cb'}->(
                Amanda::Changer::Error->new('fatal',
                        message => "Fail to read from stdin"));
        } elsif ($n_read == 0) {
            $self->abort();
-           return $params{'finished_cb'}->(
+           return $params{'request_cb'}->(
                Amanda::Changer::Error->new('fatal',
                        message => "Aborted by user"));
        } else {
@@ -76,7 +76,7 @@ sub user_request {
                chomp $line;
                $buffer = "";
                $self->abort();
-               return $params{'finished_cb'}->(undef, $line);
+               return $params{'request_cb'}->(undef, $line);
            }
        }
     };
@@ -93,7 +93,7 @@ sub user_request {
 package Amvault;
 
 use Amanda::Config qw( :getconf config_dir_relative );
-use Amanda::Debug qw( :logging );
+use Amanda::Debug qw( :logging debug );
 use Amanda::Xfer qw( :constants );
 use Amanda::Header qw( :constants );
 use Amanda::MainLoop;
@@ -108,8 +108,8 @@ use Amanda::Changer qw( :constants );
 use Amanda::Cmdline;
 use Amanda::Paths;
 use Amanda::Logfile qw( :logtype_t log_add log_add_full
-                       log_rename $amanda_log_trace_log make_stats
-                       match_datestamp match_level );
+                       log_rename $amanda_log_trace_log make_stats );
+use Amanda::Util qw ( match_datestamp match_level );
 
 use base qw(
     Amanda::Recovery::Clerk::Feedback
@@ -140,6 +140,7 @@ sub new {
 
        exporting => 0, # is an export in progress?
        call_after_export => undef, # call this when export complete
+       config_overrides_opts => $params{'config_overrides_opts'},
 
        # called when the operation is complete, with the exit
        # status
@@ -177,7 +178,7 @@ sub setup_src {
     my $src = $self->{'src'} = {};
 
     # put together a clerk, which of course requires a changer, scan,
-    # interactive, and feedback
+    # interactivity, and feedback
     my $chg = Amanda::Changer->new();
     return $self->failure("Error opening source changer: $chg")
        if $chg->isa('Amanda::Changer::Error');
@@ -185,11 +186,11 @@ sub setup_src {
 
     $src->{'seen_labels'} = {};
 
-    $src->{'interactive'} = main::Interactive->new();
+    $src->{'interactivity'} = main::Interactivity->new();
 
     $src->{'scan'} = Amanda::Recovery::Scan->new(
            chg => $src->{'chg'},
-           interactive => $src->{'interactive'});
+           interactivity => $src->{'interactivity'});
 
     $src->{'clerk'} = Amanda::Recovery::Clerk->new(
            changer => $src->{'chg'},
@@ -312,7 +313,7 @@ sub plan_cb {
                      $dump->{'dump_timestamp'} . " " .
                      $dump->{'level'} . "\n";
            }
-           $total_kb += $dump->{'kb'};
+           $total_kb += int $dump->{'kb'};
        }
 
        print STDOUT "Total Size: $total_kb KB\n";
@@ -340,17 +341,28 @@ sub plan_cb {
 sub setup_dst {
     my $self = shift;
     my $dst = $self->{'dst'} = {};
+    my $tlf = Amanda::Config::config_dir_relative(getconf($CNF_TAPELIST));
+    my $tl = Amanda::Tapelist->new($tlf);
 
     $dst->{'label'} = undef;
     $dst->{'tape_num'} = 0;
 
-    my $chg = Amanda::Changer->new($self->{'dst_changer'});
+    my $chg = Amanda::Changer->new($self->{'dst_changer'},
+                                  tapelist => $tl,
+                                  labelstr => getconf($CNF_LABELSTR),
+                                  autolabel => $self->{'dst_autolabel'});
     return $self->failure("Error opening destination changer: $chg")
        if $chg->isa('Amanda::Changer::Error');
     $dst->{'chg'} = $chg;
 
+    my $interactivity = Amanda::Interactivity->new(
+                                       name => getconf($CNF_INTERACTIVITY));
+    my $scan_name = getconf($CNF_TAPERSCAN);
     $dst->{'scan'} = Amanda::Taper::Scan->new(
+       algorithm => $scan_name,
        changer => $dst->{'chg'},
+       interactivity => $interactivity,
+       tapelist => $tl,
        labelstr => getconf($CNF_LABELSTR),
        autolabel => $self->{'dst_autolabel'});
 
@@ -460,7 +472,9 @@ sub xfer_dumps {
 
        # create and start the transfer
        $xfer = Amanda::Xfer->new([ $xfer_src, $xfer_dst ]);
-       $xfer->start($steps->{'handle_xmsg'});
+       my $size = 0;
+       $size = $current->{'dump'}->{'bytes'} if exists $current->{'dump'}->{'bytes'};
+       $xfer->start($steps->{'handle_xmsg'}, 0, $size);
 
        # count the "threads" running here (clerk and scribe)
        $n_threads = 2;
@@ -563,6 +577,16 @@ sub quit {
     my $steps = define_steps
            cb_ref => \$exit_cb;
 
+    # the export may not start until we quit the scribe, so wait for it now..
+    step check_exporting => sub {
+       # if we're exporting the final volume, wait for that to complete
+       if ($self->{'exporting'}) {
+           $self->{'call_after_export'} = $steps->{'quit_scribe'};
+       } else {
+           $steps->{'quit_scribe'}->();
+       }
+    };
+
     # we may have several resources to clean up..
     step quit_scribe => sub {
        if ($self->{'cleanup'}{'quit_scribe'}) {
@@ -570,28 +594,19 @@ sub quit {
            $self->{'dst'}{'scribe'}->quit(
                finished_cb => $steps->{'quit_scribe_finished'});
        } else {
-           $steps->{'check_exporting'}->();
+           $steps->{'quit_clerk'}->();
        }
     };
 
     step quit_scribe_finished => sub {
+       $self->{'dst'}{'scan'}->quit();
        my ($err) = @_;
        if ($err) {
            print STDERR "$err\n";
            $exit_status = 1;
        }
 
-       $steps->{'check_exporting'}->();
-    };
-
-    # the export may not start until we quit the scribe, so wait for it now..
-    step check_exporting => sub {
-       # if we're exporting the final volume, wait for that to complete
-       if ($self->{'exporting'}) {
-           $self->{'call_after_export'} = $steps->{'quit_clerk'};
-       } else {
-           $steps->{'quit_clerk'}->();
-       }
+       $steps->{'quit_clerk'}->();
     };
 
     step quit_clerk => sub {
@@ -615,12 +630,22 @@ sub quit {
     };
 
     step roll_log => sub {
+       if (defined $self->{'src'}->{'chg'}) {
+           $self->{'src'}->{'chg'}->quit();
+           $self->{'src'}->{'chg'} = undef;
+       }
+       if (defined $self->{'dst'}->{'chg'}) {
+           $self->{'dst'}->{'chg'}->quit();
+           $self->{'dst'}->{'chg'} = undef;
+       }
        if ($self->{'cleanup'}{'roll_trace_log'}) {
            log_add_full($L_FINISH, "driver", "fake driver finish");
            log_add($L_INFO, "pid-done $$");
 
-           debug("invoking amreport..");
-           system("$sbindir/amreport", $self->{'config_name'}, "--from-amdump");
+           my @amreport_cmd = ("$sbindir/amreport", $self->{'config_name'}, "--from-amdump",
+                                @{$self->{'config_overrides_opts'}});
+           debug("invoking amreport (" . join(" ", @amreport_cmd) . ")");
+           system(@amreport_cmd);
 
            debug("rolling logfile..");
            log_rename($self->{'dst_write_timestamp'});
@@ -723,6 +748,7 @@ sub scribe_notif_log_info {
     my $self = shift;
     my %params = @_;
 
+    debug("$params{'message'}");
     log_add_full($L_INFO, "taper", $params{'message'});
 }
 
@@ -736,7 +762,7 @@ sub scribe_notif_tape_done {
     # exports are going on simultaneously.
     $self->{'exporting'}++;
 
-    my $finished_cb = sub {};
+    my $finished_cb = $params{'finished_cb'};
     my $steps = define_steps
        cb_ref => \$finished_cb;
 
@@ -888,6 +914,7 @@ EOF
 Amanda::Util::setup_application("amvault", "server", $CONTEXT_CMDLINE);
 
 my $config_overrides = new_config_overrides($#ARGV+1);
+my @config_overrides_opts;
 my $opt_quiet = 0;
 my $opt_dry_run = 0;
 my $opt_fulls_only = 0;
@@ -924,9 +951,13 @@ sub add_autolabel {
     usage("unknown --autolabel value '$val'");
 }
 
+debug("Arguments: " . join(' ', @ARGV));
 Getopt::Long::Configure(qw{ bundling });
 GetOptions(
-    'o=s' => sub { add_config_override_opt($config_overrides, $_[1]); },
+    'o=s' => sub {
+       push @config_overrides_opts, "-o" . $_[1];
+       add_config_override_opt($config_overrides, $_[1]);
+    },
     'q|quiet' => \$opt_quiet,
     'n|dry-run' => \$opt_dry_run,
     'fulls-only' => \$opt_fulls_only,
@@ -980,7 +1011,8 @@ my $vault = Amvault->new(
     opt_dry_run => $opt_dry_run,
     quiet => $opt_quiet,
     fulls_only => $opt_fulls_only,
-    opt_export => $opt_export);
+    opt_export => $opt_export,
+    config_overrides_opts => \@config_overrides_opts);
 Amanda::MainLoop::call_later(sub { $vault->run($exit_cb) });
 Amanda::MainLoop::run();