2 # Copyright (c) 2009-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@';
26 package Amanda::Application::Amraw;
27 use base qw(Amanda::Application);
32 use Amanda::Constants;
33 use Amanda::Debug qw( :logging );
34 use Amanda::Util qw( quote_string );
38 my ($config, $host, $disk, $device, $level, $index, $message, $collection, $record, $calcsize, $include_list, $exclude_list, $directory) = @_;
39 my $self = $class->SUPER::new($config);
41 $self->{config} = $config;
42 $self->{host} = $host;
44 $self->{disk} = $disk;
46 $self->{disk} = $device;
48 if (defined $device) {
49 $self->{device} = $device;
51 $self->{device} = $disk;
53 $self->{level} = [ @{$level} ];
54 $self->{index} = $index;
55 $self->{message} = $message;
56 $self->{collection} = $collection;
57 $self->{record} = $record;
58 $self->{calcsize} = $calcsize;
59 $self->{exclude_list} = [ @{$exclude_list} ];
60 $self->{include_list} = [ @{$include_list} ];
61 $self->{directory} = $directory;
72 print "MAX-LEVEL 0\n";
73 print "INDEX-LINE YES\n";
74 print "INDEX-XML NO\n";
75 print "MESSAGE-LINE YES\n";
76 print "MESSAGE-XML NO\n";
78 print "COLLECTION NO\n";
79 print "MULTI-ESTIMATE NO\n";
80 print "CALCSIZE NO\n";
81 print "CLIENT-ESTIMATE YES\n";
84 sub command_selfcheck {
87 $self->print_to_server("disk " . quote_string($self->{disk}),
88 $Amanda::Script_App::GOOD)
89 if defined $self->{disk};
91 $self->print_to_server("amraw version " . $Amanda::Constants::VERSION,
92 $Amanda::Script_App::GOOD);
94 $self->print_to_server(quote_string($self->{device}),
95 $Amanda::Script_App::GOOD)
96 if defined $self->{device};
98 if (! -r $self->{device}) {
99 $self->print_to_server("$self->{device} can't be read",
100 $Amanda::Script_App::ERROR);
103 if ($#{$self->{include_list}} >= 0) {
104 $self->print_to_server("include-list not supported for backup",
105 $Amanda::Script_App::ERROR);
107 if ($#{$self->{exclude_list}} >= 0) {
108 $self->print_to_server("exclude-list not supported for backup",
109 $Amanda::Script_App::ERROR);
111 if ($self->{directory}) {
112 $self->print_to_server("directory PROPERTY not supported for backup",
113 $Amanda::Script_App::ERROR);
120 sub command_estimate {
123 my $level = $self->{level}[0];
126 $self->print_to_server("amraw can only do level 0 backup",
127 $Amanda::Script_App::ERROR);
130 if ($#{$self->{include_list}} >= 0) {
131 $self->print_to_server("include-list not supported for backup",
132 $Amanda::Script_App::ERROR);
134 if ($#{$self->{include_list}} >= 0) {
135 $self->print_to_server("exclude-list not supported for backup",
136 $Amanda::Script_App::ERROR);
138 if ($self->{directory}) {
139 $self->print_to_server("directory PROPERTY not supported for backup",
140 $Amanda::Script_App::ERROR);
143 my $fd = POSIX::open($self->{device}, &POSIX::O_RDONLY);
147 while (($s = POSIX::read($fd, $buffer, 32768)) > 0) {
151 output_size($level, $size);
158 print "$level -1 -1\n";
161 my($ksize) = int $size / (1024);
162 $ksize=32 if ($ksize<32);
163 print "$level $ksize 1\n";
170 my $level = $self->{level}[0];
172 if (defined($self->{index})) {
173 $self->{'index_out'} = IO::Handle->new_from_fd(4, 'w');
174 $self->{'index_out'} or confess("Could not open index fd");
178 $self->print_to_server("amraw can only do level 0 backup",
179 $Amanda::Script_App::ERROR);
182 if ($#{$self->{include_list}} >= 0) {
183 $self->print_to_server("include-list not supported for backup",
184 $Amanda::Script_App::ERROR);
186 if ($#{$self->{include_list}} >= 0) {
187 $self->print_to_server("exclude-list not supported for backup",
188 $Amanda::Script_App::ERROR);
190 if ($self->{directory}) {
191 $self->print_to_server("directory PROPERTY not supported for backup",
192 $Amanda::Script_App::ERROR);
195 my $fd = POSIX::open($self->{device}, &POSIX::O_RDONLY);
200 while (($s = POSIX::read($fd, $buffer, 32768)) > 0) {
201 Amanda::Util::full_write($out, $buffer, $s);
206 if (defined($self->{index})) {
207 $self->{'index_out'}->print("/\n");
208 $self->{'index_out'}->close;
211 my $ksize = $size / 1024;
215 print {$self->{mesgout}} "sendbackup: size $ksize\n";
216 print {$self->{mesgout}} "sendbackup: end\n";
222 sub command_restore {
226 my $device = $self->{device};
227 if (defined $self->{directory}) {
228 $device = $self->{directory};
230 chdir(Amanda::Util::get_original_cwd());
233 # include-list and exclude-list are ignored, the complete dle is restored.
235 $device = "amraw-restored" if !defined $device;
237 my $fd = POSIX::open($device, &POSIX::O_CREAT | &POSIX::O_RDWR, 0600 );
239 $self->print_to_server_and_die("Can't open '$device': $!",
240 $Amanda::Script_App::ERROR);
246 while (($s = POSIX::read($in, $buffer, 32768)) > 0) {
247 Amanda::Util::full_write($fd, $buffer, $s);
255 sub command_validate {
258 $self->default_validate();
265 Usage: amraw <command> --config=<config> --host=<host> --disk=<disk> --device=<device> --level=<level> --index=<yes|no> --message=<text> --collection=<no> --record=<yes|no> --calcsize.
281 my @opt_include_list;
282 my @opt_exclude_list;
285 Getopt::Long::Configure(qw{bundling});
287 'version' => \$opt_version,
288 'config=s' => \$opt_config,
289 'host=s' => \$opt_host,
290 'disk=s' => \$opt_disk,
291 'device=s' => \$opt_device,
292 'level=s' => \@opt_level,
293 'index=s' => \$opt_index,
294 'message=s' => \$opt_message,
295 'collection=s' => \$opt_collection,
296 'record' => \$opt_record,
297 'calcsize' => \$opt_calcsize,
298 'include-list=s' => \@opt_include_list,
299 'exclude-list=s' => \@opt_exclude_list,
300 'directory' => \$opt_directory,
303 if (defined $opt_version) {
304 print "amraw-" . $Amanda::Constants::VERSION , "\n";
308 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);
310 $application->do($ARGV[0]);