]> git.proxmox.com Git - pve-storage.git/commitdiff
Include incremental zfs send in storage_migrate.
authorWolfgang Link <w.link@proxmox.com>
Mon, 24 Apr 2017 15:15:32 +0000 (17:15 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Fri, 28 Apr 2017 08:05:27 +0000 (10:05 +0200)
When replica is enabled and the target host is the reptarget,
the most VM data are on the new target.

PVE/Storage.pm

index 68c39ca01ea6ef50eeeaebbb5ac00811f6f89d07..6b8d108839bdb845bca6ad17d39e5af599708c81 100755 (executable)
@@ -32,6 +32,7 @@ use PVE::Storage::GlusterfsPlugin;
 use PVE::Storage::ZFSPoolPlugin;
 use PVE::Storage::ZFSPlugin;
 use PVE::Storage::DRBDPlugin;
+use PVE::ReplicationTools;
 
 # Storage API version. Icrement it on changes in storage API interface.
 use constant APIVER => 1;
@@ -653,14 +654,27 @@ sub storage_migrate {
            my $zfspath = "$scfg->{pool}\/$volname";
 
            my $snap = ['zfs', 'snapshot', "$zfspath\@__migration__"];
+           my $send = ['zfs', 'send', '-Rpv'];
+           my $rec = ['ssh', "root\@$target_host", 'zfs', 'recv','-F' ,$zfspath];
 
-           my $send = [['zfs', 'send', '-Rpv', "$zfspath\@__migration__"], ['ssh', "root\@$target_host",
-                       'zfs', 'recv', $zfspath]];
+           if (my $snapname = PVE::ReplicationTools::get_last_replica_snap($volid)) {
+
+               #check if target snapshot exists.
+               my $checksnap = ['/usr/bin/ssh', "root\@${target_host}", "-o",
+                   'BatchMode=yes', 'zfs', 'list', '-Hrt', 'snap',
+                   "$zfspath\@$snapname "];
+               eval {
+                   run_command($checksnap);
+                   push @$send, '-I', "$zfspath\@$snapname";
+               };
+
+           }
+           push @$send, "--", "$zfspath\@__migration__";
 
            my $destroy_target = ['ssh', "root\@$target_host", 'zfs', 'destroy', "$zfspath\@__migration__"];
            run_command($snap);
            eval{
-               run_command($send);
+               run_command([$send,$rec]);
            };
            my $err = $@;
            warn "zfs send/receive failed, cleaning up snapshot(s)..\n" if $err;