From 0a93f6913570b4019d18b7eb7ded5110b2b1d19e Mon Sep 17 00:00:00 2001 From: Axel Burri Date: Thu, 11 Apr 2019 14:41:08 +0200 Subject: [PATCH] btrbk: treat all related readonly subvolumes within snapdir as "snapshots" With this, previous snapshots (far relations) are still listed when restoring a snapshot. Example (S = source subvolume, readwrite): After 3 snapshots: A->S, B->S, C->S Restore B: `btrfs subvol delete S; btrfs subvol snapshot B S'` A->S, B->S, C->S, S'->B Previous implementation would show now snapshots for S', as no snapshot has parent_uuid=S'. New implementation shows A, B, C as snapshots for S', as orphaned siblings (A, B, C pointing to deleted S) are also related. --- btrbk | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/btrbk b/btrbk index b9e6030..8c5265a 100755 --- a/btrbk +++ b/btrbk @@ -2920,14 +2920,11 @@ sub get_snapshot_children($$;$) my $snaproot = shift || die; my $svol = shift // die; my $btrbk_basename = shift; # if set, also filter by direct_leaf - my @ret; + my @ret = map( { vinfo_resolved($_, $snaproot, btrbk_direct_leaf => $btrbk_basename) // () } + @{get_related_readonly_nodes($svol)} ); - foreach (@{vinfo_subvol_list($snaproot, readonly => 1, btrbk_direct_leaf => $btrbk_basename)}) { - next unless($_->{node}{parent_uuid} eq $svol->{node}{uuid}); - TRACE "get_snapshot_children: found: $_->{PRINT}"; - push(@ret, $_); - } - DEBUG "Found " . scalar(@ret) . " snapshot children of \"$svol->{PRINT}\" in: $snaproot->{PRINT}" . (defined($btrbk_basename) ? "/$btrbk_basename.*" : ""); + if($loglevel >= 4) { TRACE "get_snapshot_children: found: $_->{PRINT}" foreach(@ret); } + DEBUG "Found " . scalar(@ret) . " related snapshots of \"$svol->{PRINT}\" in: $snaproot->{PRINT}" . (defined($btrbk_basename) ? "/$btrbk_basename.*" : ""); return @ret; }