[pve-devel] [PATCH storage 2/2] plugins: allow limiting the number of protected backups per guest

Thomas Lamprecht t.lamprecht at proxmox.com
Wed Mar 16 17:42:09 CET 2022


On 16.12.21 13:12, Fabian Ebner wrote:
> The ability to mark backups as protected broke the implicit assumption
> in vzdump that remove=1 and current number of backups being the limit
> (i.e. sum of all keep options) will result in a backup being removed.
> 
> Introduce a new storage property 'max-protected-backups' to limit the
> number of protected backups per guest. Use 5 as a default value, as it
> should cover most use cases, while still not having too big of a
> potential overhead in many scenarios.
> 
> For external plugins that do not return the backup subtype in
> list_volumes, all protected backups with the same ID will count
> towards the limit.
> 
> An alternative would be to count the protected backups when pruning.
> While that would avoid the need for a new property, it would break the
> current semantics of protected backups being ignored for pruning. It
> also would be less flexible, e.g. for PBS, it can make sense to have
> both keep-all=1 and a limit for the number of protected snapshots on
> the PVE side.
> 
> Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
> ---
>  PVE/Storage.pm                 | 24 ++++++++++++++++++++++++
>  PVE/Storage/BTRFSPlugin.pm     |  3 ++-
>  PVE/Storage/CIFSPlugin.pm      |  1 +
>  PVE/Storage/CephFSPlugin.pm    |  1 +
>  PVE/Storage/DirPlugin.pm       |  1 +
>  PVE/Storage/GlusterfsPlugin.pm |  1 +
>  PVE/Storage/NFSPlugin.pm       |  1 +
>  PVE/Storage/PBSPlugin.pm       |  1 +
>  PVE/Storage/Plugin.pm          |  7 +++++++
>  9 files changed, 39 insertions(+), 1 deletion(-)
> 
> diff --git a/PVE/Storage.pm b/PVE/Storage.pm
> index d64019f..0643fad 100755
> --- a/PVE/Storage.pm
> +++ b/PVE/Storage.pm
> @@ -232,6 +232,30 @@ sub update_volume_attribute {
>      my $scfg = storage_config($cfg, $storeid);
>      my $plugin = PVE::Storage::Plugin->lookup($scfg->{type});
>  
> +    my ($vtype, undef, $vmid) = $plugin->parse_volname($volname);
> +    my $max_protected_backups = $scfg->{'max-protected-backups'} // 5;

maybe the default limit should be user privilege dependent? E.g., for root and users
with .Allocate on the storage it wouldn't be a problem to have unlimited (or a higher
count) as default? I mean, it's naturally a bit odd to differ, but one can argue a lot
with auto-magic-convenience ;P

> +
> +    if (
> +	$vtype eq 'backup'
> +	&& $vmid
> +	&& $attribute eq 'protected'
> +	&& $value
> +	&& !$plugin->get_volume_attribute($scfg, $storeid, $volname, 'protected')
> +	&& $max_protected_backups > -1 # -1 is unlimited
> +    ) {
> +	my $backups = $plugin->list_volumes($storeid, $scfg, $vmid, ['backup']);
> +	my ($backup_type) = map { $_->{subtype} } grep { $_->{volid} eq $volid } $backups->@*;
> +
> +	my $protected_count = grep {
> +	    $_->{protected} && (!$backup_type || ($_->{subtype} && $_->{subtype} eq $backup_type))
> +	} $backups->@*;
> +
> +	if ($max_protected_backups <= $protected_count) {
> +	    die "The number of protected backups per guest is limited to $max_protected_backups ".
> +		"on storage '$storeid'\n";
> +	}
> +    }
> +
>      return $plugin->update_volume_attribute($scfg, $storeid, $volname, $attribute, $value);
>  }






More information about the pve-devel mailing list