public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Fabian Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH v4 storage 1/7] Introduce prune-backups property for directory-based storages
Date: Thu,  9 Jul 2020 14:45:41 +0200	[thread overview]
Message-ID: <20200709124547.2913-2-f.ebner@proxmox.com> (raw)
In-Reply-To: <20200709124547.2913-1-f.ebner@proxmox.com>

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
---

Changes from v3:
    * use property string validator

 PVE/Storage/CIFSPlugin.pm      |  1 +
 PVE/Storage/CephFSPlugin.pm    |  1 +
 PVE/Storage/DirPlugin.pm       |  5 +--
 PVE/Storage/GlusterfsPlugin.pm |  5 +--
 PVE/Storage/NFSPlugin.pm       |  5 +--
 PVE/Storage/PBSPlugin.pm       |  1 +
 PVE/Storage/Plugin.pm          | 59 +++++++++++++++++++++++++++++++++-
 7 files changed, 70 insertions(+), 7 deletions(-)

diff --git a/PVE/Storage/CIFSPlugin.pm b/PVE/Storage/CIFSPlugin.pm
index 72ec757..6edbc9d 100644
--- a/PVE/Storage/CIFSPlugin.pm
+++ b/PVE/Storage/CIFSPlugin.pm
@@ -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 },
diff --git a/PVE/Storage/CephFSPlugin.pm b/PVE/Storage/CephFSPlugin.pm
index 6575f4f..880ec05 100644
--- a/PVE/Storage/CephFSPlugin.pm
+++ b/PVE/Storage/CephFSPlugin.pm
@@ -150,6 +150,7 @@ sub options {
 	fuse => { optional => 1 },
 	bwlimit => { optional => 1 },
 	maxfiles => { optional => 1 },
+	'prune-backups' => { optional => 1 },
     };
 }
 
diff --git a/PVE/Storage/DirPlugin.pm b/PVE/Storage/DirPlugin.pm
index 39760a8..3c81d24 100644
--- a/PVE/Storage/DirPlugin.pm
+++ b/PVE/Storage/DirPlugin.pm
@@ -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 },
diff --git a/PVE/Storage/GlusterfsPlugin.pm b/PVE/Storage/GlusterfsPlugin.pm
index 70ea4fc..2dd414d 100644
--- a/PVE/Storage/GlusterfsPlugin.pm
+++ b/PVE/Storage/GlusterfsPlugin.pm
@@ -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 },
diff --git a/PVE/Storage/NFSPlugin.pm b/PVE/Storage/NFSPlugin.pm
index 82b0c5f..6abb24b 100644
--- a/PVE/Storage/NFSPlugin.pm
+++ b/PVE/Storage/NFSPlugin.pm
@@ -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 },
diff --git a/PVE/Storage/PBSPlugin.pm b/PVE/Storage/PBSPlugin.pm
index b236f6c..87b09f2 100644
--- a/PVE/Storage/PBSPlugin.pm
+++ b/PVE/Storage/PBSPlugin.pm
@@ -55,6 +55,7 @@ sub options {
 	password => { optional => 1 },
 	'encryption-key' => { optional => 1 },
 	maxfiles => { optional => 1 },
+	'prune-backups' => { optional => 1 },
 	fingerprint => { optional => 1 },
     };
 }
diff --git a/PVE/Storage/Plugin.pm b/PVE/Storage/Plugin.pm
index 7f04e85..6e321ae 100644
--- a/PVE/Storage/Plugin.pm
+++ b/PVE/Storage/Plugin.pm
@@ -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',
-- 
2.20.1





  reply	other threads:[~2020-07-09 12:46 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-09 12:45 [pve-devel] [PATCH-SERIES v4] fix #2649: introduce prune-backups property for storages supporting backups Fabian Ebner
2020-07-09 12:45 ` Fabian Ebner [this message]
2020-07-24 17:07   ` [pve-devel] applied: [PATCH v4 storage 1/7] Introduce prune-backups property for directory-based storages Thomas Lamprecht
2020-07-09 12:45 ` [pve-devel] [PATCH v4 storage 2/7] Add prune_backups to storage API Fabian Ebner
2020-07-24 17:07   ` [pve-devel] applied: " Thomas Lamprecht
2020-07-09 12:45 ` [pve-devel] [PATCH v4 storage 3/7] Add API and pvesm call for prune_backups Fabian Ebner
2020-07-13  7:04   ` Fabian Ebner
2020-07-24 17:08   ` Thomas Lamprecht
2020-07-09 12:45 ` [pve-devel] [PATCH v4 guest-common 4/7] Add prune-backups option to vzdump parameters Fabian Ebner
2020-08-20 15:39   ` [pve-devel] applied: " Thomas Lamprecht
2020-07-09 12:45 ` [pve-devel] [PATCH v4 manager 5/7] make use of archive_info and archive_remove Fabian Ebner
2020-08-21 11:31   ` [pve-devel] applied: " Thomas Lamprecht
2020-07-09 12:45 ` [pve-devel] [PATCH v4 manager 6/7] Allow prune-backups as an alternative to maxfiles Fabian Ebner
2020-07-09 12:45 ` [pve-devel] [PATCH v4 manager 7/7] Always use prune-backups instead of maxfiles internally Fabian Ebner
2020-08-21 11:33   ` Thomas Lamprecht
2020-08-24  7:25     ` Fabian Ebner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200709124547.2913-2-f.ebner@proxmox.com \
    --to=f.ebner@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal