From d8e8df0ebd89f6be401e8f334d50e850f748e299 Mon Sep 17 00:00:00 2001 From: Axel Burri Date: Sat, 15 Aug 2015 18:23:48 +0200 Subject: [PATCH] btrbk: added command line option "--progress", which simply pipes btrfs send through `pv` --- ChangeLog | 1 + btrbk | 35 +++++++++++++++++++++++------------ doc/btrbk.1 | 3 +++ 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 325856d..ca994bb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,7 @@ btrbk-current * Added configuration option "ssh_port" (close: #39). + * Added command line option "--progress" (close: #42). btrbk-0.19.3 diff --git a/btrbk b/btrbk index 2fbe8ff..8a46a3e 100755 --- a/btrbk +++ b/btrbk @@ -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); diff --git a/doc/btrbk.1 b/doc/btrbk.1 index 3760e54..a897d6b 100644 --- a/doc/btrbk.1 +++ b/doc/btrbk.1 @@ -46,6 +46,9 @@ executing the "run" command. \-l, \-\-loglevel 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