9611a8a39ca118f6cf00b126005ee8b52c4c9fd2
[debian/amanda] / server-src / amlogroll.pl
1 #! @PERL@
2 # Copyright (c) 2010 Zmanda Inc.  All Rights Reserved.
3 #
4 # This program is free software; you can redistribute it and/or modify it
5 # under the terms of the GNU General Public License version 2 as published
6 # by the Free Software Foundation.
7 #
8 # This program is distributed in the hope that it will be useful, but
9 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10 # or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
11 # for more details.
12 #
13 # You should have received a copy of the GNU General Public License along
14 # with this program; if not, write to the Free Software Foundation, Inc.,
15 # 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 #
17 # Contact information: Zmanda Inc., 465 S. Mathilda Ave., Suite 300
18 # Sunnyvale, CA 94086, USA, or: http://www.zmanda.com
19
20 use lib '@amperldir@';
21 use strict;
22 use warnings;
23
24 use Amanda::Util qw( :constants );
25 use Amanda::Config qw( :init );
26 use Amanda::Logfile qw( log_rename get_current_log_timestamp $amanda_log_trace_log );
27 use Amanda::Debug qw( debug );
28 use Getopt::Long;
29
30 Amanda::Util::setup_application("amlogroll", "server", $CONTEXT_CMDLINE);
31
32 my $config_overrides = new_config_overrides($#ARGV+1);
33
34 debug("Arguments: " . join(' ', @ARGV));
35 Getopt::Long::Configure(qw{bundling});
36 GetOptions(
37     'version' => \&Amanda::Util::version_opt,
38     'o=s' => sub { add_config_override_opt($config_overrides, $_[1]); },
39 ) or usage();
40
41 if (@ARGV < 1) {
42     die "USAGE: amlogroll <config> <config-overwrites> <ignored-stuff>";
43 }
44
45 set_config_overrides($config_overrides);
46 config_init($CONFIG_INIT_EXPLICIT_NAME, $ARGV[0]);
47 my ($cfgerr_level, @cfgerr_errors) = config_errors();
48 if ($cfgerr_level >= $CFGERR_WARNINGS) {
49     config_print_errors();
50     if ($cfgerr_level >= $CFGERR_ERRORS) {
51         die "Errors processing config file";
52     }
53 }
54
55 # our STDERR may be connected to the amdump log file, so be sure to do unbuffered
56 # writes to that file
57 my $old_fh = select(STDERR);
58 $| = 1;
59 select($old_fh);
60
61 Amanda::Debug::add_amanda_log_handler($amanda_log_trace_log);
62
63 Amanda::Util::finish_setup($RUNNING_AS_DUMPUSER);
64
65 # the actual work of the program - very short!
66 my $timestamp = get_current_log_timestamp();
67 die "could not get current timestamp" unless $timestamp;
68 log_rename($timestamp);
69
70 Amanda::Util::finish_application();