From e2de9de4408b48bce08624066af9b5385b944196 Mon Sep 17 00:00:00 2001 From: Axel Burri Date: Sat, 24 Jul 2021 16:47:26 +0200 Subject: [PATCH] btrbk: expand subvolume globs independent of volume --- btrbk | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/btrbk b/btrbk index e84208e..0b1c756 100755 --- a/btrbk +++ b/btrbk @@ -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')) {