update changelog to reflect new upstream version
[debian/amanda] / application-src / amsuntar.pl
index 38ba67856a3c64b05a17753097266cdacc20493e..6cf0cf1db39a91fbe8bded7b384f2d83b3d830b4 100755 (executable)
@@ -1,9 +1,10 @@
 #!@PERL@
-# Copyright (c) 2009 Zmanda, Inc.  All Rights Reserved.
+# Copyright (c) 2009-2012 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
-# by the Free Software Foundation.
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
 #
 # This program is distributed in the hope that it will be useful, but
 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
@@ -19,6 +20,7 @@
 
 use lib '@amperldir@';
 use strict;
+use warnings;
 use Getopt::Long;
 
 package Amanda::Application::Amsuntar;
@@ -34,14 +36,17 @@ use Amanda::Constants;
 use Amanda::Config qw( :init :getconf  config_dir_relative );
 use Amanda::Debug qw( :logging );
 use Amanda::Paths;
-use Amanda::Util qw( :constants );
+use Amanda::Util qw( :constants quote_string );
 
 sub new {
     my $class = shift;
-    my ($config, $host, $disk, $device, $level, $index, $message, $collection, $record, $exclude_list, $exclude_optional,  $include_list, $include_optional, $bsize, $ext_attrib, $ext_header, $ignore, $normal, $strange, $error_exp, $directory) = @_;
+    my ($config, $host, $disk, $device, $level, $index, $message, $collection, $record, $exclude_list, $exclude_optional,  $include_list, $include_optional, $bsize, $ext_attrib, $ext_header, $ignore, $normal, $strange, $error_exp, $directory, $suntar_path) = @_;
     my $self = $class->SUPER::new($config);
 
-    $self->{suntar}            = "/usr/sbin/tar";
+    $self->{suntar}            = $Amanda::Constants::SUNTAR;
+    if (defined $suntar_path) {
+       $self->{suntar}        = $suntar_path;
+    }
     $self->{pfexec}            = "/usr/bin/pfexec";
     $self->{gnutar}            = $Amanda::Constants::GNUTAR;
     $self->{teecount}          = $Amanda::Paths::amlibexecdir."/teecount";
@@ -140,6 +145,11 @@ sub command_support {
 sub command_selfcheck {
    my $self = shift;
 
+   $self->print_to_server("disk " . quote_string($self->{disk}));
+
+   $self->print_to_server("amsuntar version " . $Amanda::Constants::VERSION,
+                         $Amanda::Script_App::GOOD);
+
    if (!-e $self->{suntar}) {
       $self->print_to_server_and_die(
                       "application binary $self->{suntar} doesn't exist",
@@ -153,7 +163,6 @@ sub command_selfcheck {
    if (!defined $self->{disk} || !defined $self->{device}) {
       return;
    }
-   print "OK " . $self->{disk} . "\n";
    print "OK " . $self->{device} . "\n";
    print "OK " . $self->{directory} . "\n" if defined $self->{directory};
    $self->validate_inexclude();
@@ -226,11 +235,6 @@ sub command_backup {
    my $self = shift;
 
    $self->validate_inexclude();
-   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;
 
    my(@cmd) = $self->build_command();
    my(@cmdtc) = $self->{teecount};
@@ -258,11 +262,11 @@ sub command_backup {
       open($indexout_fd, '>&=4') ||
       $self->print_to_server_and_die("Can't open indexout_fd: $!",
                                     $Amanda::Script_App::ERROR);
-      $result = $self->parse_backup($index_fd, $mesgout_fd, $indexout_fd);
+      $result = $self->parse_backup($index_fd, $self->{mesgout}, $indexout_fd);
       close($indexout_fd);
    }
    else {
-      $result = $self->parse_backup($index_fd, $mesgout_fd, undef);
+      $result = $self->parse_backup($index_fd, $self->{mesgout}, undef);
    }
    close($index_fd);
    my $size = <$errtc>;
@@ -276,12 +280,13 @@ sub command_backup {
 
    if ($result == 1) {
        debug("$self->{suntar} returned error" );
-       print $mesgout_fd "sendbackup: error [$self->{suntar} returned error]\n";
+       $self->print_to_server("$self->{suntar} returned error", 
+                             $Amanda::Script_App::ERROR);
    }
 
    my($ksize) = int ($size/1024);
-   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";
    debug("sendbackup: size $ksize "); 
 
    exit 0;
@@ -580,6 +585,7 @@ my @opt_strange;
 my @opt_error;
 my $opt_lang;
 my $opt_directory;
+my $opt_suntar_path;
 
 Getopt::Long::Configure(qw{bundling});
 GetOptions(
@@ -605,12 +611,13 @@ GetOptions(
     'error=s'                => \@opt_error,
     'lang=s'                 => \$opt_lang,
     'directory=s'            => \$opt_directory,
+    'suntar-path=s'          => \$opt_suntar_path,
 ) or usage();
 
 if (defined $opt_lang) {
     $ENV{LANG} = $opt_lang;
 }
 
-my $application = Amanda::Application::Amsuntar->new($opt_config, $opt_host, $opt_disk, $opt_device, $opt_level, $opt_index, $opt_message, $opt_collection, $opt_record, \@opt_exclude_list, $opt_exclude_optional, \@opt_include_list, $opt_include_optional,$opt_bsize,$opt_ext_attrib,$opt_ext_head, \@opt_ignore, \@opt_normal, \@opt_strange, \@opt_error, $opt_directory);
+my $application = Amanda::Application::Amsuntar->new($opt_config, $opt_host, $opt_disk, $opt_device, $opt_level, $opt_index, $opt_message, $opt_collection, $opt_record, \@opt_exclude_list, $opt_exclude_optional, \@opt_include_list, $opt_include_optional,$opt_bsize,$opt_ext_attrib,$opt_ext_head, \@opt_ignore, \@opt_normal, \@opt_strange, \@opt_error, $opt_directory, $opt_suntar_path);
 
 $application->do($ARGV[0]);