2 # Copyright (c) 2009, 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@';
25 package Amanda::Application::Amraw;
26 use base qw(Amanda::Application);
31 use Amanda::Constants;
32 use Amanda::Debug qw( :logging );
37 my ($config, $host, $disk, $device, $level, $index, $message, $collection, $record, $calcsize, $include_list, $exclude_list, $directory) = @_;
38 my $self = $class->SUPER::new($config);
40 $self->{config} = $config;
41 $self->{host} = $host;
43 $self->{disk} = $disk;
45 $self->{disk} = $device;
47 if (defined $device) {
48 $self->{device} = $device;
50 $self->{device} = $disk;
52 $self->{level} = [ @{$level} ];
53 $self->{index} = $index;
54 $self->{message} = $message;
55 $self->{collection} = $collection;
56 $self->{record} = $record;
57 $self->{calcsize} = $calcsize;
58 $self->{exclude_list} = [ @{$exclude_list} ];
59 $self->{include_list} = [ @{$include_list} ];
60 $self->{directory} = $directory;
71 print "MAX-LEVEL 0\n";
72 print "INDEX-LINE YES\n";
73 print "INDEX-XML NO\n";
74 print "MESSAGE-LINE YES\n";
75 print "MESSAGE-XML NO\n";
77 print "COLLECTION NO\n";
78 print "MULTI-ESTIMATE NO\n";
79 print "CALCSIZE NO\n";
80 print "CLIENT-ESTIMATE YES\n";
83 sub command_selfcheck {
86 print "OK " . $self->{disk} . "\n";
87 print "OK " . $self->{device} . "\n";
89 if (! -r $self->{device}) {
90 $self->print_to_server("$self->{device} can't be read",
91 $Amanda::Script_App::ERROR);
94 if ($#{$self->{include_list}} >= 0) {
95 $self->print_to_server("include-list not supported for backup",
96 $Amanda::Script_App::ERROR);
98 if ($#{$self->{exclude_list}} >= 0) {
99 $self->print_to_server("exclude-list not supported for backup",
100 $Amanda::Script_App::ERROR);
102 if ($self->{directory}) {
103 $self->print_to_server("directory PROPERTY not supported for backup",
104 $Amanda::Script_App::ERROR);
111 sub command_estimate {
114 my $level = $self->{level}[0];
117 $self->print_to_server("amraw can only do level 0 backup",
118 $Amanda::Script_App::ERROR);
121 if ($#{$self->{include_list}} >= 0) {
122 $self->print_to_server("include-list not supported for backup",
123 $Amanda::Script_App::ERROR);
125 if ($#{$self->{include_list}} >= 0) {
126 $self->print_to_server("exclude-list not supported for backup",
127 $Amanda::Script_App::ERROR);
129 if ($self->{directory}) {
130 $self->print_to_server("directory PROPERTY not supported for backup",
131 $Amanda::Script_App::ERROR);
134 my $fd = POSIX::open($self->{device}, &POSIX::O_RDONLY);
138 while (($s = POSIX::read($fd, $buffer, 32768)) > 0) {
142 output_size($level, $size);
149 print "$level -1 -1\n";
152 my($ksize) = int $size / (1024);
153 $ksize=32 if ($ksize<32);
154 print "$level $ksize 1\n";
161 my $level = $self->{level}[0];
163 if (defined($self->{index})) {
164 $self->{'index_out'} = IO::Handle->new_from_fd(4, 'w');
165 $self->{'index_out'} or confess("Could not open index fd");
169 $self->print_to_server("amraw can only do level 0 backup",
170 $Amanda::Script_App::ERROR);
173 if ($#{$self->{include_list}} >= 0) {
174 $self->print_to_server("include-list not supported for backup",
175 $Amanda::Script_App::ERROR);
177 if ($#{$self->{include_list}} >= 0) {
178 $self->print_to_server("exclude-list not supported for backup",
179 $Amanda::Script_App::ERROR);
181 if ($self->{directory}) {
182 $self->print_to_server("directory PROPERTY not supported for backup",
183 $Amanda::Script_App::ERROR);
186 my $fd = POSIX::open($self->{device}, &POSIX::O_RDONLY);
191 while (($s = POSIX::read($fd, $buffer, 32768)) > 0) {
192 Amanda::Util::full_write($out, $buffer, $s);
197 if (defined($self->{index})) {
198 $self->{'index_out'}->print("/\n");
199 $self->{'index_out'}->close;
202 my $ksize = $size / 1024;
206 print {$self->{mesgout}} "sendbackup: size $ksize\n";
207 print {$self->{mesgout}} "sendbackup: end\n";
213 sub command_restore {
217 my $device = $self->{device};
218 if (defined $self->{directory}) {
219 $device = $self->{directory};
221 chdir(Amanda::Util::get_original_cwd());
224 # include-list and exclude-list are ignored, the complete dle is restored.
226 $device = "amraw-restored" if !defined $device;
228 my $fd = POSIX::open($device, &POSIX::O_CREAT | &POSIX::O_RDWR, 0600 );
230 $self->print_to_server_and_die("Can't open '$device': $!",
231 $Amanda::Script_App::ERROR);
237 while (($s = POSIX::read($in, $buffer, 32768)) > 0) {
238 Amanda::Util::full_write($fd, $buffer, $s);
246 sub command_validate {
249 $self->default_validate();
256 Usage: amraw <command> --config=<config> --host=<host> --disk=<disk> --device=<device> --level=<level> --index=<yes|no> --message=<text> --collection=<no> --record=<yes|no> --calcsize.
272 my @opt_include_list;
273 my @opt_exclude_list;
276 Getopt::Long::Configure(qw{bundling});
278 'version' => \$opt_version,
279 'config=s' => \$opt_config,
280 'host=s' => \$opt_host,
281 'disk=s' => \$opt_disk,
282 'device=s' => \$opt_device,
283 'level=s' => \@opt_level,
284 'index=s' => \$opt_index,
285 'message=s' => \$opt_message,
286 'collection=s' => \$opt_collection,
287 'record' => \$opt_record,
288 'calcsize' => \$opt_calcsize,
289 'include-list=s' => \@opt_include_list,
290 'exclude-list=s' => \@opt_exclude_list,
291 'directory' => \$opt_directory,
294 if (defined $opt_version) {
295 print "amraw-" . $Amanda::Constants::VERSION , "\n";
299 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);
301 $application->do($ARGV[0]);