btrbk: expand subvolume globs independent of volume

pull/411/head
Axel Burri 2021-07-24 16:47:26 +02:00
parent 3b4f275126
commit e2de9de440
1 changed files with 10 additions and 15 deletions

25
btrbk
View File

@ -6271,23 +6271,19 @@ MAIN:
foreach my $config_vol (config_subsection($config, "volume")) {
# read-in subvolume list (and expand globs) only if needed
next unless(grep defined($_->{GLOB_CONTEXT}), @{$config_vol->{SUBSECTION}});
my $sroot_glob; # read-in late
my @vol_subsection_expanded;
foreach my $config_subvol (config_subsection($config_vol, "subvolume")) {
if($config_subvol->{GLOB_CONTEXT}) {
my $globs = $config_subvol->{rel_path};
# read-in subvolume list once, only if needed
unless(defined($sroot_glob)) {
$sroot_glob = vinfo($config_vol->{url}, $config_vol);
unless(vinfo_init_root($sroot_glob)) {
ABORTED($sroot_glob, "Failed to fetch subvolume detail");
WARN "Skipping subvolume (wildcards) \"$sroot_glob->{PRINT}/$globs\": " . ABORTED_TEXT($sroot_glob), @stderr;
last;
}
}
my ($url_prefix, $globs) = check_url($config_subvol->{url}, accept_wildcards => 1);
$globs =~ s/([^\*]*)\///;
my $sroot_glob = vinfo($url_prefix . $1, $config_subvol);
INFO "Expanding wildcards: $sroot_glob->{PRINT}/$globs";
unless(vinfo_init_root($sroot_glob)) {
WARN "Failed to fetch subvolume detail for: $sroot_glob->{PRINT}", @stderr;
WARN "No subvolumes found matching: $sroot_glob->{PRINT}/$globs";
next;
}
# support "*some*file*", "*/*"
my $match = join('[^\/]*', map(quotemeta($_), split(/\*+/, $globs, -1)));
@ -6309,8 +6305,7 @@ MAIN:
}
INFO "Found source subvolume: $vol->{PRINT}";
my %conf = ( %$config_subvol,
rel_path_glob => $globs,
rel_path => $vol->{SUBVOL_PATH},
url_glob => $config_subvol->{url},
url => $vol->{URL},
snapshot_name => $vol->{NAME}, # snapshot_name defaults to subvolume name
);
@ -6530,7 +6525,7 @@ MAIN:
push @out, config_dump_keys($sroot, prefix => "\t", resolve => $resolve);
foreach my $svol (vinfo_subsection($sroot, 'subvolume')) {
push @out, ""; # newline
push @out, "\t# subvolume $svol->{CONFIG}->{rel_path_glob}" if(defined($svol->{CONFIG}->{rel_path_glob}));
push @out, "\t# subvolume $svol->{CONFIG}->{url_glob}" if(defined($svol->{CONFIG}->{url_glob}));
push @out, "\tsubvolume $svol->{URL}";
push @out, config_dump_keys($svol, prefix => "\t\t", resolve => $resolve);
foreach my $droot (vinfo_subsection($svol, 'target')) {