From: Mauro de Pascale <mauro.depascale.work@outlook.it>
To: "pve-devel@lists.proxmox.com" <pve-devel@lists.proxmox.com>
Cc: Mauro de Pascale <mauro.depascale.work@outlook.it>
Subject: [PATCH 1/2] manager: add API endpoint for streamed VM backup export
Date: Fri, 26 Jun 2026 16:43:57 +0000 [thread overview]
Message-ID: <20260626164354.44747-2-mauro.depascale.work@outlook.it> (raw)
In-Reply-To: <20260626164354.44747-1-mauro.depascale.work@outlook.it>
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
next prev parent reply other threads:[~2026-07-01 8:05 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2026-06-26 16:43 ` [PATCH 2/2] manager: add GUI support for backup export and import Mauro de Pascale
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=20260626164354.44747-2-mauro.depascale.work@outlook.it \
--to=mauro.depascale.work@outlook.it \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.