2 # Copyright (c) 2010 Zmanda Inc. All Rights Reserved.
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.
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
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
17 # Contact information: Zmanda Inc., 465 S. Mathilda Ave., Suite 300
18 # Sunnyvale, CA 94086, USA, or: http://www.zmanda.com
20 use lib '@amperldir@';
28 use Amanda::Util qw( :constants );
29 use Amanda::Config qw( :init :getconf );
31 use Amanda::Logfile qw( log_rename get_current_log_timestamp $amanda_log_trace_log );
32 use Amanda::Debug qw( debug );
34 Amanda::Util::setup_application("amdump_client", "client", $CONTEXT_CMDLINE);
37 my $config_overrides = new_config_overrides($#ARGV+1);
38 Getopt::Long::Configure(qw{bundling});
40 'config=s' => sub { $config = $_[1]; },
41 'o=s' => sub { add_config_override_opt($config_overrides, $_[1]); },
45 die "USAGE: amdump_client [--config <config>] <config-overwrites> [list|dump|check] <diskname>";
50 set_config_overrides($config_overrides);
51 config_init($CONFIG_INIT_CLIENT, undef);
52 $config = getconf($CNF_CONF) if !defined $config;
53 print "config: $config\n";
54 config_init($CONFIG_INIT_CLIENT | $CONFIG_INIT_EXPLICIT_NAME | $CONFIG_INIT_OVERLAY, $config);
55 my ($cfgerr_level, @cfgerr_errors) = config_errors();
56 if ($cfgerr_level >= $CFGERR_WARNINGS) {
57 config_print_errors();
58 if ($cfgerr_level >= $CFGERR_ERRORS) {
59 die "Errors processing config file";
63 #Amanda::Debug::add_amanda_log_handler($amanda_log_trace_log);
65 Amanda::Util::finish_setup($RUNNING_AS_DUMPUSER);
67 my $amservice = $sbindir . '/amservice';
68 my $amdump_server = getconf($CNF_AMDUMP_SERVER);
69 my $auth = getconf($CNF_AUTH);
71 my @cmd = ($amservice, '-f', '/dev/null', '-s', $amdump_server, $auth, 'amdumpd');
76 my $err = Symbol::gensym;
77 my $pid = open3($amservice_in, $amservice_out, $err, @cmd);
80 debug("send: CONFIG $config");
81 print {$amservice_in} "CONFIG $config\n";
84 print {$amservice_in} "LIST\n";
86 } elsif ($cmd eq 'dump') {
87 # check if diskname on the command line
91 print {$amservice_in} "LIST\n";
94 #find the diskname that match
95 for (my $i=1; $i <= $#ARGV; $i++) {
96 for my $diskname (@disks) {
97 if (Amanda::Logfile::match_disk($ARGV[$i], $diskname)) {
98 debug("send: DISK " . Amanda::Util::quote_string($diskname));
99 print {$amservice_in} "DISK " . Amanda::Util::quote_string($diskname) . "\n";
100 my $a = <$amservice_out>;
101 print if ($a != /^DISK /)
107 print {$amservice_in} "DUMP\n";
109 } elsif ($cmd eq 'check') {
110 # check if diskname on the command line
112 # get the list of dle
113 debug ("send: LIST");
114 print {$amservice_in} "LIST\n";
117 #find the diskname that match
118 for (my $i=1; $i <= $#ARGV; $i++) {
119 for my $diskname (@disks) {
120 if (Amanda::Logfile::match_disk($ARGV[$i], $diskname)) {
121 debug("send: DISK " . Amanda::Util::quote_string($diskname));
122 print {$amservice_in} "DISK " . Amanda::Util::quote_string($diskname) . "\n";
123 my $a = <$amservice_out>;
124 print if ($a != /^DISK /)
129 debug("send: CHECK");
130 print {$amservice_in} "CHECK\n";
136 print {$amservice_in} "END\n";
141 while (<$amservice_out>) {
143 return if /^ENDLIST/;
146 push @disks, Amanda::Util::unquote_string($_);
150 sub get_server_data {
151 while (<$amservice_out>) {
153 print "The backup is finished\n";
157 print "The check is finished\n";
167 print STDERR "USAGE: amdump_client [--config <config>] <config-overwrites> [list|dump|check] <diskname>";
170 Amanda::Util::finish_application();