mirror of https://github.com/digint/btrbk
btrbk: add "allow_multiple" flag for config_options declaration; use for option "group"
parent
3aaafa3d88
commit
0ebe2ea2e1
62
btrbk
62
btrbk
|
@ -118,7 +118,7 @@ my %config_options = (
|
||||||
kdf_keysize => { default => "32", accept_numeric => 1 },
|
kdf_keysize => { default => "32", accept_numeric => 1 },
|
||||||
kdf_keygen => { default => "once", accept => [ "once", "each" ] },
|
kdf_keygen => { default => "once", accept => [ "once", "each" ] },
|
||||||
|
|
||||||
group => { default => undef, accept_regexp => qr/^$group_match(\s*,\s*$group_match)*$/, split => qr/\s*,\s*/ },
|
group => { default => undef, accept_regexp => qr/^$group_match(\s*,\s*$group_match)*$/, allow_multiple => 1, split => qr/\s*,\s*/ },
|
||||||
|
|
||||||
backend => { default => "btrfs-progs", accept => [ "btrfs-progs", "btrfs-progs-btrbk", "btrfs-progs-sudo" ] },
|
backend => { default => "btrfs-progs", accept => [ "btrfs-progs", "btrfs-progs-btrbk", "btrfs-progs-sudo" ] },
|
||||||
backend_local => { default => undef, accept => [ "no", "btrfs-progs", "btrfs-progs-btrbk", "btrfs-progs-sudo" ] },
|
backend_local => { default => undef, accept => [ "no", "btrfs-progs", "btrfs-progs-btrbk", "btrfs-progs-sudo" ] },
|
||||||
|
@ -3102,19 +3102,18 @@ sub config_dump_keys($;@)
|
||||||
next unless exists($config->{$key});
|
next unless exists($config->{$key});
|
||||||
$val = $config->{$key};
|
$val = $config->{$key};
|
||||||
}
|
}
|
||||||
if(defined($val)) {
|
my @valary = (ref($val) eq "ARRAY") ? @$val : $val;
|
||||||
if($config_options{$key}->{accept_preserve_matrix}) {
|
foreach(@valary) {
|
||||||
$val = format_preserve_matrix($val);
|
if(defined($_)) {
|
||||||
}
|
if($config_options{$key}->{accept_preserve_matrix}) {
|
||||||
if(ref($val) eq "ARRAY") {
|
$_ = format_preserve_matrix($_);
|
||||||
my $val2 = join(',', @$val);
|
}
|
||||||
$val = $val2;
|
|
||||||
}
|
}
|
||||||
|
$_ //= exists($config->{$key}) ? "no" : "<unset>";
|
||||||
|
my $len = length($key);
|
||||||
|
$maxlen = $len if($len > $maxlen);
|
||||||
|
push @ret, { key => $key, val => $_, len => $len };
|
||||||
}
|
}
|
||||||
$val //= exists($config->{$key}) ? "no" : "<unset>";
|
|
||||||
my $len = length($key);
|
|
||||||
$maxlen = $len if($len > $maxlen);
|
|
||||||
push @ret, { key => $key, val => $val, len => $len };
|
|
||||||
}
|
}
|
||||||
# print as table
|
# print as table
|
||||||
return map { ($opts{prefix} // "") . $_->{key} . (' ' x (1 + $maxlen - $_->{len})) . ' ' . $_->{val} } @ret;
|
return map { ($opts{prefix} // "") . $_->{key} . (' ' x (1 + $maxlen - $_->{len})) . ' ' . $_->{val} } @ret;
|
||||||
|
@ -3200,11 +3199,6 @@ sub append_config_option($$$$;@)
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($opt->{split}) {
|
|
||||||
$value = [ split($opt->{split}, $value) ];
|
|
||||||
TRACE "splitted option \"$key\": " . join(',', @$value);
|
|
||||||
}
|
|
||||||
|
|
||||||
if($opt->{require_bin} && (not check_exe($opt->{require_bin}))) {
|
if($opt->{require_bin} && (not check_exe($opt->{require_bin}))) {
|
||||||
WARN "Found option \"$key\", but required executable \"$opt->{require_bin}\" does not exist on your system. Please install \"$opt->{require_bin}\".";
|
WARN "Found option \"$key\", but required executable \"$opt->{require_bin}\" does not exist on your system. Please install \"$opt->{require_bin}\".";
|
||||||
WARN "Ignoring option \"$key\" $error_statement";
|
WARN "Ignoring option \"$key\" $error_statement";
|
||||||
|
@ -3239,6 +3233,21 @@ sub append_config_option($$$$;@)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($opt->{allow_multiple}) {
|
||||||
|
my $aref = $config->{$key} // [];
|
||||||
|
if($opt->{split}) {
|
||||||
|
push(@$aref, split($opt->{split}, $value));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
push(@$aref, $value);
|
||||||
|
}
|
||||||
|
TRACE "pushing option \"$key=$value\" to $aref=[" . join(',', @$aref) . "]";
|
||||||
|
$value = $aref;
|
||||||
|
}
|
||||||
|
elsif(exists($config->{$key})) {
|
||||||
|
WARN "Option \"$key\" redefined $error_statement";
|
||||||
|
}
|
||||||
|
|
||||||
TRACE "adding option \"$key=$value\" to $context context";
|
TRACE "adding option \"$key=$value\" to $context context";
|
||||||
$value = undef if($value eq "no"); # we don't want to check for "no" all the time
|
$value = undef if($value eq "no"); # we don't want to check for "no" all the time
|
||||||
$config->{$key} = $value;
|
$config->{$key} = $value;
|
||||||
|
@ -4226,7 +4235,7 @@ MAIN:
|
||||||
my $start_time = time;
|
my $start_time = time;
|
||||||
@tm_now = localtime($start_time);
|
@tm_now = localtime($start_time);
|
||||||
|
|
||||||
my %config_override_cmdline;
|
my @config_override_cmdline;
|
||||||
my ($config_cmdline, $quiet, $verbose, $preserve_snapshots, $preserve_backups, $wipe_snapshots, $skip_snapshots, $skip_backups, $print_schedule, $lockfile_cmdline);
|
my ($config_cmdline, $quiet, $verbose, $preserve_snapshots, $preserve_backups, $wipe_snapshots, $skip_snapshots, $skip_backups, $print_schedule, $lockfile_cmdline);
|
||||||
my $resume_only_DEPRECATED; # as of btrbk-v0.26.0
|
my $resume_only_DEPRECATED; # as of btrbk-v0.26.0
|
||||||
unless(GetOptions(
|
unless(GetOptions(
|
||||||
|
@ -4247,7 +4256,7 @@ MAIN:
|
||||||
'format=s' => \$output_format,
|
'format=s' => \$output_format,
|
||||||
'print-schedule' => \$print_schedule,
|
'print-schedule' => \$print_schedule,
|
||||||
'lockfile=s' => \$lockfile_cmdline,
|
'lockfile=s' => \$lockfile_cmdline,
|
||||||
'override=s' => \%config_override_cmdline, # e.g. --override=incremental=no
|
'override=s' => \@config_override_cmdline, # e.g. --override=incremental=no
|
||||||
))
|
))
|
||||||
{
|
{
|
||||||
VERSION_MESSAGE();
|
VERSION_MESSAGE();
|
||||||
|
@ -4409,9 +4418,18 @@ MAIN:
|
||||||
HELP_MESSAGE(0);
|
HELP_MESSAGE(0);
|
||||||
exit 2;
|
exit 2;
|
||||||
}
|
}
|
||||||
foreach my $key (keys %config_override_cmdline) {
|
foreach(@config_override_cmdline) {
|
||||||
DEBUG "config_override: \"$key=$config_override_cmdline{$key}\"";
|
if(/(.*?)=(.*)/) {
|
||||||
unless(append_config_option(\%config_override, $key, $config_override_cmdline{$key}, "root", error_statement => "in option \"--override\"")) {
|
my $key = $1;
|
||||||
|
my $value = $2;
|
||||||
|
DEBUG "config_override: \"$key=$value\"";
|
||||||
|
unless(append_config_option(\%config_override, $key, $value, "root", error_statement => "in option \"--override\"")) {
|
||||||
|
HELP_MESSAGE(0);
|
||||||
|
exit 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ERROR "Option \"override\" requires \"<config_option>=<value>\" format";
|
||||||
HELP_MESSAGE(0);
|
HELP_MESSAGE(0);
|
||||||
exit 2;
|
exit 2;
|
||||||
}
|
}
|
||||||
|
|
|
@ -146,7 +146,8 @@ Note that using ``long-iso'' has implications on the scheduling, see
|
||||||
*group* <group-name>[,<group-name>]...::
|
*group* <group-name>[,<group-name>]...::
|
||||||
Add the current section (volume, subvolume or target) to a
|
Add the current section (volume, subvolume or target) to a
|
||||||
user-defined group, which can be used as filter for most btrbk
|
user-defined group, which can be used as filter for most btrbk
|
||||||
commands.
|
commands. This option can be set multiple times within the same
|
||||||
|
context.
|
||||||
|
|
||||||
|
|
||||||
=== Retention Policy Options
|
=== Retention Policy Options
|
||||||
|
|
Loading…
Reference in New Issue