btrbk: allow filtering by "<target-directory>/<snapshot-name>", which makes it possible to pinpoint a single target

pull/57/head
Axel Burri 2015-09-24 14:56:22 +02:00
parent 8059fa28db
commit b3d8c1f15f
3 changed files with 17 additions and 7 deletions

13
btrbk
View File

@ -69,7 +69,7 @@ my %config_options = (
# NOTE: the parser always maps "no" to undef
# NOTE: keys "volume", "subvolume" and "target" are hardcoded
snapshot_dir => { default => undef, accept_file => { relative => 1 } },
snapshot_name => { default => undef, accept_file => { name_only => 1 }, context => [ "subvolume" ] },
snapshot_name => { default => undef, accept_file => { name_only => 1 }, context => [ "subvolume" ] }, # NOTE: defaults to the subvolume name (hardcoded)
snapshot_create => { default => "always", accept => [ "no", "always", "ondemand", "onchange" ] },
incremental => { default => "yes", accept => [ "yes", "no", "strict" ] },
resume_missing => { default => "yes", accept => [ "yes", "no" ] },
@ -496,10 +496,13 @@ sub parse_config(@)
$value =~ s/^\/+//; # remove leading slash
TRACE "config: adding subvolume \"$value\" to volume context: $cur->{url}";
my $snapshot_name = $value;
$snapshot_name =~ s/^.*\///; # snapshot_name defaults to subvolume name
my $subvolume = { CONTEXT => "subvolume",
PARENT => $cur,
rel_path => $value,
url => $cur->{url} . '/' . $value,
snapshot_name => $snapshot_name,
};
$cur->{SUBVOLUME} //= [];
push(@{$cur->{SUBVOLUME}}, $subvolume);
@ -1739,11 +1742,14 @@ MAIN:
}
next if($found_subvol);
my $snapshot_name = $config_subvol->{snapshot_name} // die;
foreach my $config_target (@{$config_subvol->{TARGET}}) {
my $target_url = $config_target->{url} // die;
my $found_target = 0;
foreach my $filter (@filter_args) {
if(($target_url eq $filter) || (map { ($filter eq $_) || () } @{$config_target->{group}})) {
if(($filter eq $target_url) ||
($filter eq "$target_url/$snapshot_name") ||
(map { ($filter eq $_) || () } @{$config_target->{group}})) {
TRACE "filter argument \"$filter\" matches target: $target_url\n";
$match{$filter} = ($target_url eq $filter) ? "target=" . vinfo($target_url, $config_target)->{PRINT} : "group=$filter";
$found_target = 1;
@ -1878,9 +1884,6 @@ MAIN:
}
$config_subvol->{svol} = $svol;
# set default for snapshot_name
$config_subvol->{snapshot_name} //= $svol->{NAME};
# check for duplicate snapshot locations
my $snapdir = config_key($config_subvol, "snapshot_dir", postfix => '/') // "";
my $snapshot_basename = config_key($config_subvol, "snapshot_name") // die;

View File

@ -198,7 +198,13 @@ configuration section.
.PP
[hostname:]<target-directory>
.RS 4
Matches a single target of a \fItarget\fR configuration section.
Matches all targets of a \fItarget\fR configuration section.
.RE
.PP
[hostname:]<target-directory>/<snapshot-name>
.RS 4
Matches a single target of a \fItarget\fR section within a
\fIsubvolume\fR section with given <snapshot-name>.
.RE
.PP
<group-name>

View File

@ -70,7 +70,8 @@ will fail if it is not present.
\fBsnapshot_name\fR <basename>
.RS 4
Base name of the created snapshot (and backup). This option is only
valid in the \fItarget\fR section. Defaults to \fI<subvolume-name>\fR.
valid in the \fIsubvolume\fR section. Defaults to
\fI<subvolume-name>\fR.
.RE
.PP
\fBsnapshot_create\fR always|ondemand|onchange|no