From: "Fabian Grünbichler" <f.gruenbichler@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH storage 2/2] file-restore: pass in volume ID or name
Date: Fri, 23 Apr 2021 12:34:26 +0200 [thread overview]
Message-ID: <20210423103426.1245672-3-f.gruenbichler@proxmox.com> (raw)
In-Reply-To: <20210423103426.1245672-1-f.gruenbichler@proxmox.com>
instead of just the snapshot for consistency with other API endpoints,
and possible future extension to VMA backups (where 'snapshot' would be
a rather strange terminology).
add some additional checks (pbs storage type, backup volume type),
completion and magic (allow passing in either a full volume ID with
correct storage, or just the volume name, or just the snapshot for
easier API/CLI usage/convenience).
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
---
Notes:
requires corresponding patch on the GUI side as well since the parameter was renamed
the snapshot name convenience part could be dropped by replacing
+ } elsif ($volume =~ m/^backup\//) {
+ $volid = "$storeid:$volume";
+ } else {
+ $volid = "$storeid:backup/$volume";
+ }
with
+ } else {
+ $volid = "$storeid:$volume";
+ }
but since it basically applies as-is to VMA backups and passing in just
the filename, it might be nice to have..
PVE/API2/Storage/FileRestore.pm | 63 +++++++++++++++++++++++++++------
1 file changed, 52 insertions(+), 11 deletions(-)
diff --git a/PVE/API2/Storage/FileRestore.pm b/PVE/API2/Storage/FileRestore.pm
index f6dc74a..a4bad44 100644
--- a/PVE/API2/Storage/FileRestore.pm
+++ b/PVE/API2/Storage/FileRestore.pm
@@ -4,6 +4,7 @@ use strict;
use warnings;
use MIME::Base64;
+use PVE::Exception qw(raise_param_exc);
use PVE::JSONSchema qw(get_standard_option);
use PVE::PBSClient;
use PVE::Storage;
@@ -12,6 +13,26 @@ use PVE::Tools qw(extract_param);
use PVE::RESTHandler;
use base qw(PVE::RESTHandler);
+my $parse_volname_or_id = sub {
+ my ($storeid, $volume) = @_;
+
+ my $volid;
+ my ($sid, $volname) = PVE::Storage::parse_volume_id($volume, 1);
+
+ if (defined($sid)) {
+ raise_param_exc({ volume => "storage ID mismatch ($sid != $storeid)." })
+ if $sid ne $storeid;
+
+ $volid = $volume;
+ } elsif ($volume =~ m/^backup\//) {
+ $volid = "$storeid:$volume";
+ } else {
+ $volid = "$storeid:backup/$volume";
+ }
+
+ return $volid;
+};
+
__PACKAGE__->register_method ({
name => 'list',
path => 'list',
@@ -26,10 +47,13 @@ __PACKAGE__->register_method ({
additionalProperties => 0,
properties => {
node => get_standard_option('pve-node'),
- storage => get_standard_option('pve-storage-id'),
- snapshot => {
- description => "Backup snapshot identifier.",
+ storage => get_standard_option('pve-storage-id', {
+ completion => \&PVE::Storage::complete_storage_enabled,
+ }),
+ volume => {
+ description => "Backup volume ID or name. Currently only PBS snapshots are supported.",
type => 'string',
+ completion => \&PVE::Storage::complete_volume,
},
filepath => {
description => 'base64-path to the directory or file being listed, or "/".',
@@ -80,18 +104,25 @@ __PACKAGE__->register_method ({
my $path = extract_param($param, 'filepath') || "/";
my $base64 = $path ne "/";
- my $snap = extract_param($param, 'snapshot');
+
my $storeid = extract_param($param, 'storage');
+
+ my $volid = $parse_volname_or_id->($storeid, $param->{volume});
my $cfg = PVE::Storage::config();
my $scfg = PVE::Storage::storage_config($cfg, $storeid);
- my $volid = "$storeid:backup/$snap";
PVE::Storage::check_volume_access($rpcenv, $user, $cfg, undef, $volid);
+ raise_param_exc({'storage' => "Only PBS storages supported for file-restore."})
+ if $scfg->{type} ne 'pbs';
+
+ my ($vtype, $snap) = PVE::Storage::parse_volname($cfg, $volid);
+ raise_param_exc({'volume' => 'Not a backup archive.'})
+ if $vtype ne 'backup';
+
my $client = PVE::PBSClient->new($scfg, $storeid);
my $ret = $client->file_restore_list($snap, $path, $base64);
-
# 'leaf' is a proper JSON boolean, map to perl-y bool
# TODO: make PBSClient decode all bools always as 1/0?
foreach my $item (@$ret) {
@@ -115,10 +146,13 @@ __PACKAGE__->register_method ({
additionalProperties => 0,
properties => {
node => get_standard_option('pve-node'),
- storage => get_standard_option('pve-storage-id'),
- snapshot => {
- description => "Backup snapshot identifier.",
+ storage => get_standard_option('pve-storage-id', {
+ completion => \&PVE::Storage::complete_storage_enabled,
+ }),
+ volume => {
+ description => "Backup volume ID or name. Currently only PBS snapshots are supported.",
type => 'string',
+ completion => \&PVE::Storage::complete_volume,
},
filepath => {
description => 'base64-path to the directory or file to download.',
@@ -137,14 +171,21 @@ __PACKAGE__->register_method ({
my $user = $rpcenv->get_user();
my $path = extract_param($param, 'filepath');
- my $snap = extract_param($param, 'snapshot');
my $storeid = extract_param($param, 'storage');
+ my $volid = $parse_volname_or_id->($storeid, $param->{volume});
+
my $cfg = PVE::Storage::config();
my $scfg = PVE::Storage::storage_config($cfg, $storeid);
- my $volid = "$storeid:backup/$snap";
PVE::Storage::check_volume_access($rpcenv, $user, $cfg, undef, $volid);
+ raise_param_exc({'storage' => "Only PBS storages supported for file-restore."})
+ if $scfg->{type} ne 'pbs';
+
+ my ($vtype, $snap) = PVE::Storage::parse_volname($cfg, $volid);
+ raise_param_exc({'volume' => 'Not a backup archive.'})
+ if $vtype ne 'backup';
+
my $client = PVE::PBSClient->new($scfg, $storeid);
my $fifo = $client->file_restore_extract_prepare();
--
2.20.1
next prev parent reply other threads:[~2021-04-23 10:34 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-22 15:34 [pve-devel] [PATCH v2 00/13] Single-file-restore GUI for PBS snapshots Stefan Reiter
2021-04-22 15:34 ` [pve-devel] [PATCH v2 proxmox-backup 01/13] file-restore: don't force PBS_FINGERPRINT env var Stefan Reiter
2021-04-22 17:07 ` [pve-devel] applied: [pbs-devel] " Thomas Lamprecht
2021-04-22 15:34 ` [pve-devel] [PATCH v2 proxmox-backup 02/13] client-tools: add crypto_parameters_keep_fd Stefan Reiter
2021-04-22 17:07 ` [pve-devel] applied: [pbs-devel] " Thomas Lamprecht
2021-04-22 15:34 ` [pve-devel] [PATCH v2 proxmox-backup 03/13] file-restore: support encrypted VM backups Stefan Reiter
2021-04-22 17:07 ` [pve-devel] applied: [pbs-devel] " Thomas Lamprecht
2021-04-22 15:34 ` [pve-devel] [PATCH v2 common 04/13] PBSClient: adapt error message to include full package names Stefan Reiter
2021-04-23 12:17 ` [pve-devel] applied: " Thomas Lamprecht
2021-04-22 15:34 ` [pve-devel] [PATCH v2 common 05/13] PBSClient: add file_restore_list command Stefan Reiter
2021-04-23 12:17 ` [pve-devel] applied: " Thomas Lamprecht
2021-04-22 15:34 ` [pve-devel] [PATCH v2 common 06/13] PBSClient: add file_restore_extract function Stefan Reiter
2021-04-23 12:17 ` [pve-devel] applied: " Thomas Lamprecht
2021-04-22 15:34 ` [pve-devel] [PATCH v2 common 07/13] PBSClient: use crypt params for file 'list' and 'extract' Stefan Reiter
2021-04-22 19:14 ` Thomas Lamprecht
2021-04-23 12:18 ` [pve-devel] applied: " Thomas Lamprecht
2021-04-22 15:34 ` [pve-devel] [PATCH v2 http-server 08/13] support streaming data form fh to client Stefan Reiter
2021-04-23 11:56 ` [pve-devel] applied: " Thomas Lamprecht
2021-04-22 15:34 ` [pve-devel] [PATCH v2 http-server 09/13] allow stream download from path and over pvedaemon-proxy Stefan Reiter
2021-04-23 11:56 ` [pve-devel] applied: " Thomas Lamprecht
2021-04-22 15:34 ` [pve-devel] [PATCH v2 storage 10/13] add FileRestore API for PBS Stefan Reiter
2021-04-23 10:34 ` [pve-devel] [PATCH manager] file-restore: pass in full volume ID Fabian Grünbichler
2021-04-23 10:34 ` [pve-devel] [PATCH storage 1/2] file-restore: return perl-y booleans Fabian Grünbichler
2021-04-23 10:34 ` Fabian Grünbichler [this message]
2021-04-22 15:34 ` [pve-devel] [PATCH v2 proxmox-widget-toolkit 11/13] Utils: add errorCallback to monStoreErrors Stefan Reiter
2021-04-22 18:41 ` [pve-devel] applied: " Thomas Lamprecht
2021-04-22 15:34 ` [pve-devel] [PATCH v2 proxmox-widget-toolkit 12/13] FileBrowser: support 'virtual'/'v' file type Stefan Reiter
2021-04-22 18:41 ` [pve-devel] applied: " Thomas Lamprecht
2021-04-22 15:34 ` [pve-devel] [PATCH v2 proxmox-widget-toolkit 13/13] FileBrowser: show errors in messagebox and allow expand 'all' Stefan Reiter
2021-04-22 18:41 ` [pve-devel] applied: " Thomas Lamprecht
2021-04-22 15:47 ` [pve-devel] [PATCH v2 manager 1/2] backupview: add file restore button Stefan Reiter
2021-04-22 15:47 ` [pve-devel] [PATCH v2 manager 2/2] gui: add task name for 'pbs-download' Stefan Reiter
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=20210423103426.1245672-3-f.gruenbichler@proxmox.com \
--to=f.gruenbichler@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