From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 776FA1FF16F for ; Tue, 16 Sep 2025 14:36:53 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id D413013CD8; Tue, 16 Sep 2025 14:37:06 +0200 (CEST) From: Filip Schauer To: pve-devel@lists.proxmox.com Date: Tue, 16 Sep 2025 14:32:51 +0200 Message-ID: <20250916123257.107491-7-f.schauer@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250916123257.107491-1-f.schauer@proxmox.com> References: <20250916123257.107491-1-f.schauer@proxmox.com> MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1758026216233 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.007 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] [PATCH storage v8 6/9] api: content: support copying backups between path based storages X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox VE development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" This commit adds support for the "backup+meta" export format. When this format is used, the notes and protection flag of the backup are included in the metadata header. Signed-off-by: Filip Schauer --- src/PVE/API2/Storage/Content.pm | 11 +++++++++-- src/PVE/Storage/Plugin.pm | 25 ++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/PVE/API2/Storage/Content.pm b/src/PVE/API2/Storage/Content.pm index c69b859..cfe4f2f 100644 --- a/src/PVE/API2/Storage/Content.pm +++ b/src/PVE/API2/Storage/Content.pm @@ -544,7 +544,8 @@ __PACKAGE__->register_method({ permissions => { description => "If the --delete option is used, the 'Datastore.Allocate' privilege is" . " required on the source storage." - . " Without --delete, 'Datastore.AllocateSpace' is required on the target storage.", + . " Without --delete, 'Datastore.AllocateSpace' is required on the target storage." + . " When moving a backup, 'VM.Backup' is required on the VM or container.", user => 'all', }, protected => 1, @@ -610,7 +611,7 @@ __PACKAGE__->register_method({ die "use pct move-volume or qm disk move\n" 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(); @@ -619,6 +620,12 @@ __PACKAGE__->register_method({ if ($delete) { $rpcenv->check($user, "/storage/$src_storeid", ["Datastore.Allocate"]); + + if ($vtype eq 'backup') { + my $protected = + PVE::Storage::get_volume_attribute($cfg, $src_volid, 'protected'); + die "cannot delete protected backup\n" if $protected; + } } $rpcenv->check($user, "/storage/$dst_storeid", ["Datastore.AllocateSpace"]); diff --git a/src/PVE/Storage/Plugin.pm b/src/PVE/Storage/Plugin.pm index 29628ed..92c4820 100644 --- a/src/PVE/Storage/Plugin.pm +++ b/src/PVE/Storage/Plugin.pm @@ -2114,6 +2114,17 @@ sub volume_export { format => $data_format, }; + if ($vtype eq 'backup') { + $meta->{protected} = + $class->get_volume_attribute($scfg, $storeid, $volname, 'protected') + ? JSON::true + : JSON::false; + $meta->{notes} = Encode::encode( + 'utf8', + $class->get_volume_attribute($scfg, $storeid, $volname, 'notes'), + ) // ""; + } + write_meta_header($fh, $meta); write_common_header($fh, $size); if ($data_format =~ /^(raw|ova|ovf|qcow2|vmdk)$/) { @@ -2157,6 +2168,7 @@ sub volume_export_formats { return (); } return ("$vtype+meta", 'tar+size') if $format eq 'subvol'; + return ('backup+meta') if $vtype eq 'backup'; return ("$vtype+meta", 'raw+size') if $vtype =~ /^(iso|snippets|vztmpl|import)$/; } return (); @@ -2252,7 +2264,7 @@ sub volume_import { warn $@ if $@; die $err; } - } elsif (grep { $vtype eq $_ } qw(import iso snippets vztmpl)) { + } elsif (grep { $vtype eq $_ } qw(import iso snippets vztmpl backup)) { eval { run_command(['dd', "of=$file", 'conv=excl', 'bs=64k'], input => '<&' . fileno($fh)); }; @@ -2263,6 +2275,16 @@ sub volume_import { } die $err; } + + if ($vtype eq 'backup' && defined($meta)) { + if (defined($meta->{notes})) { + my $notes = Encode::decode('utf8', $meta->{notes}); + $class->update_volume_attribute($scfg, $storeid, $volname, 'notes', $notes); + } + + $class->update_volume_attribute($scfg, $storeid, $volname, 'protected', 1) + if $meta->{protected}; + } } else { die "importing volume of type '$vtype' not implemented\n"; } @@ -2280,6 +2302,7 @@ sub volume_import_formats { return (); } return ("$vtype+meta", 'tar+size') if $format eq 'subvol'; + return ('backup+meta') if $vtype eq 'backup'; return ("$vtype+meta", 'raw+size') if $vtype =~ /^(iso|snippets|vztmpl|import)$/; } return (); -- 2.47.3 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel