btrbk: cleanup trace output; cosmetics

pull/73/head
Axel Burri 2016-03-07 23:53:47 +01:00
parent f770488d85
commit 5cc908313a
1 changed files with 30 additions and 35 deletions

65
btrbk
View File

@ -254,7 +254,7 @@ sub ABORTED($;$)
{ {
my $config = shift; my $config = shift;
$abrt = shift; $abrt = shift;
$config = $config->{CONFIG} unless($config->{CONTEXT}); $config = $config->{CONFIG} if($config->{CONFIG}); # accept vinfo for $config
return $config->{ABORTED} unless(defined($abrt)); return $config->{ABORTED} unless(defined($abrt));
unless($abrt eq "USER_SKIP") { unless($abrt eq "USER_SKIP") {
@ -411,14 +411,11 @@ sub run_cmd(@)
sub vinfo($$) sub vinfo($$)
{ {
my $url = shift // die; my $url = shift // die;
my $config = shift || die; #!!! make optional my $config = shift || die;
my %info;
my $name = $url; my $name = $url;
$name =~ s/^.*\///; $name =~ s/^.*\///;
my %info = (
URL => $url,
NAME => $name,
);
if($url =~ /^ssh:\/\/(\S+?)(\/\S+)$/) { if($url =~ /^ssh:\/\/(\S+?)(\/\S+)$/) {
my ($host, $path) = ($1, $2); my ($host, $path) = ($1, $2);
@ -437,7 +434,8 @@ sub vinfo($$)
WARN "No SSH identity provided (option ssh_identity is not set) for: $url"; WARN "No SSH identity provided (option ssh_identity is not set) for: $url";
} }
%info = ( %info = (
%info, URL => $url,
NAME => $name,
HOST => $host, HOST => $host,
PATH => $path, PATH => $path,
PRINT => "$host:$path", PRINT => "$host:$path",
@ -450,7 +448,8 @@ sub vinfo($$)
} }
elsif(($url =~ /^\//) && ($url =~ /^$file_match$/)) { elsif(($url =~ /^\//) && ($url =~ /^$file_match$/)) {
%info = ( %info = (
%info, URL => $url,
NAME => $name,
PATH => $url, PATH => $url,
PRINT => $url, PRINT => $url,
); );
@ -467,6 +466,12 @@ sub vinfo($$)
} }
sub vinfo_dump($;$)
{
return Data::Dumper->new([shift], [(shift || "vinfo")])->Maxdepth(2)->Dump();
}
sub vinfo_assign_config($$) sub vinfo_assign_config($$)
{ {
my $vinfo = shift || die; my $vinfo = shift || die;
@ -536,6 +541,7 @@ sub vinfo_set_detail($$)
next if(uc($_) eq $_); # skip UPPER_CASE keys next if(uc($_) eq $_); # skip UPPER_CASE keys
next if($_ eq "path"); # skip "path", this comes in wrong by "btrfs subvolume list" next if($_ eq "path"); # skip "path", this comes in wrong by "btrfs subvolume list"
# check if already present matches new
die if(exists($vol->{$_}) && ($vol->{$_} ne $detail->{$_})); die if(exists($vol->{$_}) && ($vol->{$_} ne $detail->{$_}));
$vol->{$_} = $detail->{$_}; $vol->{$_} = $detail->{$_};
} }
@ -559,20 +565,11 @@ sub vinfo_set_detail($$)
$vinfo_cache{$vol->{REAL_URL}} = $vol if($vol->{REAL_URL}); $vinfo_cache{$vol->{REAL_URL}} = $vol if($vol->{REAL_URL});
TRACE "vinfo updated for: $vol->{PRINT}"; TRACE "vinfo updated for: $vol->{PRINT}";
TRACE(Data::Dumper->Dump([$vol], ["vinfo{$vol->{PRINT}}"])); TRACE(vinfo_dump($vol)) if($loglevel >= 4);
return $vol; return $vol;
} }
sub dump_vinfo($)
{
my $vinfo = shift;
my $dumper = Data::Dumper->new([$vinfo], ["vinfo"]);
$dumper->Maxdepth(2);
print $dumper->Dump();
}
# returns hash: ( $prefix_{url,path,host,name,subvol_path,rsh} => value, ... ) # returns hash: ( $prefix_{url,path,host,name,subvol_path,rsh} => value, ... )
sub vinfo_prefixed_keys($$) sub vinfo_prefixed_keys($$)
{ {
@ -595,26 +592,24 @@ sub vinfo_prefixed_keys($$)
sub config_key($$;@) sub config_key($$;@)
{ {
my $node = shift || die; my $config = shift || die;
my $key = shift || die; my $key = shift || die;
my %opts = @_; my %opts = @_;
$node = $node->{CONFIG} if($node->{CONFIG}); # accept vinfo for $node my $orig_config = $config;
$config = $config->{CONFIG} if($config->{CONFIG}); # accept vinfo for $config
TRACE "config_key: context=$node->{CONTEXT}, key=$key";
if(exists($config_override{$key})) { if(exists($config_override{$key})) {
TRACE "config_key: forced key=$key to value=" . ($config_override{$key} // "<undef>"); TRACE "config_key: OVERRIDE key=$key to value=" . ($config_override{$key} // "<undef>");
return $config_override{$key}; return $config_override{$key};
} }
while(not exists($node->{$key})) { while(not exists($config->{$key})) {
# note: while all config keys exist in root context (at least with default values), # note: while all config keys exist in root context (at least with default values),
# we also allow fake configs (CONTEXT="cmdline") which have no PARENT. # we also allow fake configs (CONTEXT="cmdline") which have no PARENT.
return undef unless($node->{PARENT}); return undef unless($config->{PARENT});
$node = $node->{PARENT}; $config = $config->{PARENT};
} }
TRACE "config_key: found value=" . ($node->{$key} // "<undef>"); my $retval = $config->{$key};
my $retval = $node->{$key};
$retval = $opts{prefix} . $retval if(defined($opts{prefix}) && defined($retval)); $retval = $opts{prefix} . $retval if(defined($opts{prefix}) && defined($retval));
$retval .= $opts{postfix} if(defined($opts{postfix}) && defined($retval)); $retval .= $opts{postfix} if(defined($opts{postfix}) && defined($retval));
return $retval; return $retval;
@ -959,7 +954,7 @@ sub parse_config(@)
} }
close FILE || ERROR "Failed to close configuration file: $!"; close FILE || ERROR "Failed to close configuration file: $!";
TRACE(Data::Dumper->Dump([$root], ["config{$file}"])) if($root); TRACE(Data::Dumper->Dump([$root], ["config"])) if(($loglevel >= 4) && $root);
return $root; return $root;
} }
@ -1043,7 +1038,7 @@ sub btrfs_filesystem_usage($)
} }
} }
DEBUG "Parsed " . scalar(keys %detail) . " filesystem usage detail items: $vol->{PRINT}"; DEBUG "Parsed " . scalar(keys %detail) . " filesystem usage detail items: $vol->{PRINT}";
TRACE(Data::Dumper->Dump([\%detail], ["btrfs_filesystem_usage($vol->{URL})"])); TRACE(Data::Dumper->Dump([\%detail], ["btrfs_filesystem_usage($vol->{URL})"])) if($loglevel >= 4);
return \%detail; return \%detail;
} }
@ -1137,7 +1132,7 @@ sub btrfs_subvolume_detail($)
} }
} }
DEBUG "Parsed " . scalar(keys %detail) . " subvolume detail items: $vol->{PRINT}"; DEBUG "Parsed " . scalar(keys %detail) . " subvolume detail items: $vol->{PRINT}";
TRACE(Data::Dumper->Dump([$vol], ["btrfs_subvolume_detail($vol->{URL})"])); TRACE(Data::Dumper->new([\%detail], [("btrfs_subvolume_detail")])->Maxdepth(2)->Dump()) if($loglevel >= 4);
foreach(@required_keys) { foreach(@required_keys) {
unless(defined($detail{$_})) { unless(defined($detail{$_})) {
ERROR "Failed to parse subvolume detail (unsupported btrfs-progs) for: $vol->{PRINT}"; ERROR "Failed to parse subvolume detail (unsupported btrfs-progs) for: $vol->{PRINT}";
@ -1697,7 +1692,7 @@ sub vinfo_subvol_list($)
} }
DEBUG "Found " . scalar(keys %ret) . " subvolumes below: $vol->{PRINT}"; DEBUG "Found " . scalar(keys %ret) . " subvolumes below: $vol->{PRINT}";
TRACE(Data::Dumper->Dump([\%ret], ["vinfo_subvol_list{$vol->{URL}}"])); TRACE(Data::Dumper->Dump([\%ret], ["vinfo_subvol_list"])) if($loglevel >= 4);
$vol->{SUBVOL_LIST} = \%ret; $vol->{SUBVOL_LIST} = \%ret;
return \%ret; return \%ret;
@ -2071,7 +2066,7 @@ sub schedule(@)
DEBUG "Filter scheme: preserving all within $preserve_daily days"; DEBUG "Filter scheme: preserving all within $preserve_daily days";
DEBUG "Filter scheme: preserving first in week (starting on $preserve_day_of_week), for $preserve_weekly weeks"; DEBUG "Filter scheme: preserving first in week (starting on $preserve_day_of_week), for $preserve_weekly weeks";
DEBUG "Filter scheme: preserving last weekly of month, for $preserve_monthly months"; DEBUG "Filter scheme: preserving last weekly of month, for $preserve_monthly months";
DEBUG "Filter scheme: preserving last monthly of year, for $preserve_yearly years"; DEBUG "Filter scheme: preserving last weekly of year, for $preserve_yearly years";
# sort the schedule, ascending by date # sort the schedule, ascending by date
my @sorted_schedule = sort { ($a->{btrbk_date}->[0] <=> $b->{btrbk_date}->[0]) || my @sorted_schedule = sort { ($a->{btrbk_date}->[0] <=> $b->{btrbk_date}->[0]) ||
@ -2676,7 +2671,7 @@ MAIN:
ERROR "Failed to parse configuration file"; ERROR "Failed to parse configuration file";
exit 2; exit 2;
} }
unless(ref($config->{SUBSECTION}) eq "ARRAY") { #!!! TODO: check this below, only when needed unless(ref($config->{SUBSECTION}) eq "ARRAY") {
ERROR "No volumes defined in configuration file"; ERROR "No volumes defined in configuration file";
exit 2; exit 2;
} }
@ -3499,7 +3494,7 @@ MAIN:
INFO "Creating subvolume snapshot for: $svol->{PRINT}"; INFO "Creating subvolume snapshot for: $svol->{PRINT}";
my $snapshot = vinfo_child($sroot, "$snapdir$snapshot_name"); my $snapshot = vinfo_child($sroot, "$snapdir$snapshot_name");
if(btrfs_subvolume_snapshot($svol, $snapshot)) { if(btrfs_subvolume_snapshot($svol, $snapshot)) {
$svol->{SNAPSHOT_CREATED} = $snapshot; #!!! TODO: move this to $svol directly! $svol->{SNAPSHOT_CREATED} = $snapshot;
} }
else { else {
ABORTED($svol, "Failed to create snapshot: $svol->{PRINT} -> $sroot->{PRINT}/$snapdir$snapshot_name"); ABORTED($svol, "Failed to create snapshot: $svol->{PRINT} -> $sroot->{PRINT}/$snapdir$snapshot_name");