2 # Copyright (c) 2009-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@';
25 package Amanda::Application::Amraw;
26 use base qw(Amanda::Application);
31 use Amanda::Constants;
32 use Amanda::Debug qw( :logging );
33 use Amanda::Util qw( quote_string );
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 $self->print_to_server("disk " . quote_string($self->{disk}),
87 $Amanda::Script_App::GOOD)
88 if defined $self->{disk};
90 $self->print_to_server("amraw version " . $Amanda::Constants::VERSION,
91 $Amanda::Script_App::GOOD);
93 $self->print_to_server(quote_string($self->{device}),
94 $Amanda::Script_App::GOOD)
95 if defined $self->{device};
97 if (! -r $self->{device}) {
98 $self->print_to_server("$self->{device} can't be read",
99 $Amanda::Script_App::ERROR);
102 if ($#{$self->{include_list}} >= 0) {
103 $self->print_to_server("include-list not supported for backup",
104 $Amanda::Script_App::ERROR);
106 if ($#{$self->{exclude_list}} >= 0) {
107 $self->print_to_server("exclude-list not supported for backup",
108 $Amanda::Script_App::ERROR);
110 if ($self->{directory}) {
111 $self->print_to_server("directory PROPERTY not supported for backup",
112 $Amanda::Script_App::ERROR);
119 sub command_estimate {
122 my $level = $self->{level}[0];
125 $self->print_to_server("amraw can only do level 0 backup",
126 $Amanda::Script_App::ERROR);
129 if ($#{$self->{include_list}} >= 0) {
130 $self->print_to_server("include-list not supported for backup",
131 $Amanda::Script_App::ERROR);
133 if ($#{$self->{include_list}} >= 0) {
134 $self->print_to_server("exclude-list not supported for backup",
135 $Amanda::Script_App::ERROR);
137 if ($self->{directory}) {
138 $self->print_to_server("directory PROPERTY not supported for backup",
139 $Amanda::Script_App::ERROR);
142 my $fd = POSIX::open($self->{device}, &POSIX::O_RDONLY);
146 while (($s = POSIX::read($fd, $buffer, 32768)) > 0) {
150 output_size($level, $size);
157 print "$level -1 -1\n";
160 my($ksize) = int $size / (1024);
161 $ksize=32 if ($ksize<32);
162 print "$level $ksize 1\n";
169 my $level = $self->{level}[0];
171 if (defined($self->{index})) {
172 $self->{'index_out'} = IO::Handle->new_from_fd(4, 'w');
173 $self->{'index_out'} or confess("Could not open index fd");
177 $self->print_to_server("amraw can only do level 0 backup",
178 $Amanda::Script_App::ERROR);
181 if ($#{$self->{include_list}} >= 0) {
182 $self->print_to_server("include-list not supported for backup",
183 $Amanda::Script_App::ERROR);
185 if ($#{$self->{include_list}} >= 0) {
186 $self->print_to_server("exclude-list not supported for backup",
187 $Amanda::Script_App::ERROR);
189 if ($self->{directory}) {
190 $self->print_to_server("directory PROPERTY not supported for backup",
191 $Amanda::Script_App::ERROR);
194 my $fd = POSIX::open($self->{device}, &POSIX::O_RDONLY);
199 while (($s = POSIX::read($fd, $buffer, 32768)) > 0) {
200 Amanda::Util::full_write($out, $buffer, $s);
205 if (defined($self->{index})) {
206 $self->{'index_out'}->print("/\n");
207 $self->{'index_out'}->close;
210 my $ksize = $size / 1024;
214 print {$self->{mesgout}} "sendbackup: size $ksize\n";
215 print {$self->{mesgout}} "sendbackup: end\n";
221 sub command_restore {
225 my $device = $self->{device};
226 if (defined $self->{directory}) {
227 $device = $self->{directory};
229 chdir(Amanda::Util::get_original_cwd());
232 # include-list and exclude-list are ignored, the complete dle is restored.
234 $device = "amraw-restored" if !defined $device;
236 my $fd = POSIX::open($device, &POSIX::O_CREAT | &POSIX::O_RDWR, 0600 );
238 $self->print_to_server_and_die("Can't open '$device': $!",
239 $Amanda::Script_App::ERROR);
245 while (($s = POSIX::read($in, $buffer, 32768)) > 0) {
246 Amanda::Util::full_write($fd, $buffer, $s);
254 sub command_validate {
257 $self->default_validate();
264 Usage: amraw <command> --config=<config> --host=<host> --disk=<disk> --device=<device> --level=<level> --index=<yes|no> --message=<text> --collection=<no> --record=<yes|no> --calcsize.
280 my @opt_include_list;
281 my @opt_exclude_list;
284 Getopt::Long::Configure(qw{bundling});
286 'version' => \$opt_version,
287 'config=s' => \$opt_config,
288 'host=s' => \$opt_host,
289 'disk=s' => \$opt_disk,
290 'device=s' => \$opt_device,
291 'level=s' => \@opt_level,
292 'index=s' => \$opt_index,
293 'message=s' => \$opt_message,
294 'collection=s' => \$opt_collection,
295 'record' => \$opt_record,
296 'calcsize' => \$opt_calcsize,
297 'include-list=s' => \@opt_include_list,
298 'exclude-list=s' => \@opt_exclude_list,
299 'directory' => \$opt_directory,
302 if (defined $opt_version) {
303 print "amraw-" . $Amanda::Constants::VERSION , "\n";
307 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);
309 $application->do($ARGV[0]);