From b69e9ebf349c5430fbfa8d1b31a80b254eda0441 Mon Sep 17 00:00:00 2001 From: Axel Burri Date: Sun, 11 Dec 2016 15:35:00 +0100 Subject: [PATCH] btrbk: show aggregate "size" and "used" for "usage" action --- ChangeLog | 4 ++++ btrbk | 23 +++++++++++++++++------ doc/btrbk.1 | 7 ++++--- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index b474523..23fd8e5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +btrbk-current + + * Show aggregate "size" and "used" for "usage" action (close #119). + btrbk-0.24.0 * MIGRATION diff --git a/btrbk b/btrbk index 79790fe..c156b27 100755 --- a/btrbk +++ b/btrbk @@ -46,7 +46,7 @@ use Carp qw(confess); use Getopt::Long qw(GetOptions); use Time::Local qw( timelocal timegm timegm_nocheck ); -our $VERSION = '0.24.0'; +our $VERSION = '0.24.1-dev'; our $AUTHOR = 'Axel Burri '; our $PROJECT_HOME = ''; @@ -193,9 +193,9 @@ my %table_formats = ( }, usage => { table => [ qw( host path size used free ) ], - long => [ qw( type host path size device_allocated device_unallocated device_missing used free free_min data_ratio metadata_ratio used global_reserve global_reserve_used ) ], - raw => [ qw( type host path size device_allocated device_unallocated device_missing used free free_min data_ratio metadata_ratio used global_reserve global_reserve_used ) ], - RALIGN => { size=>1, device_allocated=>1, device_unallocated=>1, device_missing=>1, used=>1, free=>1, free_min=>1, data_ratio=>1, metadata_ratio=>1, used=>1, global_reserve=>1, global_reserve_used=>1 }, + long => [ qw( type host path size used device_size device_allocated device_unallocated device_missing device_used free free_min data_ratio metadata_ratio global_reserve global_reserve_used ) ], + raw => [ qw( type host path size used device_size device_allocated device_unallocated device_missing device_used free free_min data_ratio metadata_ratio global_reserve global_reserve_used ) ], + RALIGN => { size=>1, used=>1, device_size=>1, device_allocated=>1, device_unallocated=>1, device_missing=>1, device_used=>1, free=>1, free_min=>1, data_ratio=>1, metadata_ratio=>1, global_reserve=>1, global_reserve_used=>1 }, }, transaction => { table => [ qw( type status target_host target_subvol source_host source_subvol parent_subvol ) ], @@ -745,7 +745,7 @@ sub btrfs_filesystem_usage($) my %detail; foreach (split("\n", $ret)) { if(/^\s+Device size:\s+(\S+)/) { - $detail{size} = $1; + $detail{device_size} = $1; } elsif(/^\s+Device allocated:\s+(\S+)/) { $detail{device_allocated} = $1; @@ -757,7 +757,7 @@ sub btrfs_filesystem_usage($) $detail{device_missing} = $1; } elsif(/^\s+Used:\s+(\S+)/) { - $detail{used} = $1; + $detail{device_used} = $1; } elsif(/^\s+Free \(estimated\):\s+(\S+)\s+\(min: (\S+)\)/) { $detail{free} = $1; @@ -781,6 +781,17 @@ sub btrfs_filesystem_usage($) } } DEBUG "Parsed " . scalar(keys %detail) . " filesystem usage detail items: $vol->{PRINT}"; + + # calculate aggregate size / usage + if($detail{data_ratio} =~ /^[0-9]+\.[0-9]+$/) { + if($detail{device_size} =~ /^([0-9]+\.[0-9]+)(.*)/) { + $detail{size} = sprintf('%.2f%s', $1 / $detail{data_ratio}, $2); + } + if($detail{device_used} =~ /^([0-9]+\.[0-9]+)(.*)/) { + $detail{used} = sprintf('%.2f%s', $1 / $detail{data_ratio}, $2); + } + } + TRACE(Data::Dumper->Dump([\%detail], ["btrfs_filesystem_usage($vol->{URL})"])) if($do_dumper); return \%detail; } diff --git a/doc/btrbk.1 b/doc/btrbk.1 index 9ea86be..6969708 100644 --- a/doc/btrbk.1 +++ b/doc/btrbk.1 @@ -254,9 +254,10 @@ not being set on a target (backup) subvolume. .B usage [filter...] .RS 4 -Print filesystem usage information for all source/target -volumes. Optionally filtered by [filter...] arguments (see \fIFILTER -STATEMENTS\fR below). +Print filesystem usage information for all source/target volumes, +optionally filtered by [filter...] arguments (see \fIFILTER +STATEMENTS\fR below). Note that the "free" value is an estimate of the +amount of data that can still be written to the file system. .RE .PP .B origin