public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [PATCH 1/2] manager: add API endpoint for streamed VM backup export
  2026-06-26 16:43 [PATCH 0/2] RFC: manager: add direct VM backup export/import support Mauro de Pascale
@ 2026-06-26 16:43 ` Mauro de Pascale
  0 siblings, 0 replies; 2+ messages in thread
From: Mauro de Pascale @ 2026-06-26 16:43 UTC (permalink / raw)
  To: pve-devel@lists.proxmox.com; +Cc: Mauro de Pascale

From: Mauro de Pascale <mauro.depascale.work@outlook.it>

Add an API endpoint that exposes vzdump output as a streamed download,
allowing clients to export VM backups directly without storing them on
the server first.
---
 PVE/API2/VZDump.pm | 65 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 65 insertions(+)

diff --git a/PVE/API2/VZDump.pm b/PVE/API2/VZDump.pm
index a8f21eba..84f42352 100644
--- a/PVE/API2/VZDump.pm
+++ b/PVE/API2/VZDump.pm
@@ -9,11 +9,15 @@ use PVE::Exception qw(raise_param_exc);
 use PVE::INotify;
 use PVE::JSONSchema qw(get_standard_option);
 use PVE::RPCEnvironment;
+use PVE::SafeSyslog;
 use PVE::Storage;
 use PVE::Tools qw(extract_param);
 use PVE::VZDump::Common;
 use PVE::VZDump;
 
+use IPC::Open3;
+use Symbol qw(gensym);
+
 use PVE::API2::Backup;
 use PVE::API2Tools;
 
@@ -311,4 +315,65 @@ __PACKAGE__->register_method({
     },
 });
 
+__PACKAGE__->register_method({
+    name => 'export',
+    path => 'export',
+    method => 'GET',
+    description => "Export a VM dump stream",
+    proxyto => 'node',
+    protected => 1,
+    permissions => {
+        check => ['perm', '/vms/{vmid}', ['VM.Backup']],
+    },
+    parameters => {
+        additionalProperties => 0,
+        properties => {
+            node => get_standard_option('pve-node'),
+            vmid => get_standard_option('pve-vmid'),
+            compress => {
+		description => "compression algorithm to use.",
+                type => 'string',
+                enum => ['zstd', 'gzip', 'lzo', '0'],
+                optional => 1,
+                default => 'zstd',
+            },
+        },
+    },
+    returns => { type => 'object' },
+    download => 1,
+    code => sub {
+        my ($param) = @_;
+
+        my $vmid = $param->{vmid};
+        my $compress = $param->{compress} // 'zstd';
+
+        my $suffix = $compress eq 'zstd' ? 'zst'
+                    : $param->{compress} eq 'gzip' ? 'gz'
+                    : $param->{compress} eq 'lzo'  ? 'lzo'
+                    : 'vma';
+       
+	my $filename = "vzdump-qemu-$vmid.vma.$suffix";
+
+	my $cmd = ['/usr/bin/vzdump', $vmid, '--stdout','1','--compress',$compress];
+	my $cmdstr = join(' ', @$cmd);
+	syslog('info', "running export cmd: $cmdstr");
+
+	#my ($fh, $pid) = PVE::Tools::run_command($cmd, pipe => 1);
+	open my $fh, '-|', @$cmd
+	    or die "unable to execute backup $!\n";
+
+        binmode($fh);
+
+
+        return {
+	   download => {
+		fh => $fh,
+		filename => $filename,
+		stream => 1,
+		'content-type' => 'application/octet-stream',
+		'content-disposition' => "attachment; filename=\"$filename\"",
+	   }
+	};
+    }});
+
 1;
-- 
2.47.3




^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH 1/2] manager: add API endpoint for streamed VM backup export
@ 2026-09-23 12:25 Mauro de Pascale
  0 siblings, 0 replies; 2+ messages in thread
From: Mauro de Pascale @ 2026-09-23 12:25 UTC (permalink / raw)
  To: pve-devel@lists.proxmox.com

From: Mauro de Pascale <mauro.depascale.work@outlook.it>
Add an API endpoint that exposes vzdump output as a streamed download,
allowing clients to export VM backups directly without storing them on
the server first.
________________________________
PVE/API2/VZDump.pm | 65 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 65 insertions(+)
diff --git a/PVE/API2/VZDump.pm b/PVE/API2/VZDump.pm
index a8f21eba..84f42352 100644
--- a/PVE/API2/VZDump.pm
+++ b/PVE/API2/VZDump.pm
@@ -9,11 +9,15 @@ use PVE::Exception qw(raise_param_exc);
use PVE::INotify;
use PVE::JSONSchema qw(get_standard_option);
use PVE::RPCEnvironment;
+use PVE::SafeSyslog;
use PVE::Storage;
use PVE::Tools qw(extract_param);
use PVE::VZDump::Common;
use PVE::VZDump;
+use IPC::Open3;
+use Symbol qw(gensym);
+
use PVE::API2::Backup;
use PVE::API2Tools;
@@ -311,4 +315,65 @@ __PACKAGE__->register_method({
},
});
+__PACKAGE__->register_method({

  *
name => 'export',
  *
path => 'export',
  *
method => 'GET',
  *
description => "Export a VM dump stream",
  *
proxyto => 'node',
  *
protected => 1,
  *
permissions => {
  *
check => ['perm', '/vms/{vmid}', ['VM.Backup']],
  *
},
  *
parameters => {
  *
additionalProperties => 0,
  *
properties => {
  *
node => get_standard_option('pve-node'),
  *
vmid => get_standard_option('pve-vmid'),
  *
compress => {
  *
description => "compression algorithm to use.",
  *
type => 'string',
  *
enum => ['zstd', 'gzip', 'lzo', '0'],
  *
optional => 1,
  *
default => 'zstd',
  *
},
  *
},
  *
},
  *
returns => { type => 'object' },
  *
download => 1,
  *
code => sub {
  *
my ($param) = @_;
  *

  *
my $vmid = $param->{vmid};
  *
my $compress = $param->{compress} // 'zstd';
  *

  *
my $suffix = $compress eq 'zstd' ? 'zst'
  *
: $param->{compress} eq 'gzip' ? 'gz'
  *
: $param->{compress} eq 'lzo' ? 'lzo'
  *
: 'vma';
  *

  *
my $filename = "vzdump-qemu-$vmid.vma.$suffix";
  *

  *
my $cmd = ['/usr/bin/vzdump', $vmid, '--stdout','1','--compress',$compress];
  *
my $cmdstr = join(' ', @$cmd);
  *
syslog('info', "running export cmd: $cmdstr");
  *

  *
#my ($fh, $pid) = PVE::Tools::run_command($cmd, pipe => 1);
  *
open my $fh, '-|', @$cmd
  *
or die "unable to execute backup $!
";
  *

  *
binmode($fh);
  *

  *

  *
return {
  *
download => {
  *
fh => $fh,
  *
filename => $filename,
  *
stream => 1,
  *
'content-type' => 'application/octet-stream',
  *
'content-disposition' => "attachment; filename="$filename"",
  *
}
  *
};
  *
}});
  *

     *
1;
  *
--
2.47.3



^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-09-23 12:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-23 12:25 [PATCH 1/2] manager: add API endpoint for streamed VM backup export Mauro de Pascale
  -- strict thread matches above, loose matches on Subject: below --
2026-06-26 16:43 [PATCH 0/2] RFC: manager: add direct VM backup export/import support Mauro de Pascale
2026-06-26 16:43 ` [PATCH 1/2] manager: add API endpoint for streamed VM backup export Mauro de Pascale

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