mirror of https://github.com/digint/btrbk
btrbk: added configuration option "btrfs_commit_delete"
parent
5299a57c2b
commit
92ee8b0454
38
btrbk
38
btrbk
|
@ -71,7 +71,7 @@ my %config_options = (
|
||||||
target_preserve_daily => { default => "all", accept => [ "all" ], accept_numeric => 1 },
|
target_preserve_daily => { default => "all", accept => [ "all" ], accept_numeric => 1 },
|
||||||
target_preserve_weekly => { default => 0, accept => [ "all" ], accept_numeric => 1 },
|
target_preserve_weekly => { default => 0, accept => [ "all" ], accept_numeric => 1 },
|
||||||
target_preserve_monthly => { default => "all", accept => [ "all" ], accept_numeric => 1 },
|
target_preserve_monthly => { default => "all", accept => [ "all" ], accept_numeric => 1 },
|
||||||
# TODO: btrfs_commit_delete config option, setting --commit-after or --commit-each option to "btrfs subvolume delete" command
|
btrfs_commit_delete => { default => undef, accept => [ "after", "each", "no" ] },
|
||||||
);
|
);
|
||||||
|
|
||||||
my @config_target_types = qw(send-receive);
|
my @config_target_types = qw(send-receive);
|
||||||
|
@ -571,14 +571,18 @@ sub btrfs_snapshot($$)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
sub btrfs_subvolume_delete(@)
|
sub btrfs_subvolume_delete($@)
|
||||||
{
|
{
|
||||||
|
my $commit_delete = shift;
|
||||||
my @targets = @_;
|
my @targets = @_;
|
||||||
return 0 unless(scalar(@targets));
|
return 0 unless(scalar(@targets));
|
||||||
DEBUG "[btrfs] delete:";
|
DEBUG "[btrfs] delete:";
|
||||||
|
DEBUG "[btrfs] commit-delete: " . ($commit_delete ? $commit_delete : "no");
|
||||||
DEBUG "[btrfs] subvolume: $_" foreach(@targets);
|
DEBUG "[btrfs] subvolume: $_" foreach(@targets);
|
||||||
INFO "--- $_" foreach(@targets);
|
my $options = "";
|
||||||
my $ret = run_cmd("/sbin/btrfs subvolume delete " . join(' ', @targets));
|
$options = "--commit-after " if($commit_delete eq "after");
|
||||||
|
$options = "--commit-each " if($commit_delete eq "each");
|
||||||
|
my $ret = run_cmd("/sbin/btrfs subvolume delete $options" . join(' ', @targets));
|
||||||
ERROR "Failed to delete btrfs subvolumes: " . join(' ', @targets) unless(defined($ret));
|
ERROR "Failed to delete btrfs subvolumes: " . join(' ', @targets) unless(defined($ret));
|
||||||
return defined($ret) ? scalar(@targets) : undef;
|
return defined($ret) ? scalar(@targets) : undef;
|
||||||
}
|
}
|
||||||
|
@ -750,10 +754,10 @@ sub check_backup_scheme(@)
|
||||||
foreach my $href (sort { $a->{sort} cmp $b->{sort} } @$schedule) # sorted ascending
|
foreach my $href (sort { $a->{sort} cmp $b->{sort} } @$schedule) # sorted ascending
|
||||||
{
|
{
|
||||||
if($href->{preserve}) {
|
if($href->{preserve}) {
|
||||||
INFO "$href->{sort}: $href->{preserve}";
|
INFO "=== $href->{sort}: $href->{preserve}";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
INFO "$href->{sort}: DELETE";
|
INFO "<<< $href->{sort}";
|
||||||
push(@delete, $href->{name});
|
push(@delete, $href->{name});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1175,7 +1179,10 @@ MAIN:
|
||||||
preserve_weekly => config_key($config_target, "target_preserve_weekly"),
|
preserve_weekly => config_key($config_target, "target_preserve_weekly"),
|
||||||
preserve_monthly => config_key($config_target, "target_preserve_monthly"),
|
preserve_monthly => config_key($config_target, "target_preserve_monthly"),
|
||||||
);
|
);
|
||||||
if(btrfs_subvolume_delete(@delete)) {
|
my $commit_delete = config_key($config_target, "btrfs_commit_delete");
|
||||||
|
my $ret = btrfs_subvolume_delete($commit_delete, @delete);
|
||||||
|
if(defined($ret)) {
|
||||||
|
INFO "Deleted $ret subvolumes in: $droot/$svol.*";
|
||||||
$config_target->{subvol_deleted} = \@delete;
|
$config_target->{subvol_deleted} = \@delete;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -1202,12 +1209,15 @@ MAIN:
|
||||||
preserve_weekly => config_key($config_subvol, "snapshot_preserve_weekly"),
|
preserve_weekly => config_key($config_subvol, "snapshot_preserve_weekly"),
|
||||||
preserve_monthly => config_key($config_subvol, "snapshot_preserve_monthly"),
|
preserve_monthly => config_key($config_subvol, "snapshot_preserve_monthly"),
|
||||||
);
|
);
|
||||||
if(btrfs_subvolume_delete(@delete)) {
|
my $commit_delete = config_key($config_subvol, "btrfs_commit_delete");
|
||||||
$config_subvol->{subvol_deleted} = \@delete;
|
my $ret = btrfs_subvolume_delete($commit_delete, @delete);
|
||||||
}
|
if(defined($ret)) {
|
||||||
else {
|
INFO "Deleted $ret subvolumes in: $sroot/$snapdir$svol.*";
|
||||||
$config_subvol->{ABORTED} = "btrfs subvolume delete command failed";
|
$config_subvol->{subvol_deleted} = \@delete;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
$config_subvol->{ABORTED} = "btrfs subvolume delete command failed";
|
||||||
|
}
|
||||||
$config_subvol->{schedule} = \@schedule;
|
$config_subvol->{schedule} = \@schedule;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1220,7 +1230,7 @@ MAIN:
|
||||||
{
|
{
|
||||||
my $err_count = 0;
|
my $err_count = 0;
|
||||||
print "--------------------------------------------------------------------------------\n";
|
print "--------------------------------------------------------------------------------\n";
|
||||||
print "$version_info\n";
|
print "Backup Summary ($version_info)\n";
|
||||||
print "--------------------------------------------------------------------------------";
|
print "--------------------------------------------------------------------------------";
|
||||||
foreach my $config_vol (@{$config->{VOLUME}})
|
foreach my $config_vol (@{$config->{VOLUME}})
|
||||||
{
|
{
|
||||||
|
|
|
@ -38,6 +38,7 @@ target_preserve_daily 20
|
||||||
target_preserve_weekly 10
|
target_preserve_weekly 10
|
||||||
target_preserve_monthly all
|
target_preserve_monthly all
|
||||||
|
|
||||||
|
btrfs_commit_delete after
|
||||||
|
|
||||||
volume /mnt/btr_system
|
volume /mnt/btr_system
|
||||||
subvolume root_gentoo
|
subvolume root_gentoo
|
||||||
|
|
Loading…
Reference in New Issue