Imported Upstream version 3.1.0
[debian/amanda] / application-src / amzfs-snapshot.pl
index fefd25afb6543e3240384e15b3f986f6df794cea..3872dd49ab50e57123d18229d8a8cf3fc1610bbf 100644 (file)
@@ -1,5 +1,5 @@
 #!@PERL@
-# Copyright (c) 2005-2008 Zmanda Inc.  All Rights Reserved.
+# Copyright (c) 2008,2009 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
@@ -14,7 +14,7 @@
 # with this program; if not, write to the Free Software Foundation, Inc.,
 # 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 #
-# Contact information: Zmanda Inc., 465 S Mathlida Ave, Suite 300
+# Contact information: Zmanda Inc., 465 S. Mathilda Ave., Suite 300
 # Sunnyvale, CA 94086, USA, or: http://www.zmanda.com
 
 # PROPERTY:
@@ -41,13 +41,21 @@ use Amanda::Constants;
 sub new {
     my $class = shift;
     my ($execute_where, $config, $host, $disk, $device, $level, $index, $message, $collection, $record, $df_path, $zfs_path, $pfexec_path, $pfexec) = @_;
-    my $self = $class->SUPER::new($execute_where);
+    my $self = $class->SUPER::new($execute_where, $config);
 
     $self->{execute_where} = $execute_where;
     $self->{config}        = $config;
     $self->{host}          = $host;
-    $self->{disk}          = $disk;
-    $self->{device}        = $device;
+    if (defined $disk) {
+       $self->{disk}      = $disk;
+    } else {
+       $self->{disk}      = $device;
+    }
+    if (defined $device) {
+       $self->{device}    = $device;
+    } else {
+       $self->{device}    = $disk;
+    }
     $self->{level}         = [ @{$level} ]; # Copy the array
     $self->{index}         = $index;
     $self->{message}       = $message;
@@ -64,12 +72,15 @@ sub new {
 
 sub zfs_snapshot_set_value() {
    my $self   = shift;
-   my $action = shift;
 
-   $self->zfs_set_value($action);
+   $self->zfs_set_value();
+
+   if (!defined $self->{device}) {
+       return;
+   }
 
    if (!defined $self->{mountpoint}) {
-       $self->print_to_server($action, "$self->{disk} is not a directory", $Amanda::Script_App::ERROR);
+       $self->print_to_server("$self->{disk} is not a directory", $Amanda::Script_App::ERROR);
        
    }
 }
@@ -90,15 +101,19 @@ sub command_support {
 sub command_pre_dle_amcheck {
     my $self = shift;
 
-    $self->zfs_snapshot_set_value("check");
+    $self->zfs_snapshot_set_value();
+
+    if (!defined $self->{device}) {
+       return;
+    }
 
     if ($self->{error_status} == $Amanda::Script_App::GOOD) {
        if (defined $self->{mountpoint}) {
-           $self->print_to_server("check", "mountpoint $self->{mountpoint}", $Amanda::Script_App::GOOD);
-           $self->print_to_server("check", "directory $self->{directory}", $Amanda::Script_App::GOOD);
-           $self->print_to_server("check", "dir $self->{dir}", $Amanda::Script_App::GOOD);
+           $self->print_to_server("mountpoint $self->{mountpoint}", $Amanda::Script_App::GOOD);
+           $self->print_to_server("directory $self->{directory}", $Amanda::Script_App::GOOD);
+           $self->print_to_server("dir $self->{dir}", $Amanda::Script_App::GOOD);
        }
-       $self->print_to_server("check", "snapshot $self->{snapshot}", $Amanda::Script_App::GOOD);
+       $self->print_to_server("snapshot $self->{snapshot}", $Amanda::Script_App::GOOD);
        $self->zfs_create_snapshot("check");
        print "PROPERTY directory $self->{directory}\n";
     }
@@ -107,14 +122,19 @@ sub command_pre_dle_amcheck {
 sub command_post_dle_amcheck {
     my $self = shift;
 
-    $self->zfs_snapshot_set_value("check");
+    $self->zfs_snapshot_set_value();
+
+    if (!defined $self->{device}) {
+       return;
+    }
+
     $self->zfs_destroy_snapshot("check");
 }
 
 sub command_pre_dle_estimate {
     my $self = shift;
 
-    $self->zfs_snapshot_set_value("estimate");
+    $self->zfs_snapshot_set_value();
     if ($self->{error_status} == $Amanda::Script_App::GOOD) {
        $self->zfs_create_snapshot("estimate");
        print "PROPERTY directory $self->{directory}\n";
@@ -124,14 +144,14 @@ sub command_pre_dle_estimate {
 sub command_post_dle_estimate {
     my $self = shift;
 
-    $self->zfs_snapshot_set_value("estimate");
+    $self->zfs_snapshot_set_value();
     $self->zfs_destroy_snapshot("estimate");
 }
 
 sub command_pre_dle_backup {
     my $self = shift;
 
-    $self->zfs_snapshot_set_value("backup");
+    $self->zfs_snapshot_set_value();
     if ($self->{error_status} == $Amanda::Script_App::GOOD) {
        $self->zfs_create_snapshot("backup");
        print "PROPERTY directory $self->{directory}\n";