btrbk: get_receive_targets: also match "src.received_uuid == target.uuid"

This gets important when using an old backup disk as source.

In terms of btrfs send/receive, all subvolumes matching "uuid /
received_uuid" are valid backups.

Merged (amend) from pull request: #116

Verified by Axel Burri <axel@tty0.ch>
pull/135/head
Ian Kelling 2016-11-19 15:25:55 -08:00 committed by Axel Burri
parent 2acbe4978e
commit d02f67a924
2 changed files with 13 additions and 6 deletions

View File

@ -1,5 +1,6 @@
btrbk-current
* Allow converting backup disks to source disks (close #114).
* Show aggregate "size" and "used" for "usage" action (close #119).
* raw_target_encrypt: Always set "gpg --no-random-seed-file":
prevents creation of "~/.gnupg/random_seed" with slight perfomance

18
btrbk
View File

@ -2208,23 +2208,28 @@ sub get_receive_targets($$;@)
foreach (@$droot_subvols) {
next unless($_->{node}{readonly});
# match uuid/received_uuid combinations (silently ignore uuid==uuid matches)
my $matched = undef;
if($_->{node}{received_uuid} eq $uuid) {
$matched = 'by-uuid';
$matched = 'src.uuid == target.received_uuid';
}
elsif(defined($received_uuid) && ($_->{node}{received_uuid} eq $received_uuid)) {
$matched = 'by-received_uuid';
$matched = 'src.received_uuid == target.received_uuid';
}
elsif(defined($received_uuid) && ($_->{node}{uuid} eq $received_uuid)) {
$matched = 'src.received_uuid == target.uuid';
}
next unless($matched);
TRACE "get_receive_targets: $matched: Found receive target: $_->{SUBVOL_PATH}";
TRACE "get_receive_targets: Found receive target ($matched): $_->{SUBVOL_PATH}";
push(@{$opts{seen}}, $_) if($opts{seen});
if($opts{exact_match} && !exists($_->{node}{BTRBK_RAW})) {
if($_->{direct_leaf} && ($_->{NAME} eq $src_vol->{NAME})) {
TRACE "get_receive_targets: exact_match: $_->{SUBVOL_PATH}";
}
else {
TRACE "get_receive_targets: $matched: skip non-exact match: $_->{PRINT}";
TRACE "get_receive_targets: skip non-exact match ($matched): $_->{PRINT}";
WARN "Receive target of \"$src_vol->{PRINT}\" exists at unexpected location: $_->{PRINT}" if($opts{warn});
next;
}
@ -2255,8 +2260,9 @@ sub get_receive_targets_fsroot($$@)
# search in filesystem for matching received_uuid
foreach my $node (
grep({ (not $_->{is_root}) &&
(($_->{received_uuid} eq $uuid) ||
(defined($received_uuid) && ($_->{received_uuid} eq $received_uuid)))
(($_->{received_uuid} eq $uuid) || # match src.uuid == target.received_uuid
(defined($received_uuid) && ($_->{received_uuid} eq $received_uuid)) || # match src.received_uuid == target.received_uuid
(defined($received_uuid) && ($_->{uuid} eq $received_uuid))) # match src.received_uuid == target.uuid
} values(%{$droot->{node}{TREE_ROOT}{ID_HASH}}) ) )
{
next if(scalar grep($_ == $node->{id}, @exclude));