From aa2c693e622036c6d6c472b115dea1273b3ca41a Mon Sep 17 00:00:00 2001 From: Adam Fulton Date: Mon, 1 Apr 2024 11:53:45 -0500 Subject: [PATCH] fix(syncoid): regather $snaps on --delete-target-snapshots flag --- syncoid | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/syncoid b/syncoid index bd041ae..b7a1c13 100755 --- a/syncoid +++ b/syncoid @@ -853,8 +853,18 @@ sub syncdataset { if (defined $args{'delete-target-snapshots'}) { # Find the snapshots that exist on the target, filter with # those that exist on the source. Remaining are the snapshots - # that are only on the target. Then sort by creation date, as - # to remove the oldest snapshots first. + # that are only on the target. Then sort to remove the oldest + # snapshots first. + + # regather snapshots on source and target + %snaps = getsnaps('source',$sourcehost,$sourcefs,$sourceisroot); + + if ($targetexists) { + my %targetsnaps = getsnaps('target',$targethost,$targetfs,$targetisroot); + my %sourcesnaps = %snaps; + %snaps = (%sourcesnaps, %targetsnaps); + } + my @to_delete = sort { $snaps{'target'}{$a}{'creation'}<=>$snaps{'target'}{$b}{'creation'} } grep {!exists $snaps{'source'}{$_}} keys %{ $snaps{'target'} }; while (@to_delete) { # Create batch of snapshots to remove