Skip to content

Commit

Permalink
btrbk: added command line option "--progress", which simply pipes btr…
Browse files Browse the repository at this point in the history
…fs send through `pv`
  • Loading branch information
digint committed Aug 15, 2015
1 parent 752dbc6 commit d8e8df0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
btrbk-current

* Added configuration option "ssh_port" (close: #39).
* Added command line option "--progress" (close: #42).

btrbk-0.19.3

Expand Down
35 changes: 23 additions & 12 deletions btrbk
Original file line number Diff line number Diff line change
Expand Up @@ -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])/;
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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}";
Expand All @@ -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;
Expand Down Expand Up @@ -1456,6 +1462,7 @@ MAIN:
'quiet|q' => \$quiet,
'verbose|v' => sub { $loglevel = 2; },
'loglevel|l=s' => \$loglevel,
'progress' => \$show_progress,
))
{
VERSION_MESSAGE();
Expand All @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions doc/btrbk.1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d8e8df0

Please sign in to comment.