btrbk: added command line option "--progress", which simply pipes btrfs send through `pv`

pull/44/head
Axel Burri 2015-08-15 18:23:48 +02:00
parent 752dbc6157
commit d8e8df0ebd
3 changed files with 27 additions and 12 deletions

View File

@ -1,6 +1,7 @@
btrbk-current
* Added configuration option "ssh_port" (close: #39).
* Added command line option "--progress" (close: #42).
btrbk-0.19.3

35
btrbk
View File

@ -104,6 +104,7 @@ my %uuid_fs_map; # map UUID to URL
my $dryrun;
my $loglevel = 1;
my $show_progress = 0;
my $err = "";
my $ip_addr_match = qr/(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])/;
@ -140,6 +141,7 @@ sub HELP_MESSAGE
print STDERR " -v, --verbose be verbose (set loglevel=info)\n";
print STDERR " -q, --quiet be quiet (do not print summary for the \"run\" command)\n";
print STDERR " -l, --loglevel=LEVEL set logging level (warn, info, debug, trace)\n";
print STDERR " --progress show progress bar on send-receive operation\n";
print STDERR "\n";
print STDERR "commands:\n";
print STDERR " run [subvol...] perform backup operations as defined in the config file\n";
@ -916,6 +918,7 @@ sub btrfs_send_receive($$$)
my $snapshot_name = $snapshot_path;
$snapshot_name =~ s/^.*\///;
INFO ">>> $target->{PRINT}/$snapshot_name";
print STDOUT "Receiving subvol: $target->{PRINT}/$snapshot_name\n" if($show_progress && (not $dryrun));
DEBUG "[btrfs] send/receive" . ($parent ? " (incremental)" : " (complete)") . ":";
DEBUG "[btrfs] source: $snapshot->{PRINT}";
@ -928,18 +931,21 @@ sub btrfs_send_receive($$$)
push(@send_options, '-v') if($loglevel >= 3);
push(@receive_options, '-v') if($loglevel >= 3);
my $ret = run_cmd(
{
cmd => [ qw(btrfs send), @send_options, $snapshot_path ],
rsh => $snapshot_rsh,
name => "btrfs send",
},
{
cmd => [ qw(btrfs receive), @receive_options, $target_path . '/' ],
rsh => $target_rsh,
name => "btrfs receive",
},
);
my @cmd_pipe;
push @cmd_pipe, {
cmd => [ qw(btrfs send), @send_options, $snapshot_path ],
rsh => $snapshot_rsh,
name => "btrfs send",
};
push @cmd_pipe, {
cmd => [ '/usr/bin/pv' ],
} if($show_progress);
push @cmd_pipe, {
cmd => [ qw(btrfs receive), @receive_options, $target_path . '/' ],
rsh => $target_rsh,
name => "btrfs receive",
};
my $ret = run_cmd(@cmd_pipe);
unless(defined($ret)) {
ERROR "Failed to send/receive btrfs subvolume: $snapshot->{PRINT} " . ($parent_path ? "[$parent_path]" : "") . " -> $target->{PRINT}";
return undef;
@ -1456,6 +1462,7 @@ MAIN:
'quiet|q' => \$quiet,
'verbose|v' => sub { $loglevel = 2; },
'loglevel|l=s' => \$loglevel,
'progress' => \$show_progress,
))
{
VERSION_MESSAGE();
@ -1479,6 +1486,10 @@ MAIN:
@config_src = ( $config_cmdline ) if($config_cmdline);
# check command line options
if($show_progress && (not -e '/usr/bin/pv')) {
WARN 'found option "--progress", but "pv" is not present: (please install "pv")';
$show_progress = 0;
}
my ($action_run, $action_info, $action_tree, $action_diff, $action_origin);
my @subvol_args;
my ($args_expected_min, $args_expected_max) = (0, 0);

View File

@ -46,6 +46,9 @@ executing the "run" command.
\-l, \-\-loglevel <level>
Set the level of verbosity. Accepted levels are warn, info, debug,
and trace.
.TP
\-\-progress
Show progress bar on send-receive operation.
.SH COMMANDS
.PP
.B run