2 # Copyright (c) 2010-2012 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::Util qw ( match_disk );
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);
39 debug("Arguments: " . join(' ', @ARGV));
40 Getopt::Long::Configure(qw{bundling});
42 'version' => \&Amanda::Util::version_opt,
43 'config=s' => sub { $config = $_[1]; },
44 'o=s' => sub { add_config_override_opt($config_overrides, $_[1]); },
48 die "USAGE: amdump_client [--config <config>] <config-overwrites> [list|dump|check] <diskname>";
53 set_config_overrides($config_overrides);
54 config_init($CONFIG_INIT_CLIENT, undef);
55 $config = getconf($CNF_CONF) if !defined $config;
56 print "config: $config\n";
57 config_init($CONFIG_INIT_CLIENT | $CONFIG_INIT_EXPLICIT_NAME | $CONFIG_INIT_OVERLAY, $config);
58 my ($cfgerr_level, @cfgerr_errors) = config_errors();
59 if ($cfgerr_level >= $CFGERR_WARNINGS) {
60 config_print_errors();
61 if ($cfgerr_level >= $CFGERR_ERRORS) {
62 die "Errors processing config file";
66 #Amanda::Debug::add_amanda_log_handler($amanda_log_trace_log);
68 Amanda::Util::finish_setup($RUNNING_AS_DUMPUSER);
70 my $amservice = $sbindir . '/amservice';
71 my $amdump_server = getconf($CNF_AMDUMP_SERVER);
72 my $auth = getconf($CNF_AUTH);
74 my @cmd = ($amservice, '-f', '/dev/null', '-s', $amdump_server, $auth, 'amdumpd');
79 my $err = Symbol::gensym;
80 my $pid = open3($amservice_in, $amservice_out, $err, @cmd);
83 debug("send: CONFIG $config");
84 print {$amservice_in} "CONFIG $config\n";
87 print {$amservice_in} "LIST\n";
89 } elsif ($cmd eq 'dump') {
90 # check if diskname on the command line
94 print {$amservice_in} "LIST\n";
97 #find the diskname that match
98 for (my $i=1; $i <= $#ARGV; $i++) {
99 for my $diskname (@disks) {
100 if (match_disk($ARGV[$i], $diskname)) {
101 debug("send: DISK " . Amanda::Util::quote_string($diskname));
102 print {$amservice_in} "DISK " . Amanda::Util::quote_string($diskname) . "\n";
103 my $a = <$amservice_out>;
104 print if ($a !~ /^DISK /)
110 print {$amservice_in} "DUMP\n";
112 } elsif ($cmd eq 'check') {
113 # check if diskname on the command line
115 # get the list of dle
116 debug ("send: LIST");
117 print {$amservice_in} "LIST\n";
120 #find the diskname that match
121 for (my $i=1; $i <= $#ARGV; $i++) {
122 for my $diskname (@disks) {
123 if (match_disk($ARGV[$i], $diskname)) {
124 debug("send: DISK " . Amanda::Util::quote_string($diskname));
125 print {$amservice_in} "DISK " . Amanda::Util::quote_string($diskname) . "\n";
126 my $a = <$amservice_out>;
127 print if ($a != /^DISK /)
132 debug("send: CHECK");
133 print {$amservice_in} "CHECK\n";
139 print {$amservice_in} "END\n";
144 while (<$amservice_out>) {
146 return if /^ENDLIST/;
149 push @disks, Amanda::Util::unquote_string($_);
153 sub get_server_data {
154 while (<$amservice_out>) {
156 print "The backup is finished\n";
160 print "The check is finished\n";
170 print STDERR "USAGE: amdump_client [--config <config>] <config-overwrites> [list|dump|check] <diskname>";
173 Amanda::Util::finish_application();