From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 7C70A1FF15C for ; Wed, 18 Sep 2024 17:28:26 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id AB6438289; Wed, 18 Sep 2024 17:28:34 +0200 (CEST) From: Christian Ebner To: pbs-devel@lists.proxmox.com Date: Wed, 18 Sep 2024 17:27:16 +0200 Message-Id: <20240918152716.511337-5-c.ebner@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240918152716.511337-1-c.ebner@proxmox.com> References: <20240918152716.511337-1-c.ebner@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.024 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 Subject: [pbs-devel] [PATCH v5 proxmox-backup 4/4] fix #2996: client: allow optional match patterns for restore X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox Backup Server development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pbs-devel-bounces@lists.proxmox.com Sender: "pbs-devel" When the user is only interested in a subset of the entries stored in a file-level backup, it is convenient to be able to provide a list of match patterns for the entries intended to be restored. The required restore logic is already in place. Therefore, expose it for the `proxmox-backup-client restore` command by adding the optional array of patterns as command line argument and parse these before passing them via the pxar restore options to the archive extractor. Link to bugtracker issue: https://bugzilla.proxmox.com/show_bug.cgi?id=2996 Signed-off-by: Christian Ebner --- changes since version 4: - rebased on current master proxmox-backup-client/src/main.rs | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/proxmox-backup-client/src/main.rs b/proxmox-backup-client/src/main.rs index e4034aa99..817235dbe 100644 --- a/proxmox-backup-client/src/main.rs +++ b/proxmox-backup-client/src/main.rs @@ -26,9 +26,9 @@ use pxar::accessor::{MaybeReady, ReadAt, ReadAtOperation}; use pbs_api_types::{ Authid, BackupDir, BackupGroup, BackupNamespace, BackupPart, BackupType, ClientRateLimitConfig, - CryptMode, Fingerprint, GroupListItem, PruneJobOptions, PruneListItem, RateLimitConfig, - SnapshotListItem, StorageStatus, BACKUP_ID_SCHEMA, BACKUP_NAMESPACE_SCHEMA, BACKUP_TIME_SCHEMA, - BACKUP_TYPE_SCHEMA, + CryptMode, Fingerprint, GroupListItem, PathPatterns, PruneJobOptions, PruneListItem, + RateLimitConfig, SnapshotListItem, StorageStatus, BACKUP_ID_SCHEMA, BACKUP_NAMESPACE_SCHEMA, + BACKUP_TIME_SCHEMA, BACKUP_TYPE_SCHEMA, }; use pbs_client::catalog_shell::Shell; use pbs_client::pxar::{ErrorHandler as PxarErrorHandler, MetadataArchiveReader, PxarPrevRef}; @@ -1394,6 +1394,10 @@ We do not extract '.pxar' archives when writing to standard output. type: ClientRateLimitConfig, flatten: true, }, + pattern: { + type: PathPatterns, + optional: true, + }, "allow-existing-dirs": { type: Boolean, description: "Do not fail if directories already exists.", @@ -1503,6 +1507,21 @@ async fn restore( let target = json::required_string_param(¶m, "target")?; let target = if target == "-" { None } else { Some(target) }; + let mut match_list = Vec::new(); + if let Some(pattern) = param["pattern"].as_array() { + if target.is_none() { + bail!("patterns not allowed when restoring to stdout"); + } + + for p in pattern { + if let Some(pattern) = p.as_str() { + let match_entry = + MatchEntry::parse_pattern(pattern, PatternFlag::PATH_NAME, MatchType::Include)?; + match_list.push(match_entry); + } + } + }; + let crypto = crypto_parameters(¶m)?; let crypt_config = match crypto.enc_key { @@ -1622,8 +1641,8 @@ async fn restore( let prelude_path = param["prelude-target"].as_str().map(PathBuf::from); let options = pbs_client::pxar::PxarExtractOptions { - match_list: &[], - extract_match_default: true, + match_list: &match_list, + extract_match_default: match_list.is_empty(), allow_existing_dirs, overwrite_flags, on_error, -- 2.39.2 _______________________________________________ pbs-devel mailing list pbs-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel