From 5c157f821cd4883866da35efdd89166fe36df4c3 Mon Sep 17 00:00:00 2001 From: Jim Salter Date: Mon, 30 Mar 2015 18:48:00 -0400 Subject: [PATCH] 1.0.19 - working recursive sync in syncoid! --- CHANGELIST | 2 ++ VERSION | 2 +- syncoid | 40 +++++++++++++++++++++++++++++++++++----- 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/CHANGELIST b/CHANGELIST index 9a2fb25..f51ed95 100644 --- a/CHANGELIST +++ b/CHANGELIST @@ -1,3 +1,5 @@ +1.0.19 working recursive sync (sync specified dataset and all child datasets, ie pool/ds, pool/ds/1, pool, ds/1/a, pool/ds/2 ...) with --recursive or -r in syncoid! + 1.0.18 updated syncoid to break sync out of main routine and into syncdataset(). this will allow doing recursive sync, in next update :) 1.0.17 updated syncoid to use sudo when necessary if it isn't already root - working user needs NOPASSWD for /sbin/zfs in /etc/sudoers diff --git a/VERSION b/VERSION index f8f3c08..140333f 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.0.18 +1.0.19 diff --git a/syncoid b/syncoid index 9f8ad88..5972a3e 100755 --- a/syncoid +++ b/syncoid @@ -4,7 +4,7 @@ # from http://www.gnu.org/licenses/gpl-3.0.html on 2014-11-17. A copy should also be available in this # project's Git repository at https://github.com/jimsalterjrs/sanoid/blob/master/LICENSE. -my $version = '1.0.18'; +my $version = '1.0.19'; use strict; use Data::Dumper; @@ -53,7 +53,20 @@ my %snaps; ## break here to call replication individually so that we can loop across children separately, for recursive replication ## -syncdataset($sourcehost, $sourcefs, $targethost, $targetfs); +if (! $args{'recursive'}) { + print "syncdataset($sourcehost, $sourcefs, $targethost, $targetfs);\n"; +} else { + if ($debug) { print "DEBUG: recursive sync of $sourcefs.\n"; } + my @datasets = getchilddatasets($sourcehost, $sourcefs, $sourceisroot); + foreach my $dataset(@datasets) { + $dataset =~ s/$sourcefs//; + chomp $dataset; + my $childsourcefs = $sourcefs . $dataset; + my $childtargetfs = $targetfs . $dataset; + # print "syncdataset($sourcehost, $childsourcefs, $targethost, $childtargetfs); \n"; + syncdataset($sourcehost, $childsourcefs, $targethost, $childtargetfs); + } +} exit 0; @@ -62,11 +75,28 @@ exit 0; ############################################################################## ############################################################################## +sub getchilddatasets { + my ($rhost,$fs,$isroot,%snaps) = @_; + my $mysudocmd; + + if ($isroot) { $mysudocmd = ''; } else { $mysudocmd = $sudocmd; } + if ($rhost ne '') { $rhost = "$sshcmd $rhost"; } + + my $getchildrencmd = "$rhost $mysudocmd $zfscmd list -o name -Hpr $fs |"; + if ($debug) { print "DEBUG: getting list of child datasets on $fs using $getchildrencmd...\n"; } + open FH, $getchildrencmd; + my @children = ; + close FH; + + return @children; +} sub syncdataset { my ($sourcehost, $sourcefs, $targethost, $targetfs) = @_; + if ($debug) { print "DEBUG: syncing source $sourcefs to target $targetfs.\n"; } + # make sure target is not currently in receive. if (iszfsbusy($targethost,$targetfs,$targetisroot)) { die "Cannot sync now: $targetfs is already target of a zfs receive process.\n"; @@ -115,7 +145,7 @@ sub syncdataset { my $disp_pvsize = readablebytes($pvsize); if ($pvsize == 0) { $disp_pvsize = 'UNKNOWN'; } my $synccmd = buildsynccmd($sendcmd,$recvcmd,$pvsize,$sourceisroot,$targetisroot); - print "INFO: Sending oldest full snapshot $oldestsnap (~ $disp_pvsize) to new target filesystem:\n"; + print "INFO: Sending oldest full snapshot $sourcefs\@$oldestsnap (~ $disp_pvsize) to new target filesystem:\n"; if ($debug) { print "DEBUG: $synccmd\n"; } # make sure target is (still) not currently in receive. @@ -143,7 +173,7 @@ sub syncdataset { die "Cannot sync now: $targetfs is already target of a zfs receive process.\n"; } - print "INFO: Updating new target filesystem with incremental $oldestsnap ... $newsyncsnap (~ $disp_pvsize):\n"; + print "INFO: Updating new target filesystem with incremental $sourcefs\@$oldestsnap ... $newsyncsnap (~ $disp_pvsize):\n"; if ($debug) { print "DEBUG: $synccmd\n"; } system($synccmd); @@ -182,7 +212,7 @@ sub syncdataset { if ($pvsize == 0) { $disp_pvsize = "UNKNOWN"; } my $synccmd = buildsynccmd($sendcmd,$recvcmd,$pvsize,$sourceisroot,$targetisroot); - print "Sending incremental $matchingsnap ... $newsyncsnap (~ $disp_pvsize):\n"; + print "Sending incremental $sourcefs\@$matchingsnap ... $newsyncsnap (~ $disp_pvsize):\n"; if ($debug) { print "DEBUG: $synccmd\n"; } system("$synccmd");