2 # Copyright (c) 2010-2012 Zmanda Inc. All Rights Reserved.
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
9 # This program is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 # You should have received a copy of the GNU General Public License along
15 # with this program; if not, write to the Free Software Foundation, Inc.,
16 # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 # Contact information: Zmanda Inc., 465 S. Mathilda Ave., Suite 300
19 # Sunnyvale, CA 94086, USA, or: http://www.zmanda.com
21 use lib '@amperldir@';
29 use Amanda::Util qw( :constants );
30 use Amanda::Config qw( :init :getconf );
32 use Amanda::Util qw ( match_disk );
33 use Amanda::Debug qw( debug );
35 Amanda::Util::setup_application("amdump_client", "client", $CONTEXT_CMDLINE);
38 my $config_overrides = new_config_overrides($#ARGV+1);
40 debug("Arguments: " . join(' ', @ARGV));
41 Getopt::Long::Configure(qw{bundling});
43 'version' => \&Amanda::Util::version_opt,
44 'config=s' => sub { $config = $_[1]; },
45 'o=s' => sub { add_config_override_opt($config_overrides, $_[1]); },
49 die "USAGE: amdump_client [--config <config>] <config-overwrites> [list|dump|check] <diskname>";
54 set_config_overrides($config_overrides);
55 config_init($CONFIG_INIT_CLIENT, undef);
56 $config = getconf($CNF_CONF) if !defined $config;
57 print "config: $config\n";
58 config_init($CONFIG_INIT_CLIENT | $CONFIG_INIT_EXPLICIT_NAME | $CONFIG_INIT_OVERLAY, $config);
59 my ($cfgerr_level, @cfgerr_errors) = config_errors();
60 if ($cfgerr_level >= $CFGERR_WARNINGS) {
61 config_print_errors();
62 if ($cfgerr_level >= $CFGERR_ERRORS) {
63 die "Errors processing config file";
67 #Amanda::Debug::add_amanda_log_handler($amanda_log_trace_log);
69 Amanda::Util::finish_setup($RUNNING_AS_DUMPUSER);
71 my $amservice = $sbindir . '/amservice';
72 my $amdump_server = getconf($CNF_AMDUMP_SERVER);
73 my $auth = getconf($CNF_AUTH);
75 my @cmd = ($amservice, '-f', '/dev/null', '-s', $amdump_server, $auth, 'amdumpd');
80 my $err = Symbol::gensym;
81 my $pid = open3($amservice_in, $amservice_out, $err, @cmd);
84 debug("send: CONFIG $config");
85 print {$amservice_in} "CONFIG $config\n";
88 print {$amservice_in} "LIST\n";
90 } elsif ($cmd eq 'dump') {
91 # check if diskname on the command line
95 print {$amservice_in} "LIST\n";
98 #find the diskname that match
99 for (my $i=1; $i <= $#ARGV; $i++) {
100 for my $diskname (@disks) {
101 if (match_disk($ARGV[$i], $diskname)) {
102 debug("send: DISK " . Amanda::Util::quote_string($diskname));
103 print {$amservice_in} "DISK " . Amanda::Util::quote_string($diskname) . "\n";
104 my $a = <$amservice_out>;
105 print if ($a !~ /^DISK /)
111 print {$amservice_in} "DUMP\n";
113 } elsif ($cmd eq 'check') {
114 # check if diskname on the command line
116 # get the list of dle
117 debug ("send: LIST");
118 print {$amservice_in} "LIST\n";
121 #find the diskname that match
122 for (my $i=1; $i <= $#ARGV; $i++) {
123 for my $diskname (@disks) {
124 if (match_disk($ARGV[$i], $diskname)) {
125 debug("send: DISK " . Amanda::Util::quote_string($diskname));
126 print {$amservice_in} "DISK " . Amanda::Util::quote_string($diskname) . "\n";
127 my $a = <$amservice_out>;
128 print if ($a != /^DISK /)
133 debug("send: CHECK");
134 print {$amservice_in} "CHECK\n";
140 print {$amservice_in} "END\n";
145 while (<$amservice_out>) {
147 return if /^ENDLIST/;
150 push @disks, Amanda::Util::unquote_string($_);
154 sub get_server_data {
155 while (<$amservice_out>) {
157 print "The backup is finished\n";
161 print "The check is finished\n";
171 print STDERR "USAGE: amdump_client [--config <config>] <config-overwrites> [list|dump|check] <diskname>";
174 Amanda::Util::finish_application();