#!@PERL@
-# Copyright (c) 2008,2009 Zmanda, Inc. All Rights Reserved.
+# Copyright (c) 2008, 2009, 2010 Zmanda, Inc. All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 as published
use lib '@amperldir@';
use strict;
+use warnings;
use Getopt::Long;
package Amanda::Application::Amsamba;
#on exit:
# $self->{exclude}
# $self->{include}
+# $self->{include_filename}
sub validate_inexclude {
my $self = shift;
}
close(FF);
}
- if ($#{$self->{include_file}} >= 0) {
- $self->{include} = [ @{$self->{include_file}} ];
- }
- foreach my $file (@{$self->{include_list}}) {
- if (!open(FF, $file)) {
- if ($self->{action} eq 'check' && !$self->{include_optional}) {
- $self->print_to_server("Open of '$file' failed: $!",
- $Amanda::Script_App::ERROR);
+
+ if ($self->{action} eq "restore" and defined $self->{'include_list'}) {
+ # put all include in a single file $self->{'include_filename'}
+ $self->{'include_filename'} = "$AMANDA_TMPDIR/amsamba.$$.include";
+ open INC_FILE, ">$self->{'include_filename'}";
+ if ($#{$self->{include_file}} >= 0) {
+ print INC_FILE "$self->{include_file}\n";
+ }
+ foreach my $file (@{$self->{include_list}}) {
+ if (!open(FF, $file)) {
+ if ($self->{action} eq 'check' && !$self->{include_optional}) {
+ $self->print_to_server("Open of '$file' failed: $!",
+ $Amanda::Script_App::ERROR);
+ }
+ next;
}
- next;
+ while (<FF>) {
+ print INC_FILE;
+ }
+ close(FF);
}
- while (<FF>) {
- chomp;
- push @{$self->{include}}, $_;
+
+ # add command line include for amrestore
+ for(my $i=1;defined $ARGV[$i]; $i++) {
+ my $param = $ARGV[$i];
+ $param =~ /^(.*)$/;
+ print INC_FILE "$1\n";
+ }
+
+ close INC_FILE;
+ } else {
+ # put all include in $self->{'include'} they will be added on
+ # command line.
+ if ($#{$self->{include_file}} >= 0) {
+ $self->{include} = [ @{$self->{include_file}} ];
+ }
+
+ foreach my $file (@{$self->{include_list}}) {
+ if (!open(FF, $file)) {
+ if ($self->{action} eq 'check' && !$self->{include_optional}) {
+ $self->print_to_server("Open of '$file' failed: $!",
+ $Amanda::Script_App::ERROR);
+ }
+ next;
+ }
+ while (<FF>) {
+ chomp;
+ push @{$self->{include}}, $_;
+ }
+ close(FF);
+ }
+
+ # add command line include for amrestore
+ if ($self->{action} eq "restore") {
+ for(my $i=1;defined $ARGV[$i]; $i++) {
+ my $param = $ARGV[$i];
+ $param =~ /^(.*)$/;
+ push @{$self->{include}}, $1;
+ }
}
- close(FF);
}
}
while ($line = <$amandapass>) {
chomp $line;
next if $line =~ /^#/;
- my ($diskname, $userpasswd, $domain, $extra);
- ($diskname, $userpasswd) = Amanda::Util::skip_quoted_string($line);
- if ($userpasswd) {
- ($userpasswd, $domain) =
- Amanda::Util::skip_quoted_string($userpasswd);
- }
- if ($domain) {
- ($domain, $extra) =
- Amanda::Util::skip_quoted_string($domain);
- }
+ my ($diskname, $userpasswd, $domain, $extra) = Amanda::Util::split_quoted_string_friendly($line);
if ($extra) {
debug("Trailling characters ignored in amandapass line");
}
- $diskname = Amanda::Util::unquote_string($diskname);
- $userpasswd = Amanda::Util::unquote_string($userpasswd);
- $domain = Amanda::Util::unquote_string($domain);
if (defined $diskname &&
($diskname eq '*' ||
($self->{unc}==0 && $diskname =~ m,^(//[^/]+)/\*$, && $1 eq $self->{cifshost}) ||
$diskname eq $self->{share} ||
$diskname eq $self->{sambashare})) {
if (defined $userpasswd && $userpasswd ne "") {
- $self->{domain} = $domain if ($domain ne "");
+ $self->{domain} = $domain if defined $domain && $domain ne "";
my ($username, $password) = split('%', $userpasswd, 2);
$self->{username} = $username;
$self->{password} = $password;
sub command_selfcheck {
my $self = shift;
+ $self->print_to_server("disk " . quote_string($self->{disk}));
+
+ $self->print_to_server("amsamba version " . $Amanda::Constants::VERSION,
+ $Amanda::Script_App::GOOD);
#check binary
if (!defined($self->{smbclient}) || $self->{smbclient} eq "") {
$self->print_to_server(
elsif (! -x $self->{smbclient}) {
$self->print_to_server("$self->{smbclient} is not executable",
$Amanda::Script_App::ERROR);
+ } else {
+ my @sv = `$self->{smbclient} --version`;
+ if ($? >> 8 == 0) {
+ $sv[0] =~ /^[^0-9]*(.*)$/;
+ my $sv = $1;
+ $self->print_to_server("amsamba smbclient-version $sv",
+ $Amanda::Script_App::GOOD);
+ } else {
+ $self->print_to_server(
+ "[Can't get " . $self->{smbclient} . " version]\n",
+ $Amanda::Script_App::ERROR);
+ }
}
+
$self->print_to_server("$self->{smbclient}",
$Amanda::Script_App::GOOD);
if (!defined $self->{disk} || !defined $self->{device}) {
$self->validate_inexclude();
print "OK " . $self->{share} . "\n";
- print "OK " . $self->{disk} . "\n";
print "OK " . $self->{device} . "\n";
print "OK " . $self->{directory} . "\n" if defined $self->{directory};
my $self = shift;
my $level = $self->{level}[0];
- my $mesgout_fd;
- open($mesgout_fd, '>&=3') ||
- $self->print_to_server_and_die("Can't open mesgout_fd: $!",
- $Amanda::Script_App::ERROR);
- $self->{mesgout} = $mesgout_fd;
$self->parsesharename();
$self->findpass();
open($indexout_fd, '>&=4') ||
$self->print_to_server_and_die("Can't open indexout_fd: $!",
$Amanda::Script_App::ERROR);
- $self->parse_backup($index, $mesgout_fd, $indexout_fd);
+ $self->parse_backup($index, $self->{mesgout}, $indexout_fd);
close($indexout_fd);
}
else {
- $self->parse_backup($index_fd, $mesgout_fd, undef);
+ $self->parse_backup($index_fd, $self->{mesgout}, undef);
}
close($index);
if ($ksize < 32) {
$ksize = 32;
}
- print $mesgout_fd "sendbackup: size $ksize\n";
- print $mesgout_fd "sendbackup: end\n";
+ print {$self->{mesgout}} "sendbackup: size $ksize\n";
+ print {$self->{mesgout}} "sendbackup: end\n";
}
waitpid $pid, 0;
if (defined $self->{domain}) {
push @cmd, "-W", $self->{domain};
}
- push @cmd, "-Tx", "-";
- if ($#{$self->{include}} >= 0) {
- push @cmd, @{$self->{include}};
- }
- for(my $i=1;defined $ARGV[$i]; $i++) {
- my $param = $ARGV[$i];
- $param =~ /^(.*)$/;
- push @cmd, $1;
+ if (defined $self->{'include_filename'}) {
+ push @cmd, "-TFx", "-", "$self->{'include_filename'}";
+ } else {
+ push @cmd, "-Tx", "-";
+ if ($#{$self->{include}} >= 0) {
+ push @cmd, @{$self->{include}};
+ }
+ for(my $i=1;defined $ARGV[$i]; $i++) {
+ my $param = $ARGV[$i];
+ $param =~ /^(.*)$/;
+ push @cmd, $1;
+ }
}
my ($parent_rdr, $child_wtr);
if (defined $self->{password}) {