lsbtr: add -r, --related option

lsbtr-related
Axel Burri 2020-08-28 16:51:07 +02:00
parent f40e3adce3
commit 1910036a03
2 changed files with 55 additions and 10 deletions

45
btrbk
View File

@ -333,11 +333,13 @@ sub HELP_MESSAGE
#80-----------------------------------------------------------------------------
if($program_name eq "lsbtr") {
print STDERR <<"END_HELP_LSBTR";
usage: lsbtr [options] [path]...
usage: lsbtr [options] [(<path> | <url>)...]
or: lsbtr -r [options] <subvolume>
options:
-h, --help display this help message
--version display version information
-r, --related print related subvolumes
-l, --long use long listing format
-u, --uuid print uuid table (parent/received relations)
--raw print raw table format
@ -5013,6 +5015,7 @@ MAIN:
my ($config_cmdline, $lockfile_cmdline, $print_schedule,
$preserve_snapshots, $preserve_backups, $wipe_snapshots, $skip_snapshots, $skip_backups,
$archive_raw,
$ls_related,
$resume_only_DEPRECATED, # as of btrbk-v0.26.0
);
@ -5035,6 +5038,7 @@ MAIN:
);
push @cmdline_options, ($program_name eq "lsbtr") ? (
# "lsbtr" options
'related|r' => \$ls_related,
'long|l' => sub { $output_format = "table" },
'uuid|u' => sub { $output_format = "long" },
'raw' => sub { $output_format = "raw" },
@ -5140,6 +5144,7 @@ MAIN:
$action_ls = 1;
$fallback_default_config = 1;
$args_expected_min = 1;
$args_expected_max = 1 if($ls_related);
@subvol_args = @ARGV;
$subvol_args_allow_relative = 1;
}
@ -5386,6 +5391,44 @@ MAIN:
}
if($action_ls && $ls_related)
{
#
# print related subvolumes for subvolume
#
my $vol = vinfo($subvol_args[0], $config);
unless(vinfo_init_root($vol)) {
ERROR "Failed to fetch subvolume detail for: $vol->{PRINT}", @stderr;
exit 1;
}
my @data;
foreach my $node (@{get_related_nodes($vol)}) {
foreach my $fs_info (_fs_info($node)) {
my $mountinfo = $fs_info->{mountinfo} // {};
push @data, {
%{$node}, # copy node
top => $node->{top_level}, # alias (narrow column)
mount_source => $mountinfo->{mount_source},
mount_point => $mountinfo->{mount_point},
mount_subvolid => $mountinfo->{MNTOPS}{subvolid}, # $fs_info->{mountpoint_node}{id}
mount_subvol => $mountinfo->{MNTOPS}{subvol},
subvolume_path => $node->{path},
subvolume_rel_path => $node->{REL_PATH},
host => $vol->{HOST},
path => $fs_info->{path},
flags => ($node->{readonly} ? "readonly" : undef),
};
}
}
my @sorted = sort { ($a->{path} cmp $b->{path}) } @data;
DEBUG "Listing " . scalar(@sorted) . " related subvolumes for: $vol->{PRINT}";
$output_format ||= "short";
print_formatted("fs_list", \@sorted, no_header => !scalar(@sorted));
exit 0;
}
if($action_ls)
{
#

View File

@ -16,22 +16,20 @@ SYNOPSIS
--------
[verse]
lsbtr [-h|--help] [--version]
[-l|--long] [-u|--uuid] [--raw]
[-v|--verbose]
[-c|--config <file>]
[--override <config_option>=<value>]
[<path>|<url>...]
lsbtr [options] [(<path> | <url>)...]
lsbtr -r [options] <subvolume>
DESCRIPTION
-----------
List btrfs subvolumes and their mount points visible by the file
system below '<path>'.
system below '<path>', or, if the '-r' option is present, list all
related subvolumes of '<subvolume>'.
*lsbtr* is part of *btrbk* (basically a shortcut for "btrbk ls"), and
takes some global configuration options from btrbk.conf(5) if present.
*lsbtr* is part of *btrbk* (basically a more powerful variant of
"btrbk ls"), and takes some global configuration options from
btrbk.conf(5) if present.
*lsbtr* requires 'root privileges' to run correctly. Alternatively,
consider using "btrfs-progs-sudo" or "btrfs-progs-btrbk" backends,
@ -48,6 +46,10 @@ OPTIONS
--version::
Prints the btrbk version.
-r, --related::
Print (deep) related subvolumes. Includes the whole "parent of
parent" and "children of children" chain.
-l, --long::
Print output in long table format (additionally print subvolume
path).