btrbk: add print_size, and command line option modifier

extents-diff
Axel Burri 2019-05-23 15:36:39 +02:00
parent 075fb8bfad
commit 3094092df4
1 changed files with 26 additions and 0 deletions

26
btrbk
View File

@ -275,6 +275,7 @@ my $do_dumper;
my $show_progress = 0; my $show_progress = 0;
my $err = ""; my $err = "";
my $output_format; my $output_format;
my @output_unit;
my $lockfile; my $lockfile;
my $tlog_fh; my $tlog_fh;
my $syslog_enabled = 0; my $syslog_enabled = 0;
@ -4671,6 +4672,27 @@ sub print_formatted(@)
} }
sub print_size($)
{
my $size = shift;
if($output_format && ($output_format eq "raw")) {
return $size;
}
return "-" if($size == 0);
my ($unit, $mul);
if(@output_unit) {
($unit, $mul) = @output_unit;
}
else {
($unit, $mul) = ("KiB", 1024);
($unit, $mul) = ("MiB", $mul * 1024) if($size > $mul * 1024);
($unit, $mul) = ("GiB", $mul * 1024) if($size > $mul * 1024);
($unit, $mul) = ("TiB", $mul * 1024) if($size > $mul * 1024);
}
return sprintf('%.2f', ($size / $mul)) . " $unit";
}
sub _origin_tree sub _origin_tree
{ {
my $prefix = shift; my $prefix = shift;
@ -4806,6 +4828,10 @@ MAIN:
'print-schedule|S' => \$print_schedule, 'print-schedule|S' => \$print_schedule,
'lockfile=s' => \$lockfile_cmdline, 'lockfile=s' => \$lockfile_cmdline,
'override=s' => \@config_override_cmdline, # e.g. --override=incremental=no 'override=s' => \@config_override_cmdline, # e.g. --override=incremental=no
'kbytes' => sub { @output_unit = ("KiB", 1024 ) },
'mbytes' => sub { @output_unit = ("MiB", 1024 * 1024 ) },
'gbytes' => sub { @output_unit = ("GiB", 1024 * 1024 * 1024 ) },
'tbytes' => sub { @output_unit = ("TiB", 1024 * 1024 * 1024 * 1024 ) },
)) ))
{ {
VERSION_MESSAGE(); VERSION_MESSAGE();