2 # Copyright (c) 2009 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@';
24 package Amanda::Application::Amraw;
25 use base qw(Amanda::Application);
30 use Amanda::Constants;
31 use Amanda::Debug qw( :logging );
36 my ($config, $host, $disk, $device, $level, $index, $message, $collection, $record, $calcsize, $include_list, $exclude_list, $directory) = @_;
37 my $self = $class->SUPER::new($config);
39 $self->{config} = $config;
40 $self->{host} = $host;
42 $self->{disk} = $disk;
44 $self->{disk} = $device;
46 if (defined $device) {
47 $self->{device} = $device;
49 $self->{device} = $disk;
51 $self->{level} = [ @{$level} ];
52 $self->{index} = $index;
53 $self->{message} = $message;
54 $self->{collection} = $collection;
55 $self->{record} = $record;
56 $self->{calcsize} = $calcsize;
57 $self->{exclude_list} = [ @{$exclude_list} ];
58 $self->{include_list} = [ @{$include_list} ];
59 $self->{directory} = $directory;
70 print "MAX-LEVEL 0\n";
71 print "INDEX-LINE YES\n";
72 print "INDEX-XML NO\n";
73 print "MESSAGE-LINE YES\n";
74 print "MESSAGE-XML NO\n";
76 print "COLLECTION NO\n";
77 print "MULTI-ESTIMATE NO\n";
78 print "CALCSIZE NO\n";
79 print "CLIENT-ESTIMATE YES\n";
82 sub command_selfcheck {
85 print "OK " . $self->{disk} . "\n";
86 print "OK " . $self->{device} . "\n";
88 if (! -r $self->{device}) {
89 $self->print_to_server("$self->{device} can't be read",
90 $Amanda::Script_App::ERROR);
93 if ($#{$self->{include_list}} >= 0) {
94 $self->print_to_server("include-list not supported for backup",
95 $Amanda::Script_App::ERROR);
97 if ($#{$self->{exclude_list}} >= 0) {
98 $self->print_to_server("exclude-list not supported for backup",
99 $Amanda::Script_App::ERROR);
101 if ($self->{directory}) {
102 $self->print_to_server("directory PROPERTY not supported for backup",
103 $Amanda::Script_App::ERROR);
110 sub command_estimate {
113 my $level = $self->{level}[0];
116 $self->print_to_server("amraw can only do level 0 backup",
117 $Amanda::Script_App::ERROR);
120 if ($#{$self->{include_list}} >= 0) {
121 $self->print_to_server("include-list not supported for backup",
122 $Amanda::Script_App::ERROR);
124 if ($#{$self->{include_list}} >= 0) {
125 $self->print_to_server("exclude-list not supported for backup",
126 $Amanda::Script_App::ERROR);
128 if ($self->{directory}) {
129 $self->print_to_server("directory PROPERTY not supported for backup",
130 $Amanda::Script_App::ERROR);
133 my $fd = POSIX::open($self->{device}, &POSIX::O_RDONLY);
137 while (($s = POSIX::read($fd, $buffer, 32768)) > 0) {
141 output_size($level, $size);
148 print "$level -1 -1\n";
151 my($ksize) = int $size / (1024);
152 $ksize=32 if ($ksize<32);
153 print "$level $ksize 1\n";
160 my $level = $self->{level}[0];
162 open($mesgout_fd, '>&=3') ||
163 $self->print_to_server_and_die("Can't open mesgout_fd: $!",
164 $Amanda::Script_App::ERROR);
165 $self->{mesgout} = $mesgout_fd;
167 if (defined($self->{index})) {
168 $self->{'index_out'} = IO::Handle->new_from_fd(4, 'w');
169 $self->{'index_out'} or confess("Could not open index fd");
173 $self->print_to_server("amraw can only do level 0 backup",
174 $Amanda::Script_App::ERROR);
177 if ($#{$self->{include_list}} >= 0) {
178 $self->print_to_server("include-list not supported for backup",
179 $Amanda::Script_App::ERROR);
181 if ($#{$self->{include_list}} >= 0) {
182 $self->print_to_server("exclude-list not supported for backup",
183 $Amanda::Script_App::ERROR);
185 if ($self->{directory}) {
186 $self->print_to_server("directory PROPERTY not supported for backup",
187 $Amanda::Script_App::ERROR);
190 my $fd = POSIX::open($self->{device}, &POSIX::O_RDONLY);
195 while (($s = POSIX::read($fd, $buffer, 32768)) > 0) {
196 Amanda::Util::full_write($out, $buffer, $s);
201 if (defined($self->{index})) {
202 $self->{'index_out'}->print("/\n");
203 $self->{'index_out'}->close;
206 my $ksize = $size / 1024;
210 print $mesgout_fd "sendbackup: size $ksize\n";
211 print $mesgout_fd "sendbackup: end\n";
217 sub command_restore {
221 my $device = $self->{device};
222 if (defined $self->{directory}) {
223 $device = $self->{directory};
225 chdir(Amanda::Util::get_original_cwd());
228 # include-list and exclude-list are ignored, the complete dle is restored.
230 $device = "amraw-restored" if !defined $device;
232 my $fd = POSIX::open($device, &POSIX::O_CREAT | &POSIX::O_RDWR, 0600 );
234 $self->print_to_server_and_die("Can't open '$device': $!",
235 $Amanda::Script_App::ERROR);
241 while (($s = POSIX::read($in, $buffer, 32768)) > 0) {
242 Amanda::Util::full_write($fd, $buffer, $s);
250 sub command_validate {
253 $self->default_validate();
260 Usage: amraw <command> --config=<config> --host=<host> --disk=<disk> --device=<device> --level=<level> --index=<yes|no> --message=<text> --collection=<no> --record=<yes|no> --calcsize.
276 my @opt_include_list;
277 my @opt_exclude_list;
280 Getopt::Long::Configure(qw{bundling});
282 'version' => \$opt_version,
283 'config=s' => \$opt_config,
284 'host=s' => \$opt_host,
285 'disk=s' => \$opt_disk,
286 'device=s' => \$opt_device,
287 'level=s' => \@opt_level,
288 'index=s' => \$opt_index,
289 'message=s' => \$opt_message,
290 'collection=s' => \$opt_collection,
291 'record' => \$opt_record,
292 'calcsize' => \$opt_calcsize,
293 'include-list=s' => \@opt_include_list,
294 'exclude-list=s' => \@opt_exclude_list,
295 'directory' => \$opt_directory,
298 if (defined $opt_version) {
299 print "amraw-" . $Amanda::Constants::VERSION , "\n";
303 my $application = Amanda::Application::Amraw->new($opt_config, $opt_host, $opt_disk, $opt_device, \@opt_level, $opt_index, $opt_message, $opt_collection, $opt_record, $opt_calcsize, \@opt_include_list, \@opt_exclude_list, $opt_directory);
305 $application->do($ARGV[0]);