From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <d.csapak@proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by lists.proxmox.com (Postfix) with ESMTPS id 407C59DD5A
 for <pbs-devel@lists.proxmox.com>; Tue,  6 Jun 2023 11:20:47 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id 2092432343
 for <pbs-devel@lists.proxmox.com>; Tue,  6 Jun 2023 11:20:47 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com
 [94.136.29.106])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by firstgate.proxmox.com (Proxmox) with ESMTPS
 for <pbs-devel@lists.proxmox.com>; Tue,  6 Jun 2023 11:20:46 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1])
 by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 2D8B448C62
 for <pbs-devel@lists.proxmox.com>; Tue,  6 Jun 2023 11:20:46 +0200 (CEST)
From: Dominik Csapak <d.csapak@proxmox.com>
To: pbs-devel@lists.proxmox.com
Date: Tue,  6 Jun 2023 11:20:45 +0200
Message-Id: <20230606092045.1782511-1-d.csapak@proxmox.com>
X-Mailer: git-send-email 2.30.2
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.015 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DMARC_MISSING             0.1 Missing DMARC policy
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
 T_SCC_BODY_TEXT_LINE    -0.01 -
Subject: [pbs-devel] [PATCH proxmox-backup] ui: tape: fix restore datastore
 mapping parameter construction
X-BeenThere: pbs-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox Backup Server development discussion
 <pbs-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pbs-devel>, 
 <mailto:pbs-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pbs-devel/>
List-Post: <mailto:pbs-devel@lists.proxmox.com>
List-Help: <mailto:pbs-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel>, 
 <mailto:pbs-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Tue, 06 Jun 2023 09:20:47 -0000

We recently took into account the selected datastore when restoring from
tape, but the snapshot grids value may not only be a single datastore, it can
also be a list of snapshots, datastores or 'all'.

handle these cases and extract the source datastore correctly.

This fixes tape restoration when not a whole datastore is selected.

Reported in the forum:
https://forum.proxmox.com/threads/restore-from-lto-parameter-verification-errors-store.128445

Fixes: df881ed0 ("ui: tape: fix restoring a single datastore")
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
this patch should also apply cleanly on the stable-2 branch currently

 www/tape/window/TapeRestore.js | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/www/tape/window/TapeRestore.js b/www/tape/window/TapeRestore.js
index 2ff7c4dd..c1d3493c 100644
--- a/www/tape/window/TapeRestore.js
+++ b/www/tape/window/TapeRestore.js
@@ -380,6 +380,19 @@ Ext.define('PBS.TapeManagement.TapeRestoreWindow', {
 			if (values.store.toString() !== "") {
 			    if (vm.get('singleDatastore')) {
 				let source = controller.lookup('snapshotGrid').getValue();
+				if (source === 'all') {
+				    // all values are selected
+				    source = values.store;
+				} else if (Ext.isArray(source)) {
+				    if (source[0].indexOf(':') !== -1) {
+					// one or multiple snapshots are selected
+					// extract datastore from first
+					source = source[0].split(':')[0];
+				    } else {
+					// one whole datstore is selected
+					source = source[0];
+				    }
+				}
 				datastores.push(`${source}=${values.store}`);
 			    } else {
 				datastores.push(values.store);
-- 
2.30.2