]> git.proxmox.com Git - pve-storage.git/commitdiff
prune: introduce keep-all option
authorFabian Ebner <f.ebner@proxmox.com>
Mon, 23 Nov 2020 12:33:08 +0000 (13:33 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Mon, 23 Nov 2020 14:27:17 +0000 (15:27 +0100)
useful to have an alternative to the old maxfiles = 0. There has to
be a way for vzdump to distinguish between:
1. use the /etc/vzdump.conf default (when no options are configured for the storage)
2. use no limit (when keep-all=1)

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
PVE/Storage.pm
PVE/Storage/PBSPlugin.pm
PVE/Storage/Plugin.pm

index 13fea736be9d93c671e97eddaabc2c3e4a0d04ce..7314085ef1da1b73902b3b811f8106094039e10c 100755 (executable)
@@ -1623,7 +1623,10 @@ my $prune_mark = sub {
 sub prune_mark_backup_group {
     my ($backup_group, $keep) = @_;
 
-    if (!scalar(grep {$_ > 0} values %{$keep})) {
+    my $keep_all = delete $keep->{'keep-all'};
+
+    if ($keep_all || !scalar(grep {$_ > 0} values %{$keep})) {
+       $keep = { 'keep-all' => 1 } if $keep_all;
        foreach my $prune_entry (@{$backup_group}) {
            $prune_entry->{mark} = 'keep';
        }
index 2e6d3f6f48e3651fbbec3053da8cc9735d7e5da0..ef9bc79b978e450ada8f6c53fc21a2fcbdf77f05 100644 (file)
@@ -313,10 +313,17 @@ sub prune_backups {
     }
 
     my @param;
-    foreach my $opt (keys %{$keep}) {
-       next if $keep->{$opt} == 0;
-       push @param, "--$opt";
-       push @param, "$keep->{$opt}";
+
+    my $keep_all = delete $keep->{'keep-all'};
+
+    if (!$keep_all) {
+       foreach my $opt (keys %{$keep}) {
+           next if $keep->{$opt} == 0;
+           push @param, "--$opt";
+           push @param, "$keep->{$opt}";
+       }
+    } else { # no need to pass anything to PBS
+       $keep = { 'keep-all' => 1 };
     }
 
     push @param, '--dry-run' if $dryrun;
index 94d42eb48fc418cdd97e5eba6da2f334b63c981d..c60d84bad16241ae8898e0b907b30c2b62ec8897 100644 (file)
@@ -52,6 +52,11 @@ my %prune_option = (
 );
 
 our $prune_backups_format = {
+    'keep-all' => {
+       type => 'boolean',
+       description => 'Keep all backups. Conflicts with the other options when true.',
+       optional => 1,
+    },
     'keep-last' => {
        %prune_option,
        description => 'Keep the last <N> backups.',
@@ -82,7 +87,20 @@ our $prune_backups_format = {
                       'than one backup for a single year, only the latest one is kept.'
     },
 };
-PVE::JSONSchema::register_format('prune-backups', $prune_backups_format);
+PVE::JSONSchema::register_format('prune-backups', $prune_backups_format, \&validate_prune_backups);
+sub validate_prune_backups {
+    my ($prune_backups) = @_;
+
+    my $keep_all = delete $prune_backups->{'keep-all'};
+
+    if (!scalar(grep {$_ > 0} values %{$prune_backups})) {
+       $prune_backups = { 'keep-all' => 1 };
+    } elsif ($keep_all) {
+       die "keep-all cannot be set together with other options.\n";
+    }
+
+    return $prune_backups;
+}
 register_standard_option('prune-backups', {
     description => "The retention options with shorter intervals are processed first " .
                   "with --keep-last being the very first one. Each option covers a " .