b685a5276374bba6334c2d71ac407298e14663dc
[debian/amanda] / server-src / taper.pl
1 #! @PERL@
2 # Copyright (c) 2009, 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 package main;
25
26 use Amanda::Util qw( :constants );
27 use Amanda::Config qw( :init :getconf );
28 use Amanda::Logfile qw( :logtype_t log_add $amanda_log_trace_log );
29 use Amanda::Debug qw( debug );
30 use Amanda::Taper::Controller;
31 use Getopt::Long;
32
33 Amanda::Util::setup_application("taper", "server", $CONTEXT_DAEMON);
34
35 my $config_overrides = new_config_overrides($#ARGV+1);
36
37 debug("Arguments: " . join(' ', @ARGV));
38 Getopt::Long::Configure(qw{bundling});
39 GetOptions(
40     'version' => \&Amanda::Util::version_opt,
41     'o=s' => sub { add_config_override_opt($config_overrides, $_[1]); },
42 ) or usage();
43
44 if (@ARGV != 1) {
45     die "USAGE: taper <config> <config-overwrites>";
46 }
47
48 set_config_overrides($config_overrides);
49 config_init($CONFIG_INIT_EXPLICIT_NAME, $ARGV[0]);
50 my ($cfgerr_level, @cfgerr_errors) = config_errors();
51 if ($cfgerr_level >= $CFGERR_WARNINGS) {
52     config_print_errors();
53     if ($cfgerr_level >= $CFGERR_ERRORS) {
54         die "Errors processing config file";
55     }
56 }
57
58 # our STDERR is connected to the amdump log file, so be sure to do unbuffered
59 # writes to that file
60 my $old_fh = select(STDERR);
61 $| = 1;
62 select($old_fh);
63
64 log_add($L_INFO, "taper pid $$");
65 Amanda::Debug::add_amanda_log_handler($amanda_log_trace_log);
66
67 Amanda::Util::finish_setup($RUNNING_AS_DUMPUSER);
68
69 my $tlf = Amanda::Config::config_dir_relative(getconf($CNF_TAPELIST));
70 my $tl = Amanda::Tapelist->new($tlf);
71 # transfer control to the Amanda::Taper::Controller class implemented above
72 my $controller = Amanda::Taper::Controller->new(tapelist => $tl);
73 $controller->start();
74 Amanda::MainLoop::run();
75
76 log_add($L_INFO, "pid-done $$");
77 Amanda::Util::finish_application();