Imported Upstream version 3.3.1
[debian/amanda] / server-src / amdump.pl
index 383fa85c7ed0356ad8504368ebf2ac6d782b4fcb..04499f5b89318fe808c3d8e42ab0df02b36b57b8 100644 (file)
@@ -36,7 +36,7 @@ use Amanda::Paths;
 sub usage {
     my ($msg) = @_;
     print STDERR <<EOF;
-Usage: amdump <conf> [--no-taper] [-o configoption]* [host/disk]*
+Usage: amdump <conf> [--no-taper] [--from-client] [-o configoption]* [host/disk]*
 EOF
     print STDERR "$msg\n" if $msg;
     exit 1;
@@ -48,10 +48,15 @@ my $config_overrides = new_config_overrides($#ARGV+1);
 my @config_overrides_opts;
 
 my $opt_no_taper = 0;
+my $opt_from_client = 0;
+
+debug("Arguments: " . join(' ', @ARGV));
 Getopt::Long::Configure(qw(bundling));
 GetOptions(
+    'version' => \&Amanda::Util::version_opt,
     'help|usage|?' => \&usage,
     'no-taper' => \$opt_no_taper,
+    'from-client' => \$opt_from_client,
     'o=s' => sub {
        push @config_overrides_opts, "-o" . $_[1];
        add_config_override_opt($config_overrides, $_[1]);
@@ -148,10 +153,11 @@ sub bail_already_running {
        or die("cannot open a fake log to send an report - situation is dire");
     print $fakelog <<EOF;
 INFO amdump amdump pid $$
+START planner date $timestamp
 START driver date $timestamp
 ERROR amdump $msg
 EOF
-    run_subprocess("$sbindir/amreport", $config_name, '--from-amdump', '-l', $fakelogfile);
+    run_subprocess("$sbindir/amreport", $config_name, '--from-amdump', '-l', $fakelogfile, @config_overrides_opts);
     unlink($fakelogfile);
 
     # and we're done here
@@ -164,7 +170,7 @@ sub do_amcleanup {
     # logfiles are still around.  First, try an amcleanup -p to see if
     # the actual processes are already dead
     debug("runing amcleanup -p");
-    run_subprocess("$sbindir/amcleanup", '-p', $config_name);
+    run_subprocess("$sbindir/amcleanup", '-p', $config_name, @config_overrides_opts);
 
     # and check again
     return unless -f $amdump_log_filename || -f $trace_log_filename;
@@ -192,7 +198,8 @@ sub start_logfiles {
     # undef first.. stupid perl.
     debug("beginning amdump log");
     $amdump_log = undef;
-    open($amdump_log, ">", $amdump_log_filename)
+    # Must be opened in append so that all subprocess can write to it.
+    open($amdump_log, ">>", $amdump_log_filename)
        or die("could not open amdump log file '$amdump_log_filename': $!");
 }
 
@@ -200,6 +207,7 @@ sub planner_driver_pipeline {
     my $planner = "$amlibexecdir/planner";
     my $driver = "$amlibexecdir/driver";
     my @no_taper = $opt_no_taper? ('--no-taper'):();
+    my @from_client = $opt_from_client? ('--from-client'):();
 
     check_exec($planner);
     check_exec($driver);
@@ -221,7 +229,7 @@ sub planner_driver_pipeline {
        close($amdump_log);
        exec $planner,
            # note that @no_taper must follow --starttime
-           $config_name, '--starttime', $timestamp, @no_taper, @config_overrides_opts, @hostdisk;
+           $config_name, '--starttime', $timestamp, @no_taper, @from_client, @config_overrides_opts, @hostdisk;
        die "Could not exec $planner: $!";
     }
     debug(" planner: $pl_pid");
@@ -238,7 +246,7 @@ sub planner_driver_pipeline {
        POSIX::dup2(fileno($amdump_log), 2);
        close($amdump_log);
        exec $driver,
-           $config_name, @no_taper, @config_overrides_opts;
+           $config_name, @no_taper, @from_client, @config_overrides_opts;
        die "Could not exec $driver: $!";
     }
     debug(" driver: $dr_pid");
@@ -261,7 +269,7 @@ sub planner_driver_pipeline {
 
 sub do_amreport {
     debug("running amreport");
-    run_subprocess("$sbindir/amreport", $config_name, '--from-amdump');
+    run_subprocess("$sbindir/amreport", $config_name, '--from-amdump', @config_overrides_opts);
 }
 
 sub roll_trace_logs {
@@ -272,12 +280,12 @@ sub roll_trace_logs {
 
 sub trim_trace_logs {
     debug("trimming old trace logs");
-    run_subprocess("$amlibexecdir/amtrmlog", $config_name);
+    run_subprocess("$amlibexecdir/amtrmlog", $config_name, @config_overrides_opts);
 }
 
 sub trim_indexes {
     debug("trimming old indexes");
-    run_subprocess("$amlibexecdir/amtrmidx", $config_name);
+    run_subprocess("$amlibexecdir/amtrmidx", $config_name, @config_overrides_opts);
 }
 
 sub roll_amdump_logs {
@@ -304,6 +312,13 @@ wait_for_hold();
 # bail out
 do_amcleanup();
 
+my $crtl_c = 0;
+$SIG{INT} = \&interrupt;
+
+sub interrupt {
+    $crtl_c = 1;
+}
+
 # start up the log file
 start_logfiles();
 
@@ -316,6 +331,14 @@ amdump_log("starttime-locale-independent $starttime_locale_independent");
 # run the planner and driver, the one piped to the other
 planner_driver_pipeline();
 
+if ($crtl_c == 1) {
+    print "Caught a ctrl-c\n";
+    log_add($L_FATAL, "amdump killed by ctrl-c");
+    debug("Caught a ctrl-c");
+    $exit_code = 1;
+}
+$SIG{INT} = 'DEFAULT';
+
 my $end_longdate = strftime "%a %b %e %H:%M:%S %Z %Y", localtime;
 amdump_log("end at $end_longdate");