btrbk: fix print schedule if deletion is skipped

If deletion is skipped, we don't have a schedule call on the target,
which is used for --print-schedule text. Add some (rather hacky) code
to be able to also use the schedule result of the backup process.
pull/542/head
Axel Burri 2022-06-18 21:22:50 +02:00
parent 468ca1eae5
commit eff9af34bc
1 changed files with 21 additions and 10 deletions

31
btrbk
View File

@ -4491,6 +4491,7 @@ sub macro_send_receive(@)
TARGET_TYPE => $target_type, TARGET_TYPE => $target_type,
FORCE_PRESERVE => 'preserve forced: created just now', FORCE_PRESERVE => 'preserve forced: created just now',
}, $raw_info); }, $raw_info);
$source->{SUBVOL_SENT}{$target->{URL}} = $vol_received;
} }
# add info to $config->{SUBVOL_RECEIVED} # add info to $config->{SUBVOL_RECEIVED}
@ -6754,10 +6755,12 @@ MAIN:
# #
# create backups # create backups
# #
my $schedule_results;
if($skip_backups) { if($skip_backups) {
INFO "Skipping backup creation (btrbk snapshot)"; INFO "Skipping backup creation (btrbk snapshot)";
} }
else { else {
$schedule_results = [];
foreach my $sroot (vinfo_subsection($config, 'volume')) { foreach my $sroot (vinfo_subsection($config, 'volume')) {
foreach my $svol (vinfo_subsection($sroot, 'subvolume')) { foreach my $svol (vinfo_subsection($sroot, 'subvolume')) {
my $snaproot = vinfo_snapshot_root($svol); my $snaproot = vinfo_snapshot_root($svol);
@ -6815,10 +6818,15 @@ MAIN:
}); });
$last_dvol_date = $btrbk_date if(!defined($last_dvol_date) || cmp_date($btrbk_date, $last_dvol_date) > 0); $last_dvol_date = $btrbk_date if(!defined($last_dvol_date) || cmp_date($btrbk_date, $last_dvol_date) > 0);
} }
my $schedule_results_mixed = [];
my ($preserve, undef) = schedule( my ($preserve, undef) = schedule(
schedule => \@schedule, schedule => \@schedule,
preserve => config_preserve_hash($droot, $action_archive ? "archive" : "target"), preserve => config_preserve_hash($droot, $action_archive ? "archive" : "target"),
preserve_threshold_date => ($action_archive && config_key($droot, "archive_exclude_older") ? $last_dvol_date : undef), preserve_threshold_date => ($action_archive && config_key($droot, "archive_exclude_older") ? $last_dvol_date : undef),
results => $schedule_results_mixed,
result_hints => { topic => "backup", root_path => $snaproot->{PATH} },
result_delete_action_text => 'REMOVE_FROM_OUTPUT',
); );
my @resume = grep defined, @$preserve; # remove entries with no value from list (target subvolumes) my @resume = grep defined, @$preserve; # remove entries with no value from list (target subvolumes)
$resume_total = scalar @resume; $resume_total = scalar @resume;
@ -6860,6 +6868,13 @@ MAIN:
last; last;
} }
} }
# replace results with target value
foreach (@$schedule_results_mixed) {
my $replace = $_->{value}{SUBVOL_SENT}{$droot->{URL}} // next;
$_->{value} = $replace;
}
push @$schedule_results, @$schedule_results_mixed;
} }
if($resume_total) { if($resume_total) {
@ -6876,7 +6891,6 @@ MAIN:
# #
# remove backups following a preserve daily/weekly/monthly scheme # remove backups following a preserve daily/weekly/monthly scheme
# #
my $schedule_results;
if($preserve_snapshots && $preserve_backups) { if($preserve_snapshots && $preserve_backups) {
INFO "Preserving all snapshots and backups"; INFO "Preserving all snapshots and backups";
} }
@ -6988,15 +7002,12 @@ MAIN:
# print scheduling results # print scheduling results
# #
if($print_schedule && $schedule_results) { if($print_schedule && $schedule_results) {
my @data = map { { %$_, vinfo_prefixed_keys("", $_->{value}) }; } @$schedule_results; foreach my $topic (qw(snapshot backup)) {
my @data_snapshot = grep { $_->{topic} eq "snapshot" } @data; my @data = map +{ %$_, vinfo_prefixed_keys("", $_->{value}) },
my @data_backup = grep { $_->{topic} eq "backup" } @data; grep { !($_->{action} && $_->{action} eq "REMOVE_FROM_OUTPUT") }
grep { $_->{topic} eq $topic } @$schedule_results;
if(scalar(@data_snapshot)) { next unless(@data);
print_formatted("schedule", \@data_snapshot, title => "SNAPSHOT SCHEDULE", paragraph => 1); print_formatted("schedule", \@data, title => (uc($topic) . " SCHEDULE"), paragraph => 1);
}
if(scalar(@data_backup)) {
print_formatted("schedule", \@data_backup, title => "BACKUP SCHEDULE", paragraph => 1);
} }
} }