summaryrefslogtreecommitdiff
path: root/misc/amanda32-server/files/extra-patch-application-src::amzfs-sendrecv.pl
blob: 0a19153747d955d3a60819eec8f72fcd46f000f8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
--- application-src/amzfs-sendrecv.pl.orig	2009-01-22 02:35:38.000000000 +0100
+++ application-src/amzfs-sendrecv.pl	2009-01-31 10:37:59.495534563 +0100
@@ -235,13 +235,48 @@
         } elsif (defined $errmsg) {
             $self->print_to_server_and_die($action, $errmsg, $Amanda::Script_App::ERROR);
         } else {
-	        $self->print_to_server_and_die($action, "cannot estimate snapshot '$self->{snapshot}\@$self->{snapshot}': unknown reason", $Amanda::Script_App::ERROR);
+	    $self->print_to_server_and_die($action, "cannot estimate snapshot '$self->{snapshot}\@$self->{snapshot}': unknown reason", $Amanda::Script_App::ERROR);
 	}
     }
+    if ($level == 0) {
+	my $compratio = $self->get_compratio();
+	$msg *= int $compratio;
+    }
 
     return $msg;
 }
 
+sub get_compratio
+{
+    my $self = shift;
+    my $action = shift;
+
+    my $cmd;
+    $cmd =  "$self->{pfexec_cmd} $self->{zfs_path} get -Hp -o value compressratio $self->{filesystem}\@$self->{snapshot}";
+    debug "running (get-compression): $cmd";
+    my($wtr, $rdr, $err, $pid);
+    $err = Symbol::gensym;
+    $pid = open3($wtr, $rdr, $err, $cmd);
+    close $wtr;
+    my ($msg) = <$rdr>;
+    my ($errmsg) = <$err>;
+    waitpid $pid, 0;
+    close $rdr;
+    close $err;
+    if ($? !=  0) {
+        if (defined $msg && defined $errmsg) {
+            $self->print_to_server_and_die($action, "$msg, $errmsg", $Amanda::Script_App::ERROR);
+        } elsif (defined $msg) {
+            $self->print_to_server_and_die($action, $msg, $Amanda::Script_App::ERROR);
+        } elsif (defined $errmsg) {
+            $self->print_to_server_and_die($action, $errmsg, $Amanda::Script_App::ERROR);
+        } else {
+	    $self->print_to_server_and_die($action, "cannot read compression ratio '$self->{snapshot}\@$self->{snapshot}': unknown reason", $Amanda::Script_App::ERROR);
+	}
+    }
+    return $msg
+}
+
 sub command_index_from_output {
 }