From c0da910276e6318ce27c17bd776d183df94ffaf7 Mon Sep 17 00:00:00 2001 From: Axel Burri Date: Sun, 5 Jun 2022 17:36:01 +0200 Subject: [PATCH] btrbk: on resume, abort on unexpected if receive target is not present A more sophisticated implementation would be to check this after scheduling, only if the target really needs to be backuped. We could as well automatically trigger a `btrfs snapshot -r` on target in these cases, but this seems counter-intuitive. --- btrbk | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/btrbk b/btrbk index 00a0ea3..22de3b7 100755 --- a/btrbk +++ b/btrbk @@ -7006,9 +7006,10 @@ MAIN: my $resume_total = 0; my $resume_success = 0; + my $unexpected_only = []; foreach my $snapshot (@snapshots) { - if(get_receive_targets($droot, $snapshot, exact => 1, warn => 1)){ + if(get_receive_targets($droot, $snapshot, exact => 1, warn => 1, ret_unexpected_only => $unexpected_only)) { DEBUG "Found correlated target of: $snapshot->{PRINT}"; next; } @@ -7021,6 +7022,16 @@ MAIN: }); } + if(scalar @$unexpected_only && ((config_key($droot, "incremental") // "") eq "strict")) { + # If target exists at unexpected location ONLY, we can't send/receive it. + ABORTED($droot, "Receive targets of backup candidates exist at unexpected location only"); + WARN "Skipping backup of \"$sroot->{PRINT}/${snapshot_basename}.*\": " . ABORTED_TEXT($droot), + "Please check your target configuration, or fix manually by running" . ($droot->{URL_PREFIX} ? " (on $droot->{URL_PREFIX}):" : ":"), + "`btrfs subvolume snapshot -r `", + map { "target: $droot->{PATH}/$_->{src_vol}{NAME}, found: " . _fs_path($_->{target_node}) } @$unexpected_only; + next; + } + if(scalar @schedule) { DEBUG "Checking schedule for backup candidates";