btrbk: use parser function for assembling archive config

pull/542/head
Axel Burri 2022-06-06 18:22:19 +02:00
parent 443cb1891b
commit 053cd7a59c
1 changed files with 17 additions and 33 deletions

50
btrbk
View File

@ -5869,8 +5869,6 @@ MAIN:
my $src_root = $subvol_args[0] || die; my $src_root = $subvol_args[0] || die;
my $archive_root = $subvol_args[1] || die; my $archive_root = $subvol_args[1] || die;
$config->{SUBSECTION} = []; # clear configured subsections, we build them dynamically
unless(vinfo_init_root($src_root)) { unless(vinfo_init_root($src_root)) {
ERROR "Failed to fetch subvolume detail for '$src_root->{PRINT}'", @stderr; ERROR "Failed to fetch subvolume detail for '$src_root->{PRINT}'", @stderr;
exit 1; exit 1;
@ -5880,46 +5878,32 @@ MAIN:
exit 1; exit 1;
} }
my $config_volume = { CONTEXT => "volume", $config->{SUBSECTION} = []; # clear configured subsections, we build them dynamically
PARENT => $config,
SUBSECTION => [],
DUMMY => 1,
url => "/dev/null",
};
push(@{$config->{SUBSECTION}}, $config_volume);
my $cur = $config;
my %name_uniq; my %name_uniq;
my @subvol_list = @{vinfo_subvol_list($src_root)}; foreach my $vol (sort { ($a->{subtree_depth} <=> $b->{subtree_depth}) ||
my @sorted = sort { ($a->{subtree_depth} <=> $b->{subtree_depth}) || ($a->{SUBVOL_DIR} cmp $b->{SUBVOL_DIR}) } @subvol_list; ($a->{SUBVOL_DIR} cmp $b->{SUBVOL_DIR})
foreach my $vol (@sorted) { } @{vinfo_subvol_list($src_root)})
{
next unless($vol->{node}{readonly}); next unless($vol->{node}{readonly});
my $snapshot_name = $vol->{node}{BTRBK_BASENAME}; my $snapshot_name = $vol->{node}{BTRBK_BASENAME};
unless(defined($snapshot_name)) { unless(defined($snapshot_name)) {
WARN "Skipping subvolume (not a btrbk subvolume): $vol->{PRINT}"; WARN "Skipping subvolume (not a btrbk subvolume): $vol->{PRINT}";
next; next;
} }
my $subvol_dir = $vol->{SUBVOL_DIR}; my $subdir = $vol->{SUBVOL_DIR} ? "/" . $vol->{SUBVOL_DIR} : "";
next if($name_uniq{"$subvol_dir/$snapshot_name"}); next if($name_uniq{"$subdir/$snapshot_name"});
$name_uniq{"$subvol_dir/$snapshot_name"} = 1; $name_uniq{"$subdir/$snapshot_name"} = 1;
my $droot_url = $archive_root->{URL} . ($subvol_dir eq "" ? "" : "/$subvol_dir"); $cur = parse_config_line($cur, $_->[0], $_->[1]) // die for(
my $sroot_url = $src_root->{URL} . ($subvol_dir eq "" ? "" : "/$subvol_dir"); [ subvolume => $src_root->{URL} . $subdir ],
my $config_sroot = { # CONTEXT => "archive_source", [ snapshot_dir => $src_root->{PATH} . $subdir ],
CONTEXT => "subvolume", [ snapshot_name => $snapshot_name ],
PARENT => $config_volume, [ target => ($archive_raw ? "raw" : "send-receive") . " '" . $archive_root->{URL} . $subdir . "'" ],
url => $sroot_url, # ABORTED() needs this [ target_create_dir => "yes" ],
snapshot_name => $snapshot_name, );
snapshot_dir => $sroot_url,
};
my $config_droot = { # CONTEXT => "archive_target",
CONTEXT => "target",
PARENT => $config_sroot,
target_type => ($archive_raw ? "raw" : "send-receive"), # macro_send_receive checks this
url => $droot_url, # ABORTED() needs this
target_create_dir => "yes",
};
$config_sroot->{SUBSECTION} = [ $config_droot ];
push(@{$config_volume->{SUBSECTION}}, $config_sroot);
} }
_config_propagate_target($config);
# translate archive_exclude globs, add to exclude args # translate archive_exclude globs, add to exclude args
my $archive_exclude = config_key($config, 'archive_exclude') // []; my $archive_exclude = config_key($config, 'archive_exclude') // [];