X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=server-src%2Famdump.pl;h=558a4c7df747908e4bba1b6b2529e888088ef07b;hb=refs%2Fheads%2Fmaster;hp=4caf7182bdcc8dece102e8b454df86de7b874e9f;hpb=cb38d19aa8dc2c5d380ab2d7ad9724a5d99eee5d;p=debian%2Famanda diff --git a/server-src/amdump.pl b/server-src/amdump.pl index 4caf718..558a4c7 100644 --- a/server-src/amdump.pl +++ b/server-src/amdump.pl @@ -1,9 +1,10 @@ #! @PERL@ -# Copyright (c) 2010 Zmanda Inc. All Rights Reserved. +# Copyright (c) 2010-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 -# by the Free Software Foundation. +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY @@ -23,6 +24,7 @@ use warnings; use Getopt::Long; use POSIX qw(WIFEXITED WEXITSTATUS strftime); +use File::Glob qw( :glob ); use Amanda::Config qw( :init :getconf ); use Amanda::Util qw( :constants ); @@ -36,7 +38,7 @@ use Amanda::Paths; sub usage { my ($msg) = @_; print STDERR < [--no-taper] [-o configoption]* [host/disk]* +Usage: amdump [--no-taper] [--from-client] [--exact-match] [-o configoption]* [host/disk]* EOF print STDERR "$msg\n" if $msg; exit 1; @@ -48,10 +50,17 @@ my $config_overrides = new_config_overrides($#ARGV+1); my @config_overrides_opts; my $opt_no_taper = 0; +my $opt_from_client = 0; +my $opt_exact_match = 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, + 'exact-match' => \$opt_exact_match, 'o=s' => sub { push @config_overrides_opts, "-o" . $_[1]; add_config_override_opt($config_overrides, $_[1]); @@ -82,7 +91,8 @@ my $timestamp = strftime "%Y%m%d%H%M%S", @now; my $datestamp = strftime "%Y%m%d", @now; my $starttime_locale_independent = strftime "%Y-%m-%d %H:%M:%S %Z", @now; my $trace_log_filename = "$logdir/log"; -my $amdump_log_filename = "$logdir/amdump"; +my $amdump_log_filename_default = "$logdir/amdump"; +my $amdump_log_filename = "$logdir/amdump.$timestamp"; my $exit_code = 0; my $amdump_log = \*STDERR; @@ -148,6 +158,7 @@ sub bail_already_running { or die("cannot open a fake log to send an report - situation is dire"); print $fakelog <>", $amdump_log_filename) or die("could not open amdump log file '$amdump_log_filename': $!"); + unlink $amdump_log_filename_default; + symlink $amdump_log_filename, $amdump_log_filename_default; } 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'):(); + my @exact_match = $opt_exact_match? ('--exact-match'):(); check_exec($planner); check_exec($driver); @@ -222,7 +237,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, @exact_match, @config_overrides_opts, @hostdisk; die "Could not exec $planner: $!"; } debug(" planner: $pl_pid"); @@ -239,7 +254,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"); @@ -284,15 +299,19 @@ sub trim_indexes { sub roll_amdump_logs { debug("renaming amdump log and trimming old amdump logs (beyond tapecycle+2)"); - # rename all the way along the tapecycle + unlink "$amdump_log_filename_default.1"; + rename $amdump_log_filename_default, "$amdump_log_filename_default.1"; + + # keep the latest tapecycle files. + my @files = sort {-M $b <=> -M $a} grep { !/^\./ && -f "$_"} <$logdir/amdump.*>; my $days = getconf($CNF_TAPECYCLE) + 2; for (my $i = $days-1; $i >= 1; $i--) { - next unless -f "$amdump_log_filename.$i"; - rename("$amdump_log_filename.$i", "$amdump_log_filename.".($i+1)); + my $a = pop @files; + } + foreach my $name (@files) { + unlink $name; + amdump_log("unlink $name"); } - - # now swap the current logfile in - rename("$amdump_log_filename", "$amdump_log_filename.1"); } # now do the meat of the amdump work; these operations are ported directly @@ -305,6 +324,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(); @@ -317,6 +343,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");