btrbk: abort on unexpected only if receive target is not present

pull/427/head
Axel Burri 2021-10-04 19:17:36 +02:00
parent 4234fb2965
commit c538702d8c
1 changed files with 4 additions and 2 deletions

6
btrbk
View File

@ -3517,6 +3517,7 @@ sub get_receive_targets($$;@)
my @ret; my @ret;
my @correlated = _correlated_nodes($droot->{node}, $src_vol->{node}); my @correlated = _correlated_nodes($droot->{node}, $src_vol->{node});
my $unexpected;
foreach (@correlated) { foreach (@correlated) {
my $vinfo = vinfo_resolved($_, $droot); # returns undef if not below $droot my $vinfo = vinfo_resolved($_, $droot); # returns undef if not below $droot
if(exists($_->{BTRBK_RAW})) { if(exists($_->{BTRBK_RAW})) {
@ -3530,7 +3531,7 @@ sub get_receive_targets($$;@)
} }
else { else {
TRACE "get_receive_targets: skip unexpected match: " . _fs_path($_) if($do_trace); TRACE "get_receive_targets: skip unexpected match: " . _fs_path($_) if($do_trace);
${$opts{ret_unexpected}} = 1 if($opts{ret_unexpected}); $unexpected = 1;
if($opts{warn} && config_key($droot, "warn_unknown_targets")) { if($opts{warn} && config_key($droot, "warn_unknown_targets")) {
WARN "Receive target of \"$src_vol->{PRINT}\" exists at unknown location: " . ($vinfo ? $vinfo->{PRINT} : _fs_path($_)); WARN "Receive target of \"$src_vol->{PRINT}\" exists at unknown location: " . ($vinfo ? $vinfo->{PRINT} : _fs_path($_));
} }
@ -3538,6 +3539,7 @@ sub get_receive_targets($$;@)
} }
push(@ret, $vinfo); push(@ret, $vinfo);
} }
${$opts{ret_unexpected_only}} = 1 if($opts{ret_unexpected_only} && $unexpected && !scalar(@ret));
return @ret; return @ret;
} }
@ -4598,11 +4600,11 @@ sub macro_archive_target($$$;$)
my $has_unexpected_location = 0; my $has_unexpected_location = 0;
foreach my $svol (@{vinfo_subvol_list($sroot, readonly => 1, btrbk_direct_leaf => $snapshot_name, sort => 'path')}) foreach my $svol (@{vinfo_subvol_list($sroot, readonly => 1, btrbk_direct_leaf => $snapshot_name, sort => 'path')})
{ {
next if(get_receive_targets($droot, $svol, exact => 1, warn => 1, ret_unexpected => \$has_unexpected_location));
if(my $ff = vinfo_match(\@exclude_vf, $svol)) { if(my $ff = vinfo_match(\@exclude_vf, $svol)) {
INFO "Skipping archive candidate \"$svol->{PRINT}\": Match on exclude pattern \"$ff->{unparsed}\""; INFO "Skipping archive candidate \"$svol->{PRINT}\": Match on exclude pattern \"$ff->{unparsed}\"";
next; next;
} }
next if(get_receive_targets($droot, $svol, exact => 1, warn => 1, ret_unexpected_only => \$has_unexpected_location));
DEBUG "Adding archive candidate: $svol->{PRINT}"; DEBUG "Adding archive candidate: $svol->{PRINT}";
push @schedule, { value => $svol, push @schedule, { value => $svol,