From 2e974c1f4fd3e3ea82560a0813f10dc781945750 Mon Sep 17 00:00:00 2001 From: Axel Burri Date: Thu, 28 Sep 2017 14:02:06 +0200 Subject: [PATCH] btrbk: add "--wipe" command line option --- ChangeLog | 1 + btrbk | 14 ++++++++++---- doc/btrbk.1 | 8 ++++++++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 98a20ea..dba7fd7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -8,6 +8,7 @@ btrbk-current * Add "snapshot" command (close #150). * Add "prune" command. * Add "--preserve-snapshots" and "--preserve-backups" options. + * Add "--wipe" command line option (close #173). * Change raw backup format (sidecar file instead of uuid in file). * Honor target_preserve for raw targets (delete raw targets). * Add symmetric encryption for raw targets (close #157). diff --git a/btrbk b/btrbk index a2a6a3c..910cfe6 100755 --- a/btrbk +++ b/btrbk @@ -302,6 +302,7 @@ sub HELP_MESSAGE print STDERR " -p, --preserve preserve all (do not delete anything)\n"; print STDERR " --preserve-snapshots preserve snapshots (do not delete snapshots)\n"; print STDERR " --preserve-backups preserve backups (do not delete backups)\n"; + print STDERR " --wipe delete all but latest snapshots\n"; print STDERR " -v, --verbose be verbose (set loglevel=info)\n"; print STDERR " -q, --quiet be quiet (do not print backup summary)\n"; print STDERR " -l, --loglevel=LEVEL set logging level (warn, info, debug, trace)\n"; @@ -2944,10 +2945,14 @@ sub config_key($$;@) } -sub config_preserve_hash($$) +sub config_preserve_hash($$;@) { my $config = shift || die; my $prefix = shift || die; + my %opts = @_; + if($opts{wipe}) { + return { dow => 'sunday', min => 'latest', min_q => 'latest' }; + } my $ret = config_key($config, $prefix . "_preserve") // {}; my $preserve_min = config_key($config, $prefix . "_preserve_min"); if(defined($preserve_min)) { @@ -4147,7 +4152,7 @@ MAIN: @tm_now = localtime($start_time); my %config_override_cmdline; - my ($config_cmdline, $quiet, $verbose, $preserve_snapshots, $preserve_backups, $skip_snapshots, $skip_backups, $print_schedule, $lockfile_cmdline); + my ($config_cmdline, $quiet, $verbose, $preserve_snapshots, $preserve_backups, $wipe_snapshots, $skip_snapshots, $skip_backups, $print_schedule, $lockfile_cmdline); my $resume_only_DEPRECATED; # as of btrbk-v0.26.0 unless(GetOptions( 'help|h' => sub { VERSION_MESSAGE(); HELP_MESSAGE(0); exit 0; }, @@ -4157,6 +4162,7 @@ MAIN: 'preserve|p' => sub { $preserve_snapshots = 1, $preserve_backups = 1 }, 'preserve-snapshots' => \$preserve_snapshots, 'preserve-backups' => \$preserve_backups, + 'wipe' => \$wipe_snapshots, 'resume-only|r' => \$resume_only_DEPRECATED, 'quiet|q' => \$quiet, 'verbose|v' => sub { $loglevel = 2; }, @@ -5766,9 +5772,9 @@ MAIN: } } else { - INFO "Cleaning snapshots: $sroot->{PRINT}/$snapdir_ts$snapshot_basename.*"; + INFO "Cleaning snapshots" . ($wipe_snapshots ? " (wipe)" : "") . ": $sroot->{PRINT}/$snapdir_ts$snapshot_basename.*"; macro_delete($sroot, $snapdir, $snapshot_basename, $svol, - { preserve => config_preserve_hash($svol, "snapshot"), + { preserve => config_preserve_hash($svol, "snapshot", wipe => $wipe_snapshots), results => $schedule_results, result_hints => { topic => "snapshot", root_path => $sroot->{PATH} }, }, diff --git a/doc/btrbk.1 b/doc/btrbk.1 index 8c47b28..f253c9f 100644 --- a/doc/btrbk.1 +++ b/doc/btrbk.1 @@ -80,6 +80,14 @@ Preserve all backups. Skips deletion of any backups, even if specified in the configuration file. .RE .PP +\-\-wipe +.RS 4 +Ignore configured snapshot retention policy, delete all but latest +snapshots instead. All snapshots needed for incremental backup (latest +common) are also preserved. Useful if you are getting low on disk +space (ENOSPC). +.RE +.PP \-v, \-\-verbose .RS 4 Verbose output (shortcut for "\-\-loglevel=info").