From 92159d862ab8dbb29f4b71186dc0f35a28338677 Mon Sep 17 00:00:00 2001 From: Axel Burri Date: Tue, 29 Sep 2015 19:43:11 +0200 Subject: [PATCH] btrbk: additional test for non-zero target file after raw backup, as failure is not detected by exit code --- btrbk | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/btrbk b/btrbk index 68559ea..c944565 100755 --- a/btrbk +++ b/btrbk @@ -1034,8 +1034,10 @@ sub btrfs_send_to_file($$$$;@) cmd => [ qw(btrfs send), @send_options, $snapshot_path ], rsh => $snapshot->{RSH}, name => "btrfs send", - filter_stderr => \&stderr_filter_send_receive, }; + push @cmd_pipe, { + cmd => [ '/usr/bin/pv' ], + } if($show_progress); if($opts{compress}) { die unless($compress{$opts{compress}}); $target_filename .= $compress{$opts{compress}}->{postfix}; @@ -1062,17 +1064,26 @@ sub btrfs_send_to_file($$$$;@) $$ret_vol_received = $vol_received if(ref $ret_vol_received); INFO ">>> $vol_received->{PRINT}"; + print STDOUT "Receiving subvol (raw): $vol_received->{PRINT}\n" if($show_progress && (not $dryrun)); + DEBUG "[btrfs] send-to-file" . ($parent ? " (incremental)" : " (complete)") . ":"; DEBUG "[btrfs] source: $snapshot->{PRINT}"; DEBUG "[btrfs] parent: $parent->{PRINT}" if($parent); DEBUG "[btrfs] target: $target->{PRINT}"; my $ret = run_cmd(@cmd_pipe); + if(defined($ret)) { + # Test target file for "exists and size > 0" after writing, + # as we can not rely on the exit status of 'dd' + DEBUG "Testing target file (non-zero size): $target->{PRINT}"; + $ret = run_cmd({ + cmd => ['test', '-s', "$target_path/$target_filename"], + rsh => $target->{RSH}, + name => "test", + }); + } unless(defined($ret)) { ERROR "Failed to send btrfs subvolume to raw file: $snapshot->{PRINT} " . ($parent_path ? "[$parent_path]" : "") . " -> $vol_received->{PRINT}"; - - # TODO: delete file - ERROR "Please delete incomplete raw file: $vol_received->{PRINT}"; return undef; } return 1;