mirror of https://github.com/digint/btrbk
btrbk: add config_preserve_hash(); fix macro_delete()
parent
5cc908313a
commit
eba08f2ca3
61
btrbk
61
btrbk
|
@ -616,6 +616,20 @@ sub config_key($$;@)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
sub config_preserve_hash($$)
|
||||||
|
{
|
||||||
|
my $config = shift || die;
|
||||||
|
my $prefix = shift || die;
|
||||||
|
return (
|
||||||
|
preserve_day_of_week => config_key($config, "preserve_day_of_week"),
|
||||||
|
preserve_daily => config_key($config, "${prefix}_preserve_daily"),
|
||||||
|
preserve_weekly => config_key($config, "${prefix}_preserve_weekly"),
|
||||||
|
preserve_monthly => config_key($config, "${prefix}_preserve_monthly"),
|
||||||
|
preserve_yearly => config_key($config, "${prefix}_preserve_yearly"),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
sub config_dump_keys($;@)
|
sub config_dump_keys($;@)
|
||||||
{
|
{
|
||||||
my $config = shift || die;
|
my $config = shift || die;
|
||||||
|
@ -1723,7 +1737,7 @@ sub vinfo_subvol($$)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# sets $config->{ABORTED} on failure
|
# sets $target->{CONFIG}->{ABORTED} on failure
|
||||||
# sets $target->{SUBVOL_RECEIVED}
|
# sets $target->{SUBVOL_RECEIVED}
|
||||||
sub macro_send_receive(@)
|
sub macro_send_receive(@)
|
||||||
{
|
{
|
||||||
|
@ -1825,14 +1839,16 @@ sub macro_send_receive(@)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
sub macro_delete($$$$$)
|
# sets $result_vinfo->{CONFIG}->{ABORTED} on failure
|
||||||
|
# sets $result_vinfo->{SUBVOL_DELETED}
|
||||||
|
sub macro_delete($$$$;@)
|
||||||
{
|
{
|
||||||
my $config = shift || die; #!!! TODO
|
|
||||||
my $root_subvol = shift || die;
|
my $root_subvol = shift || die;
|
||||||
my $subvol_basename = shift // die; # relative "path/to/snapshot_name"
|
my $subvol_basename = shift // die; # relative "path/to/snapshot_name"
|
||||||
my $config_section = shift || die;
|
my $result_vinfo = shift || die;
|
||||||
my $schedule_options = shift || die;
|
my $schedule_options = shift || die;
|
||||||
my $raw_format = ($config->{CONTEXT} eq "target") ? ($config->{target_type} eq "raw") : undef;
|
my %delete_options = @_;
|
||||||
|
my $raw_format = ($root_subvol->{CONFIG}->{CONTEXT} eq "target") ? ($root_subvol->{CONFIG}->{target_type} eq "raw") : undef;
|
||||||
|
|
||||||
my @schedule;
|
my @schedule;
|
||||||
foreach my $vol (values %{vinfo_subvol_list($root_subvol)}) {
|
foreach my $vol (values %{vinfo_subvol_list($root_subvol)}) {
|
||||||
|
@ -1855,22 +1871,17 @@ sub macro_delete($$$$$)
|
||||||
}
|
}
|
||||||
my (undef, $delete) = schedule(
|
my (undef, $delete) = schedule(
|
||||||
schedule => \@schedule,
|
schedule => \@schedule,
|
||||||
preserve_day_of_week => config_key($config, "preserve_day_of_week"),
|
|
||||||
preserve_daily => config_key($config, "${config_section}_preserve_daily"),
|
|
||||||
preserve_weekly => config_key($config, "${config_section}_preserve_weekly"),
|
|
||||||
preserve_monthly => config_key($config, "${config_section}_preserve_monthly"),
|
|
||||||
preserve_yearly => config_key($config, "${config_section}_preserve_yearly"),
|
|
||||||
%$schedule_options
|
%$schedule_options
|
||||||
);
|
);
|
||||||
my $ret = btrfs_subvolume_delete($delete, commit => config_key($config, "btrfs_commit_delete"), type => "delete_${config_section}");
|
my $ret = btrfs_subvolume_delete($delete, %delete_options);
|
||||||
if(defined($ret)) {
|
if(defined($ret)) {
|
||||||
INFO "Deleted $ret subvolumes in: $root_subvol->{PRINT}/$subvol_basename.*";
|
INFO "Deleted $ret subvolumes in: $root_subvol->{PRINT}/$subvol_basename.*";
|
||||||
$config->{VINFO}->{SUBVOL_DELETED} //= []; #!!! TODO: not very nice. find other way, or simply do this outside the macro.
|
$result_vinfo->{SUBVOL_DELETED} //= [];
|
||||||
push @{$config->{VINFO}->{SUBVOL_DELETED}}, @$delete;
|
push @{$result_vinfo->{SUBVOL_DELETED}}, @$delete;
|
||||||
return $delete;
|
return $delete;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ABORTED($config, "Failed to delete subvolume");
|
ABORTED($result_vinfo, "Failed to delete subvolume");
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3569,12 +3580,8 @@ MAIN:
|
||||||
my ($preserve, undef) = schedule(
|
my ($preserve, undef) = schedule(
|
||||||
schedule => \@schedule,
|
schedule => \@schedule,
|
||||||
today => \@today,
|
today => \@today,
|
||||||
preserve_day_of_week => config_key($droot, "preserve_day_of_week"),
|
|
||||||
preserve_daily => config_key($droot, "target_preserve_daily"),
|
|
||||||
preserve_weekly => config_key($droot, "target_preserve_weekly"),
|
|
||||||
preserve_monthly => config_key($droot, "target_preserve_monthly"),
|
|
||||||
preserve_yearly => config_key($droot, "target_preserve_yearly"),
|
|
||||||
preserve_latest => $preserve_latest,
|
preserve_latest => $preserve_latest,
|
||||||
|
config_preserve_hash($droot, "target"),
|
||||||
);
|
);
|
||||||
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;
|
||||||
|
@ -3670,12 +3677,16 @@ MAIN:
|
||||||
# delete backups
|
# delete backups
|
||||||
#
|
#
|
||||||
INFO "Cleaning backups of subvolume \"$svol->{PRINT}\": $droot->{PRINT}/$snapshot_basename.*";
|
INFO "Cleaning backups of subvolume \"$svol->{PRINT}\": $droot->{PRINT}/$snapshot_basename.*";
|
||||||
unless(macro_delete($droot->{CONFIG}, $droot, $snapshot_basename, "target",
|
unless(macro_delete($droot, $snapshot_basename, $droot,
|
||||||
{ today => \@today,
|
{ today => \@today,
|
||||||
|
config_preserve_hash($droot, "target"),
|
||||||
preserve_latest => $preserve_latest_backup,
|
preserve_latest => $preserve_latest_backup,
|
||||||
results => $schedule_results,
|
results => $schedule_results,
|
||||||
result_hints => { topic => "backup", root_path => $droot->{PATH} },
|
result_hints => { topic => "backup", root_path => $droot->{PATH} },
|
||||||
} ))
|
},
|
||||||
|
commit => config_key($droot, "btrfs_commit_delete"),
|
||||||
|
type => "delete_target",
|
||||||
|
))
|
||||||
{
|
{
|
||||||
$target_aborted = -1;
|
$target_aborted = -1;
|
||||||
}
|
}
|
||||||
|
@ -3693,12 +3704,16 @@ MAIN:
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
INFO "Cleaning snapshots: $sroot->{PRINT}/$snapdir$snapshot_basename.*";
|
INFO "Cleaning snapshots: $sroot->{PRINT}/$snapdir$snapshot_basename.*";
|
||||||
macro_delete($svol->{CONFIG}, $sroot, $snapdir . $snapshot_basename, "snapshot",
|
macro_delete($sroot, $snapdir . $snapshot_basename, $svol,
|
||||||
{ today => \@today,
|
{ today => \@today,
|
||||||
|
config_preserve_hash($svol, "snapshot"),
|
||||||
preserve_latest => $preserve_latest_snapshot,
|
preserve_latest => $preserve_latest_snapshot,
|
||||||
results => $schedule_results,
|
results => $schedule_results,
|
||||||
result_hints => { topic => "snapshot", root_path => $sroot->{PATH} },
|
result_hints => { topic => "snapshot", root_path => $sroot->{PATH} },
|
||||||
} );
|
},
|
||||||
|
commit => config_key($svol, "btrfs_commit_delete"),
|
||||||
|
type => "delete_snapshot",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue