[pve-devel] [PATCH storage v6 3/7] api: content: support moving backups between path based storages

Fiona Ebner f.ebner at proxmox.com
Thu Feb 13 18:21:03 CET 2025


Am 20.01.25 um 12:28 schrieb Filip Schauer:
> This commit adds the "backup+size" export format. When this format is
> used, the data stream starts with metadata of the backup (protected flag
> & notes) followed by the contents of the backup archive.
> 
> Signed-off-by: Filip Schauer <f.schauer at proxmox.com>
> ---
>  src/PVE/API2/Storage/Content.pm | 15 ++++++++++--
>  src/PVE/Storage.pm              | 10 +++++++-
>  src/PVE/Storage/Plugin.pm       | 42 +++++++++++++++++++++++++++++----
>  3 files changed, 60 insertions(+), 7 deletions(-)
> 
> diff --git a/src/PVE/API2/Storage/Content.pm b/src/PVE/API2/Storage/Content.pm
> index ac451dc..9ee3c51 100644
> --- a/src/PVE/API2/Storage/Content.pm
> +++ b/src/PVE/API2/Storage/Content.pm
> @@ -548,10 +548,10 @@ __PACKAGE__->register_method ({
>  
>  	my $cfg = PVE::Storage::config();
>  
> -	my ($vtype) = PVE::Storage::parse_volname($cfg, $src_volid);
> +	my ($vtype, undef, $ownervm) = PVE::Storage::parse_volname($cfg, $src_volid);
>  	die "use pct move-volume or qm disk move" if $vtype eq 'images' || $vtype eq 'rootdir';
>  	die "moving volume of type '$vtype' not implemented\n"
> -	    if (!grep { $vtype eq $_ } qw(import iso snippets vztmpl));
> +	    if (!grep { $vtype eq $_ } qw(backup import iso snippets vztmpl));
>  
>  	my $rpcenv = PVE::RPCEnvironment::get();
>  	my $user = $rpcenv->get_user();
> @@ -560,10 +560,21 @@ __PACKAGE__->register_method ({
>  
>  	if ($delete) {
>  	    $rpcenv->check($user, "/storage/$src_storeid", ["Datastore.Allocate"]);
> +
> +	    if ($vtype eq 'backup') {
> +		my $src_cfg = PVE::Storage::storage_config($cfg, $src_storeid);
> +		my $src_plugin = PVE::Storage::Plugin->lookup($src_cfg->{type});
> +		my $protected = $src_plugin->get_volume_attribute($src_cfg, $src_storeid, $volname, 'protected');

I'd prefer this to use the function from the storage module rather than
calling into the plugin itself.

> +		die "cannot delete protected backup\n" if $protected;
> +	    }
>  	} else {
>  	    $rpcenv->check($user, "/storage/$dst_storeid", ["Datastore.AllocateSpace"]);
>  	}
>  
> +	if ($vtype eq 'backup' && $ownervm) {
> +	    $rpcenv->check($user, "/vms/$ownervm", ['VM.Backup']);
> +	}

Don't you just need to pass $ownervm to check_volume_access()? Because
having this check rules out a user with Datastore.Allocate to use the
API if they don't also have the backup permission.




More information about the pve-devel mailing list