mirror of https://github.com/digint/btrbk
btrbk: allow deletion of non-incremental raw targets
implemented directly in btrfs_subvolume_delete()pull/204/head
parent
dcb0c5aa28
commit
e804930b5e
|
@ -8,6 +8,7 @@ btrbk-current
|
||||||
* Add "snapshot" command (close #150).
|
* Add "snapshot" command (close #150).
|
||||||
* Add "--preserve-snapshots" and "--preserve-backups" options.
|
* Add "--preserve-snapshots" and "--preserve-backups" options.
|
||||||
* Change raw backup format (sidecar file instead of uuid in file).
|
* Change raw backup format (sidecar file instead of uuid in file).
|
||||||
|
* Honor target_preserve for raw targets (delete raw targets).
|
||||||
* Do not run in "perl taint mode" by default: remove "perl -T" in
|
* Do not run in "perl taint mode" by default: remove "perl -T" in
|
||||||
hashbang; hardcode $PATH only if taint mode is enabled.
|
hashbang; hardcode $PATH only if taint mode is enabled.
|
||||||
* Remove "duration" column from transaction_log/transaction_syslog.
|
* Remove "duration" column from transaction_log/transaction_syslog.
|
||||||
|
|
55
btrbk
55
btrbk
|
@ -1139,24 +1139,44 @@ sub btrfs_subvolume_delete($@)
|
||||||
$targets = [ $targets ] unless(ref($targets) eq "ARRAY");
|
$targets = [ $targets ] unless(ref($targets) eq "ARRAY");
|
||||||
return 0 unless(scalar(@$targets));
|
return 0 unless(scalar(@$targets));
|
||||||
|
|
||||||
# assert all targets share same HOST
|
|
||||||
# NOTE: rsh and backend command is taken from first target
|
# NOTE: rsh and backend command is taken from first target
|
||||||
my $rsh_host_check = $targets->[0]->{HOST} || "";
|
my $rsh_host_check = $targets->[0]->{HOST} || "";
|
||||||
|
my $target_type = $targets->[0]->{node}{TARGET_TYPE} || "";
|
||||||
foreach (@$targets) {
|
foreach (@$targets) {
|
||||||
|
# assert all targets share same HOST
|
||||||
die if($rsh_host_check ne ($_->{HOST} || ""));
|
die if($rsh_host_check ne ($_->{HOST} || ""));
|
||||||
|
# assert all targets share same target type
|
||||||
|
die if($target_type && ($_->{node}{TARGET_TYPE} ne $target_type));
|
||||||
}
|
}
|
||||||
|
|
||||||
INFO "[delete] options: commit-$commit" if($commit);
|
INFO "[delete] options: commit-$commit" if($commit && (not $target_type));
|
||||||
INFO "[delete] target: $_->{PRINT}" foreach(@$targets);
|
INFO "[delete] target: $_->{PRINT}" foreach(@$targets);
|
||||||
my @options;
|
|
||||||
@options = ("--commit-$commit") if($commit);
|
|
||||||
start_transaction($opts{type} // "delete",
|
start_transaction($opts{type} // "delete",
|
||||||
map( { { vinfo_prefixed_keys("target", $_) }; } @$targets)
|
map( { { vinfo_prefixed_keys("target", $_) }; } @$targets)
|
||||||
);
|
);
|
||||||
my @cmd_target_paths = map { { unsafe => $_->{PATH} } } @$targets;
|
my $ret;
|
||||||
my $ret = run_cmd(cmd => vinfo_cmd($targets->[0], "btrfs subvolume delete", @options, @cmd_target_paths ),
|
if($target_type eq "raw") {
|
||||||
|
my @cmd_target_paths;
|
||||||
|
foreach(@$targets) {
|
||||||
|
if($_->{node}{BTRBK_RAW}{split}) {
|
||||||
|
push @cmd_target_paths, "$_->{PATH}.split_??"; # unsafe is checked with path.info below
|
||||||
|
} else {
|
||||||
|
push @cmd_target_paths, { unsafe => $_->{PATH} };
|
||||||
|
}
|
||||||
|
push @cmd_target_paths, { unsafe => "$_->{PATH}.info" };
|
||||||
|
}
|
||||||
|
$ret = run_cmd(cmd => ['rm', @cmd_target_paths ],
|
||||||
rsh => vinfo_rsh($targets->[0]),
|
rsh => vinfo_rsh($targets->[0]),
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
my @cmd_target_paths = map { { unsafe => $_->{PATH} } } @$targets;
|
||||||
|
my @options;
|
||||||
|
@options = ("--commit-$commit") if($commit);
|
||||||
|
$ret = run_cmd(cmd => vinfo_cmd($targets->[0], "btrfs subvolume delete", @options, @cmd_target_paths ),
|
||||||
|
rsh => vinfo_rsh($targets->[0]),
|
||||||
|
);
|
||||||
|
}
|
||||||
end_transaction($opts{type} // "delete", ($dryrun ? "DRYRUN" : (defined($ret) ? "success" : "ERROR")));
|
end_transaction($opts{type} // "delete", ($dryrun ? "DRYRUN" : (defined($ret) ? "success" : "ERROR")));
|
||||||
ERROR "Failed to delete btrfs subvolumes: " . join(' ', map( { $_->{PRINT} } @$targets)) unless(defined($ret));
|
ERROR "Failed to delete btrfs subvolumes: " . join(' ', map( { $_->{PRINT} } @$targets)) unless(defined($ret));
|
||||||
return defined($ret) ? scalar(@$targets) : undef;
|
return defined($ret) ? scalar(@$targets) : undef;
|
||||||
|
@ -4830,10 +4850,6 @@ MAIN:
|
||||||
$subvol->{node}{FORCE_PRESERVE} = "preserve forced: parent of another raw target";
|
$subvol->{node}{FORCE_PRESERVE} = "preserve forced: parent of another raw target";
|
||||||
$child->{node}{FORCE_PRESERVE} ||= "preserve forced: child of another raw target";
|
$child->{node}{FORCE_PRESERVE} ||= "preserve forced: child of another raw target";
|
||||||
}
|
}
|
||||||
|
|
||||||
# For now, always preserve all raw files.
|
|
||||||
# TODO: remove this line as soon as incremental rotation is implemented.
|
|
||||||
$subvol->{node}{FORCE_PRESERVE} = "preserve forced: raw target";
|
|
||||||
}
|
}
|
||||||
# TRACE(Data::Dumper->Dump([\@subvol_list], ["vinfo_raw_subvol_list{$droot}"]));
|
# TRACE(Data::Dumper->Dump([\@subvol_list], ["vinfo_raw_subvol_list{$droot}"]));
|
||||||
}
|
}
|
||||||
|
@ -5116,8 +5132,6 @@ MAIN:
|
||||||
foreach my $svol (vinfo_subsection($sroot, 'subvolume')) {
|
foreach my $svol (vinfo_subsection($sroot, 'subvolume')) {
|
||||||
my $snapshot_name = config_key($svol, "snapshot_name") // die;
|
my $snapshot_name = config_key($svol, "snapshot_name") // die;
|
||||||
foreach my $droot (vinfo_subsection($svol, 'target')) {
|
foreach my $droot (vinfo_subsection($svol, 'target')) {
|
||||||
my $target_type = $droot->{CONFIG}->{target_type} || die;
|
|
||||||
|
|
||||||
INFO "Cleaning incomplete backups in: $droot->{PRINT}/$snapshot_name.*";
|
INFO "Cleaning incomplete backups in: $droot->{PRINT}/$snapshot_name.*";
|
||||||
push @out, "$droot->{PRINT}/$snapshot_name.*";
|
push @out, "$droot->{PRINT}/$snapshot_name.*";
|
||||||
my @delete;
|
my @delete;
|
||||||
|
@ -5130,22 +5144,7 @@ MAIN:
|
||||||
push(@delete, $target_vol);
|
push(@delete, $target_vol);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
my $ret;
|
my $ret = btrfs_subvolume_delete(\@delete, commit => config_key($droot, "btrfs_commit_delete"), type => "delete_garbled");
|
||||||
if($target_type eq "raw") {
|
|
||||||
if(scalar(@delete)) {
|
|
||||||
DEBUG "[raw] delete:";
|
|
||||||
DEBUG "[raw] file: $_->{PRINT}" foreach(@delete);
|
|
||||||
$ret = run_cmd({
|
|
||||||
cmd => ['rm', (map { { unsafe => $_->{PATH} } } @delete) ],
|
|
||||||
rsh => vinfo_rsh($droot),
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
$ret = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$ret = btrfs_subvolume_delete(\@delete, commit => config_key($droot, "btrfs_commit_delete"), type => "delete_garbled");
|
|
||||||
}
|
|
||||||
if(defined($ret)) {
|
if(defined($ret)) {
|
||||||
INFO "Deleted $ret incomplete backups in: $droot->{PRINT}/$snapshot_name.*";
|
INFO "Deleted $ret incomplete backups in: $droot->{PRINT}/$snapshot_name.*";
|
||||||
$droot->{SUBVOL_DELETED} //= [];
|
$droot->{SUBVOL_DELETED} //= [];
|
||||||
|
|
|
@ -414,8 +414,9 @@ a directory within a subvolume. See btrfs\-send(8), btrfs\-receive(8).
|
||||||
Backup to a raw (filesystem independent) file from the output of
|
Backup to a raw (filesystem independent) file from the output of
|
||||||
btrfs\-send(8), with optional compression and encryption.
|
btrfs\-send(8), with optional compression and encryption.
|
||||||
.PP
|
.PP
|
||||||
Note that the target preserve mechanism is currently disabled for raw
|
Note that the target preserve mechanism is currently disabled for
|
||||||
backups (btrbk does not delete any raw files)!
|
incremental raw backups (btrbk does not delete any incremental raw
|
||||||
|
files)!
|
||||||
.PP
|
.PP
|
||||||
Additional options for raw targets:
|
Additional options for raw targets:
|
||||||
.PP
|
.PP
|
||||||
|
|
Loading…
Reference in New Issue