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 <[email protected]>
---
Unchanged since v8

 src/PVE/API2/Storage/Content.pm | 10 ++++++++--
 src/PVE/Storage/Plugin.pm       | 25 ++++++++++++++++++++++++-
 2 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/src/PVE/API2/Storage/Content.pm b/src/PVE/API2/Storage/Content.pm
index 201d839..ea811ec 100644
--- a/src/PVE/API2/Storage/Content.pm
+++ b/src/PVE/API2/Storage/Content.pm
@@ -544,7 +544,7 @@ __PACKAGE__->register_method({
     permissions => {
         description => "If the --delete option is used, the 
'Datastore.Allocate' privilege is"
             . " required on the source storage. 'Datastore.AllocateSpace' is 
required on the target"
-            . " storage.",
+            . " storage. When moving a backup, 'VM.Backup' is required on the 
VM or container.",
         user => 'all',
     },
     protected => 1,
@@ -600,7 +600,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 ($dst_storeid, $dst_volname);
         if ($param->{target} =~ m/:/) {
@@ -627,6 +627,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 3a83459..437a677 100644
--- a/src/PVE/Storage/Plugin.pm
+++ b/src/PVE/Storage/Plugin.pm
@@ -2186,6 +2186,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)$/) {
@@ -2229,6 +2240,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 =~ 
/^(images|iso|snippets|vztmpl|import)$/;
     }
     return ();
@@ -2324,7 +2336,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));
         };
@@ -2335,6 +2347,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";
     }
@@ -2352,6 +2374,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 =~ 
/^(images|iso|snippets|vztmpl|import)$/;
     }
     return ();
-- 
2.47.3



_______________________________________________
pve-devel mailing list
[email protected]
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to