public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Filip Schauer <f.schauer@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH storage v8 6/9] api: content: support copying backups between path based storages
Date: Tue, 16 Sep 2025 14:32:51 +0200	[thread overview]
Message-ID: <20250916123257.107491-7-f.schauer@proxmox.com> (raw)
In-Reply-To: <20250916123257.107491-1-f.schauer@proxmox.com>

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 <f.schauer@proxmox.com>
---
 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


  parent reply	other threads:[~2025-09-16 12:36 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-16 12:32 [pve-devel] [PATCH storage v8 0/9] support copying volumes between storages Filip Schauer
2025-09-16 12:32 ` [pve-devel] [PATCH storage v8 1/9] storage migrate: remove remnant from rsync-based migration Filip Schauer
2025-09-16 12:32 ` [pve-devel] [PATCH storage v8 2/9] storage migrate: avoid ssh when moving a volume locally Filip Schauer
2025-09-16 12:32 ` [pve-devel] [PATCH storage v8 3/9] plugin: allow volume import of iso, snippets, vztmpl and import Filip Schauer
2025-09-16 12:32 ` [pve-devel] [PATCH storage v8 4/9] api: content: implement copying volumes between storages Filip Schauer
2025-09-16 12:32 ` [pve-devel] [PATCH storage v8 5/9] introduce $vtype+meta export formats Filip Schauer
2025-09-16 12:32 ` Filip Schauer [this message]
2025-09-16 12:32 ` [pve-devel] [PATCH storage v8 7/9] storage: introduce decompress_archive_into_pipe helper Filip Schauer
2025-09-16 12:32 ` [pve-devel] [PATCH storage v8 8/9] support copying VMA backups to PBS Filip Schauer
2025-09-16 12:32 ` [pve-devel] [PATCH storage v8 9/9] pvesm: add a copy-volume command Filip Schauer

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=20250916123257.107491-7-f.schauer@proxmox.com \
    --to=f.schauer@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