]> git.proxmox.com Git - pve-storage.git/commitdiff
Introduce prune-backups property for directory-based storages
authorFabian Ebner <f.ebner@proxmox.com>
Thu, 9 Jul 2020 12:45:41 +0000 (14:45 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 24 Jul 2020 13:44:53 +0000 (15:44 +0200)
Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
PVE/Storage/CIFSPlugin.pm
PVE/Storage/CephFSPlugin.pm
PVE/Storage/DirPlugin.pm
PVE/Storage/GlusterfsPlugin.pm
PVE/Storage/NFSPlugin.pm
PVE/Storage/PBSPlugin.pm
PVE/Storage/Plugin.pm

index 72ec757b0beb7885e43f9ff5623947c3ccc474ab..6edbc9df52b78699d66e551de7c33107cf160fe9 100644 (file)
@@ -134,6 +134,7 @@ sub options {
        nodes => { optional => 1 },
        disable => { optional => 1 },
        maxfiles => { optional => 1 },
+       'prune-backups' => { optional => 1 },
        content => { optional => 1 },
        format => { optional => 1 },
        username => { optional => 1 },
index 6575f4f81ab28234bdecc97877f74eda9696aa93..880ec05266e557a5f4f1187fca32c697f1fa7b84 100644 (file)
@@ -150,6 +150,7 @@ sub options {
        fuse => { optional => 1 },
        bwlimit => { optional => 1 },
        maxfiles => { optional => 1 },
+       'prune-backups' => { optional => 1 },
     };
 }
 
index 39760a89c15f50a91d0c4784dcbd73a2fe782c76..3c81d24a98ca7cd2bb4f2e29b5768af5eb758147 100644 (file)
@@ -49,10 +49,11 @@ sub properties {
 sub options {
     return {
        path => { fixed => 1 },
-        nodes => { optional => 1 },
+       nodes => { optional => 1 },
        shared => { optional => 1 },
        disable => { optional => 1 },
-        maxfiles => { optional => 1 },
+       maxfiles => { optional => 1 },
+       'prune-backups' => { optional => 1 },
        content => { optional => 1 },
        format => { optional => 1 },
        mkdir => { optional => 1 },
index 70ea4fc3bb1022ba8c37a734cf7a590e9f159ad4..2dd414d895696ce773d818aab4f2faeeb8cc0a2e 100644 (file)
@@ -129,9 +129,10 @@ sub options {
        server2 => { optional => 1 },
        volume => { fixed => 1 },
        transport => { optional => 1 },
-        nodes => { optional => 1 },
+       nodes => { optional => 1 },
        disable => { optional => 1 },
-        maxfiles => { optional => 1 },
+       maxfiles => { optional => 1 },
+       'prune-backups' => { optional => 1 },
        content => { optional => 1 },
        format => { optional => 1 },
        mkdir => { optional => 1 },
index 82b0c5ffe46cf001fc335c6b854d6ab928919e6c..6abb24b1734805f8a0c16a9c35e2b052cd93402f 100644 (file)
@@ -79,9 +79,10 @@ sub options {
        path => { fixed => 1 },
        server => { fixed => 1 },
        export => { fixed => 1 },
-        nodes => { optional => 1 },
+       nodes => { optional => 1 },
        disable => { optional => 1 },
-        maxfiles => { optional => 1 },
+       maxfiles => { optional => 1 },
+       'prune-backups' => { optional => 1 },
        options => { optional => 1 },
        content => { optional => 1 },
        format => { optional => 1 },
index 0a4da820e3507f5f276d10db4782f2c8b56a8fc5..dd648703d75a9a38e5aa9319da940a960dcb5437 100644 (file)
@@ -55,6 +55,7 @@ sub options {
        password => { optional => 1 },
        'encryption-key' => { optional => 1 },
        maxfiles => { optional => 1 },
+       'prune-backups' => { optional => 1 },
        fingerprint => { optional => 1 },
     };
 }
index 7f04e85ae8cd00748f3286a6fdaae64992ff22d8..6e321aeee6d5a0057947133dbb6fd3aeb710227a 100644 (file)
@@ -10,7 +10,7 @@ use File::Basename;
 use File::stat qw();
 
 use PVE::Tools qw(run_command);
-use PVE::JSONSchema qw(get_standard_option);
+use PVE::JSONSchema qw(get_standard_option register_standard_option);
 use PVE::Cluster qw(cfs_register_file);
 
 use JSON;
@@ -43,6 +43,62 @@ cfs_register_file ('storage.cfg',
                   sub { __PACKAGE__->parse_config(@_); },
                   sub { __PACKAGE__->write_config(@_); });
 
+my %prune_option = (
+    optional => 1,
+    type => 'integer', minimum => '0',
+    format_description => 'N',
+);
+
+my $prune_backups_format = {
+       'keep-last' => {
+           %prune_option,
+           description => 'Keep the last <N> backups.',
+       },
+       'keep-hourly' => {
+           %prune_option,
+           description => 'Keep backups for the last <N> different hours. If there is more' .
+                          'than one backup for a single hour, only the latest one is kept.'
+       },
+       'keep-daily' => {
+           %prune_option,
+           description => 'Keep backups for the last <N> different days. If there is more' .
+                          'than one backup for a single day, only the latest one is kept.'
+       },
+       'keep-weekly' => {
+           %prune_option,
+           description => 'Keep backups for the last <N> different weeks. If there is more' .
+                          'than one backup for a single week, only the latest one is kept.'
+       },
+       'keep-monthly' => {
+           %prune_option,
+           description => 'Keep backups for the last <N> different months. If there is more' .
+                          'than one backup for a single month, only the latest one is kept.'
+       },
+       'keep-yearly' => {
+           %prune_option,
+           description => 'Keep backups for the last <N> different years. If there is more' .
+                          'than one backup for a single year, only the latest one is kept.'
+       },
+};
+PVE::JSONSchema::register_format('prune-backups', $prune_backups_format, \&validate_prune_backups);
+sub validate_prune_backups {
+    my ($keep) = @_;
+
+    die "at least one keep-option must be set and positive\n"
+       if !grep { $_ } values %{$keep};
+
+    return $keep;
+}
+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 " .
+                  "specific period of time. We say that backups within this period " .
+                  "are covered by this option. The next option does not take care " .
+                  "of already covered backups and only considers older backups.",
+    optional => 1,
+    type => 'string',
+    format => 'prune-backups',
+});
 
 my $defaultData = {
     propertyList => {
@@ -68,6 +124,7 @@ my $defaultData = {
            minimum => 0,
            optional => 1,
        },
+       'prune-backups' => get_standard_option('prune-backups'),
        shared => {
            description => "Mark storage as shared.",
            type => 'boolean',