Merge branch 'master' into resumeable-replication

This commit is contained in:
Christoph Klaffl 2018-04-25 18:03:14 +02:00
commit 944a718351
No known key found for this signature in database
GPG Key ID: FC1C525C2A47CC28
1 changed files with 38 additions and 37 deletions

75
syncoid
View File

@ -180,23 +180,23 @@ sub syncdataset {
my $newsyncsnap; my $newsyncsnap;
# skip snapshot checking/creation in case of resumed receive # skip snapshot checking/creation in case of resumed receive
if (!defined($receivetoken)) { if (!defined($receivetoken)) {
# build hashes of the snaps on the source and target filesystems. # build hashes of the snaps on the source and target filesystems.
%snaps = getsnaps('source',$sourcehost,$sourcefs,$sourceisroot); %snaps = getsnaps('source',$sourcehost,$sourcefs,$sourceisroot);
if ($targetexists) { if ($targetexists) {
my %targetsnaps = getsnaps('target',$targethost,$targetfs,$targetisroot); my %targetsnaps = getsnaps('target',$targethost,$targetfs,$targetisroot);
my %sourcesnaps = %snaps; my %sourcesnaps = %snaps;
%snaps = (%sourcesnaps, %targetsnaps); %snaps = (%sourcesnaps, %targetsnaps);
} }
if (defined $args{'dumpsnaps'}) { if (defined $args{'dumpsnaps'}) {
print "merged snapshot list of $targetfs: \n"; print "merged snapshot list of $targetfs: \n";
dumphash(\%snaps); dumphash(\%snaps);
print "\n\n\n"; print "\n\n\n";
} }
if (!defined $args{'no-sync-snap'}) { if (!defined $args{'no-sync-snap'}) {
# create a new syncoid snapshot on the source filesystem. # create a new syncoid snapshot on the source filesystem.
@ -209,7 +209,8 @@ sub syncdataset {
return 0; return 0;
} }
} }
} }
my $newsyncsnapescaped = escapeshellparam($newsyncsnap);
# there is currently (2014-09-01) a bug in ZFS on Linux # there is currently (2014-09-01) a bug in ZFS on Linux
# that causes readonly to always show on if it's EVER # that causes readonly to always show on if it's EVER
@ -278,7 +279,7 @@ sub syncdataset {
# $originaltargetreadonly = getzfsvalue($targethost,$targetfs,$targetisroot,'readonly'); # $originaltargetreadonly = getzfsvalue($targethost,$targetfs,$targetisroot,'readonly');
# setzfsvalue($targethost,$targetfs,$targetisroot,'readonly','on'); # setzfsvalue($targethost,$targetfs,$targetisroot,'readonly','on');
$sendcmd = "$sourcesudocmd $zfscmd send $args{'streamarg'} $sourcefsescaped\@$oldestsnapescaped $sourcefsescaped\@$newsyncsnap"; $sendcmd = "$sourcesudocmd $zfscmd send $args{'streamarg'} $sourcefsescaped\@$oldestsnapescaped $sourcefsescaped\@$newsyncsnapescaped";
$pvsize = getsendsize($sourcehost,"$sourcefs\@$oldestsnap","$sourcefs\@$newsyncsnap",$sourceisroot); $pvsize = getsendsize($sourcehost,"$sourcefs\@$oldestsnap","$sourcefs\@$newsyncsnap",$sourceisroot);
$disp_pvsize = readablebytes($pvsize); $disp_pvsize = readablebytes($pvsize);
if ($pvsize == 0) { $disp_pvsize = "UNKNOWN"; } if ($pvsize == 0) { $disp_pvsize = "UNKNOWN"; }
@ -307,26 +308,26 @@ sub syncdataset {
# setzfsvalue($targethost,$targetfs,$targetisroot,'readonly',$originaltargetreadonly); # setzfsvalue($targethost,$targetfs,$targetisroot,'readonly',$originaltargetreadonly);
} }
} else { } else {
# resume interrupted receive if there is a valid resume $token # resume interrupted receive if there is a valid resume $token
# and because this will ony resume the receive to the next # and because this will ony resume the receive to the next
# snapshot, do a normal sync after that # snapshot, do a normal sync after that
if (defined($receivetoken)) { if (defined($receivetoken)) {
my $sendcmd = "$sourcesudocmd $zfscmd send -t $receivetoken"; my $sendcmd = "$sourcesudocmd $zfscmd send -t $receivetoken";
my $recvcmd = "$targetsudocmd $zfscmd receive $receiveextraargs -F $targetfsescaped"; my $recvcmd = "$targetsudocmd $zfscmd receive $receiveextraargs -F $targetfsescaped";
my $pvsize = getsendsize($sourcehost,"","",$sourceisroot,$receivetoken); my $pvsize = getsendsize($sourcehost,"","",$sourceisroot,$receivetoken);
my $disp_pvsize = readablebytes($pvsize); my $disp_pvsize = readablebytes($pvsize);
if ($pvsize == 0) { $disp_pvsize = "UNKNOWN"; } if ($pvsize == 0) { $disp_pvsize = "UNKNOWN"; }
my $synccmd = buildsynccmd($sendcmd,$recvcmd,$pvsize,$sourceisroot,$targetisroot); my $synccmd = buildsynccmd($sendcmd,$recvcmd,$pvsize,$sourceisroot,$targetisroot);
if (!$quiet) { print "Resuming interrupted zfs send/receive from $sourcefs to $targetfs (~ $disp_pvsize remaining):\n"; } if (!$quiet) { print "Resuming interrupted zfs send/receive from $sourcefs to $targetfs (~ $disp_pvsize remaining):\n"; }
if ($debug) { print "DEBUG: $synccmd\n"; } if ($debug) { print "DEBUG: $synccmd\n"; }
system("$synccmd") == 0 system("$synccmd") == 0
or die "CRITICAL ERROR: $synccmd failed: $?"; or die "CRITICAL ERROR: $synccmd failed: $?";
# a resumed transfer will only be done to the next snapshot, # a resumed transfer will only be done to the next snapshot,
# so do an normal sync cycle # so do an normal sync cycle
return syncdataset($sourcehost, $sourcefs, $targethost, $targetfs); return syncdataset($sourcehost, $sourcefs, $targethost, $targetfs);
} }
# find most recent matching snapshot and do an -I # find most recent matching snapshot and do an -I
# to the new snapshot # to the new snapshot
@ -367,7 +368,7 @@ sub syncdataset {
system ("$targetsudocmd $zfscmd rollback -R $targetfsescaped\@$matchingsnapescaped"); system ("$targetsudocmd $zfscmd rollback -R $targetfsescaped\@$matchingsnapescaped");
} }
my $sendcmd = "$sourcesudocmd $zfscmd send $args{'streamarg'} $sourcefsescaped\@$matchingsnapescaped $sourcefsescaped\@$newsyncsnap"; my $sendcmd = "$sourcesudocmd $zfscmd send $args{'streamarg'} $sourcefsescaped\@$matchingsnapescaped $sourcefsescaped\@$newsyncsnapescaped";
my $recvcmd = "$targetsudocmd $zfscmd receive $receiveextraargs -F $targetfsescaped"; my $recvcmd = "$targetsudocmd $zfscmd receive $receiveextraargs -F $targetfsescaped";
my $pvsize = getsendsize($sourcehost,"$sourcefs\@$matchingsnap","$sourcefs\@$newsyncsnap",$sourceisroot); my $pvsize = getsendsize($sourcehost,"$sourcefs\@$matchingsnap","$sourcefs\@$newsyncsnap",$sourceisroot);
my $disp_pvsize = readablebytes($pvsize); my $disp_pvsize = readablebytes($pvsize);
@ -984,7 +985,7 @@ sub getsnaps() {
my $guid = $line; my $guid = $line;
$guid =~ s/^.*\sguid\s*(\d*).*/$1/; $guid =~ s/^.*\sguid\s*(\d*).*/$1/;
my $snap = $line; my $snap = $line;
$snap =~ s/^.*\@(\S*)\s*guid.*$/$1/; $snap =~ s/^.*\@(.*)\tguid.*$/$1/;
$snaps{$type}{$snap}{'guid'}=$guid; $snaps{$type}{$snap}{'guid'}=$guid;
} }
} }
@ -996,7 +997,7 @@ sub getsnaps() {
my $creation = $line; my $creation = $line;
$creation =~ s/^.*\screation\s*(\d*).*/$1/; $creation =~ s/^.*\screation\s*(\d*).*/$1/;
my $snap = $line; my $snap = $line;
$snap =~ s/^.*\@(\S*)\s*creation.*$/$1/; $snap =~ s/^.*\@(.*)\tcreation.*$/$1/;
$snaps{$type}{$snap}{'creation'}=$creation; $snaps{$type}{$snap}{'creation'}=$creation;
} }
} }