btrbk: UNFINISHED: add command-line option "--ignore-related"

Ref: github bug #249

Should work for `btrbk prune --preserve-backups --ignore-related`.

UNFINISHED: Counterpart for `--preserve-snapshots` still needs source readin.
prune-ignore-latest-common
Axel Burri 2018-08-27 16:17:52 +02:00
parent 1862bc16d3
commit d345dfbf50
1 changed files with 18 additions and 10 deletions

28
btrbk
View File

@ -4431,7 +4431,7 @@ MAIN:
@tm_now = localtime($start_time); @tm_now = localtime($start_time);
my @config_override_cmdline; my @config_override_cmdline;
my ($config_cmdline, $quiet, $verbose, $preserve_snapshots, $preserve_backups, $wipe_snapshots, $skip_snapshots, $skip_backups, $print_schedule, $lockfile_cmdline); my ($config_cmdline, $quiet, $verbose, $preserve_snapshots, $preserve_backups, $wipe_snapshots, $skip_snapshots, $skip_backups, $ignore_related, $print_schedule, $lockfile_cmdline);
my $resume_only_DEPRECATED; # as of btrbk-v0.26.0 my $resume_only_DEPRECATED; # as of btrbk-v0.26.0
unless(GetOptions( unless(GetOptions(
'help|h' => sub { VERSION_MESSAGE(); HELP_MESSAGE(0); exit 0; }, 'help|h' => sub { VERSION_MESSAGE(); HELP_MESSAGE(0); exit 0; },
@ -4442,6 +4442,7 @@ MAIN:
'preserve-snapshots' => sub { $preserve_snapshots = "preserve-snapshots" }, 'preserve-snapshots' => sub { $preserve_snapshots = "preserve-snapshots" },
'preserve-backups' => sub { $preserve_backups = "preserve-backups" }, 'preserve-backups' => sub { $preserve_backups = "preserve-backups" },
'wipe' => \$wipe_snapshots, 'wipe' => \$wipe_snapshots,
'ignore-related' => \$ignore_related, # TODO: find better name for this
'resume-only|r' => \$resume_only_DEPRECATED, 'resume-only|r' => \$resume_only_DEPRECATED,
'quiet|q' => \$quiet, 'quiet|q' => \$quiet,
'verbose|v' => sub { $loglevel = 2; }, 'verbose|v' => sub { $loglevel = 2; },
@ -5387,6 +5388,11 @@ MAIN:
# initialize targets, and we don't want to fail on missing targets. # initialize targets, and we don't want to fail on missing targets.
DEBUG "Skipping target tree readin (preserving all snapshots and backups)"; DEBUG "Skipping target tree readin (preserving all snapshots and backups)";
} }
elsif($action_run && $skip_backups && $preserve_backups && $ignore_related) {
# if running "btrbk prune --preserve-backups --ignore-related", there is no need to
# initialize targets, and we don't want to fail on missing targets.
DEBUG "Skipping target tree readin (ignoring latest common match)";
}
else { else {
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')) {
@ -5991,16 +5997,18 @@ MAIN:
} }
# always preserve latest common snapshot/backup pair # always preserve latest common snapshot/backup pair
foreach my $child (@snapshot_children) { unless($ignore_related) {
my @receive_targets = get_receive_targets($droot, $child, exact => 1); foreach my $child (@snapshot_children) {
if(scalar(@receive_targets)) { my @receive_targets = get_receive_targets($droot, $child, exact => 1);
DEBUG "Force preserve for latest common snapshot: $child->{PRINT}"; if(scalar(@receive_targets)) {
$child->{node}{FORCE_PRESERVE} = 'preserve forced: latest common snapshot'; DEBUG "Force preserve for latest common snapshot: $child->{PRINT}";
foreach(@receive_targets) { $child->{node}{FORCE_PRESERVE} = 'preserve forced: latest common snapshot';
DEBUG "Force preserve for latest common target: $_->{PRINT}"; foreach(@receive_targets) {
$_->{node}{FORCE_PRESERVE} = 'preserve forced: latest common target'; DEBUG "Force preserve for latest common target: $_->{PRINT}";
$_->{node}{FORCE_PRESERVE} = 'preserve forced: latest common target';
}
last;
} }
last;
} }
} }