btrbk: action "archive": delete archives according to archive retention policy

pull/88/head
Axel Burri 2016-04-19 18:53:44 +02:00
parent 31f0f97ff0
commit 5e7a6e5ef4
1 changed files with 48 additions and 8 deletions

56
btrbk
View File

@ -2883,7 +2883,7 @@ sub schedule(@)
if($href->{preserve}) { if($href->{preserve}) {
push(@preserve, $href->{value}) unless($href->{informative_only}); push(@preserve, $href->{value}) unless($href->{informative_only});
push @$results_list, { %result_base, push @$results_list, { %result_base,
action => $href->{informative_only} ? 'seen' : $result_preserve_action_text, action => $href->{informative_only} ? undef : $result_preserve_action_text,
reason => $href->{preserve}, reason => $href->{preserve},
value => $href->{value}, value => $href->{value},
} if($results_list); } if($results_list);
@ -2892,7 +2892,7 @@ sub schedule(@)
else { else {
push(@delete, $href->{value}) unless($href->{informative_only}); push(@delete, $href->{value}) unless($href->{informative_only});
push @$results_list, { %result_base, push @$results_list, { %result_base,
action => $result_delete_action_text, action => $href->{informative_only} ? undef : $result_delete_action_text,
value => $href->{value}, value => $href->{value},
} if($results_list); } if($results_list);
TRACE "schedule: $href->{value}->{PRINT}: delete ($result_delete_action_text)" if($href->{value} && $href->{value}->{PRINT}); TRACE "schedule: $href->{value}->{PRINT}: delete ($result_delete_action_text)" if($href->{value} && $href->{value}->{PRINT});
@ -3577,21 +3577,51 @@ MAIN:
} }
my $schedule_results = []; my $schedule_results = [];
my $aborted;
foreach my $sroot (vinfo_subsection($config, 'archive_source')) { foreach my $sroot (vinfo_subsection($config, 'archive_source')) {
if($aborted) {
# abort all subsequent sources on any abort (we don't want to go on hammering on "disk full" errors)
ABORTED($sroot, $aborted);
next;
}
foreach my $droot (vinfo_subsection($sroot, 'target')) { foreach my $droot (vinfo_subsection($sroot, 'target')) {
my $snapshot_name = config_key($droot, "snapshot_name") // die; my $snapshot_name = config_key($droot, "snapshot_name") // die;
INFO "Archiving subvolumes: $sroot->{PRINT}/${snapshot_name}.*"; INFO "Archiving subvolumes: $sroot->{PRINT}/${snapshot_name}.*";
macro_archive_target($sroot, $droot, $snapshot_name, { results => $schedule_results }); macro_archive_target($sroot, $droot, $snapshot_name, { results => $schedule_results });
if(ABORTED($droot)) { if(ABORTED($droot)) {
# also abort $sroot # also abort $sroot
ABORTED($sroot, "At least one target aborted"); $aborted = "At least one target aborted earlier";
ABORTED($sroot, $aborted);
WARN "Skipping archiving of \"$sroot->{PRINT}/\": $abrt"; WARN "Skipping archiving of \"$sroot->{PRINT}/\": $abrt";
last; last;
} }
} }
last if(ABORTED($sroot));
} }
my $del_schedule_results = [];
if($preserve_backups || $resume_only) {
INFO "Preserving all archives (option \"-p\" or \"-r\" present)";
}
else
{
foreach my $sroot (vinfo_subsection($config, 'archive_source')) {
foreach my $droot (vinfo_subsection($sroot, 'target')) {
my $snapshot_name = config_key($droot, "snapshot_name") // die;
INFO "Cleaning archive: $droot->{PRINT}/${snapshot_name}.*";
macro_delete($droot, "", $snapshot_name, $droot,
{ preserve => config_preserve_hash($droot, "archive"),
results => $del_schedule_results,
result_hints => { topic => "archive", root_path => $droot->{PATH} },
},
commit => config_key($droot, "btrfs_commit_delete"),
type => "delete_archive",
);
}
}
}
my $exit_status = exit_status($config); my $exit_status = exit_status($config);
my $time_elapsed = time - $start_time; my $time_elapsed = time - $start_time;
INFO "Completed within: ${time_elapsed}s (" . localtime(time) . ")"; INFO "Completed within: ${time_elapsed}s (" . localtime(time) . ")";
@ -3611,13 +3641,19 @@ MAIN:
print "\n"; print "\n";
} }
if($print_schedule && not ($preserve_backups || $resume_only)) {
my @data = map { { %$_, vinfo_prefixed_keys("", $_->{value}) }; } @$del_schedule_results;
print_formatted("schedule", \@data, title => "DELETE SCHEDULE");
print "\n";
}
# print summary # print summary
$output_format ||= "custom"; $output_format ||= "custom";
if($output_format eq "custom") if($output_format eq "custom")
{ {
my @unrecoverable; my @unrecoverable;
my @out; my @out;
foreach my $sroot (vinfo_subsection($config, 'archive_source')) { foreach my $sroot (vinfo_subsection($config, 'archive_source', 1)) {
foreach my $droot (vinfo_subsection($sroot, 'target', 1)) { foreach my $droot (vinfo_subsection($sroot, 'target', 1)) {
my @subvol_out; my @subvol_out;
if($droot->{SUBDIR_CREATED}) { if($droot->{SUBDIR_CREATED}) {
@ -3629,8 +3665,12 @@ MAIN:
$create_mode = "!!!" if($_->{ERROR}); $create_mode = "!!!" if($_->{ERROR});
push @subvol_out, "$create_mode $_->{received_subvolume}->{PRINT}"; push @subvol_out, "$create_mode $_->{received_subvolume}->{PRINT}";
} }
if(ABORTED($droot) && (ABORTED($droot) ne "USER_SKIP")) { foreach(sort { $a->{PATH} cmp $b->{PATH} } @{$droot->{SUBVOL_DELETED} // []}) {
push @subvol_out, "!!! Target \"$droot->{PRINT}\" aborted: " . ABORTED($droot); push @subvol_out, "--- $_->{PRINT}";
}
if((ABORTED($droot) && (ABORTED($droot) ne "USER_SKIP")) ||
(ABORTED($sroot) && (ABORTED($sroot) ne "USER_SKIP"))) {
push @subvol_out, "!!! Target \"$droot->{PRINT}\" aborted: " . (ABORTED($droot) || ABORTED($sroot));
} }
if($droot->{CONFIG}->{UNRECOVERABLE}) { if($droot->{CONFIG}->{UNRECOVERABLE}) {
push(@unrecoverable, $droot->{CONFIG}->{UNRECOVERABLE}); push(@unrecoverable, $droot->{CONFIG}->{UNRECOVERABLE});
@ -3644,8 +3684,8 @@ MAIN:
print_header(title => "Archive Summary", print_header(title => "Archive Summary",
time => $start_time, time => $start_time,
legend => [ legend => [
# "--- deleted subvolume",
"++. created directory", "++. created directory",
"--- deleted subvolume",
"*** received subvolume (non-incremental)", "*** received subvolume (non-incremental)",
">>> received subvolume (incremental)", ">>> received subvolume (incremental)",
], ],