]> git.proxmox.com Git - pve-zsync.git/commitdiff
add target_dataset function
authorFabian Ebner <f.ebner@proxmox.com>
Tue, 4 May 2021 08:09:59 +0000 (10:09 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 4 May 2021 10:12:51 +0000 (12:12 +0200)
so the logic can be re-used and extended in a single place.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
pve-zsync

index a21da4929b1add1d6a12948ae27bf34837d5cabd..93b0d0d52bbba848e8773e5db83a8dade3e9155d 100755 (executable)
--- a/pve-zsync
+++ b/pve-zsync
@@ -725,8 +725,7 @@ sub snapshot_get{
     push @$cmd, 'ssh', "$dest_user\@$dest->{ip}", '--', if $dest->{ip};
     push @$cmd, 'zfs', 'list', '-r', '-t', 'snapshot', '-Ho', 'name', '-S', 'creation';
 
-    my $path = $dest->{all};
-    $path .= "/$source->{last_part}" if $source->{last_part};
+    my $path = target_dataset($source, $dest);
     push @$cmd, $path;
 
     my $raw;
@@ -900,6 +899,17 @@ sub parse_disks {
     return $disks;
 }
 
+# how the corresponding dataset is named on the target
+sub target_dataset {
+    my ($source, $dest) = @_;
+
+    my $target = "$dest->{all}";
+    $target .= "/$source->{last_part}" if $source->{last_part};
+    $target =~ s!/+!/!g;
+
+    return $target;
+}
+
 sub snapshot_destroy {
     my ($source, $dest, $method, $snap, $source_user, $dest_user) = @_;
 
@@ -919,8 +929,7 @@ sub snapshot_destroy {
     if ($dest) {
        my @ssh = $dest->{ip} ? ('ssh', "$dest_user\@$dest->{ip}", '--') : ();
 
-       my $path = "$dest->{all}";
-       $path .= "/$source->{last_part}" if $source->{last_part};
+       my $path = target_dataset($source, $dest);
 
        eval {
            run_cmd([@ssh, @zfscmd, "$path\@$snap"]);
@@ -971,9 +980,7 @@ sub send_image {
        my $bwl = $param->{limit}*1024;
        push @$cmd, \'|', 'cstream', '-t', $bwl;
     }
-    my $target = "$dest->{all}";
-    $target .= "/$source->{last_part}" if $source->{last_part};
-    $target =~ s!/+!/!g;
+    my $target = target_dataset($source, $dest);
 
     push @$cmd, \'|';
     push @$cmd, 'ssh', '-o', 'BatchMode=yes', "$param->{dest_user}\@$dest->{ip}", '--' if $dest->{ip};