From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 CF09A98835 for ; Mon, 9 Oct 2023 13:52:18 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 2DB4816D47 for ; Mon, 9 Oct 2023 13:52:17 +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 ; Mon, 9 Oct 2023 13:52:13 +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 9DE0A44928 for ; Mon, 9 Oct 2023 13:52:13 +0200 (CEST) From: Christian Ebner To: pbs-devel@lists.proxmox.com Date: Mon, 9 Oct 2023 13:51:37 +0200 Message-Id: <20231009115139.1417886-22-c.ebner@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231009115139.1417886-1-c.ebner@proxmox.com> References: <20231009115139.1417886-1-c.ebner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.081 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] [RFC v2 proxmox-backup 21/23] fix #3174: client: Add detection mode to backup creation 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: , X-List-Received-Date: Mon, 09 Oct 2023 11:52:18 -0000 Introduces the `change-detection-mode` parameter to change file encoding behavior. When set to `metadata`, the catalog for the previous backup run and the corresponding index file are fetched from the server and used as reference during pxar archive creation. This allows the archiver to skip encoding of file payloads for unchanged regular files and referencing their existing chunks to be included in the new backups index file instead, creating a pxar archive with appendix section containing the payloads as concatenation of chunks. Signed-off-by: Christian Ebner --- Changes since version 1: - Replace `incremental` flag with `change-detection-mode` param proxmox-backup-client/src/main.rs | 118 ++++++++++++++++++++++++++++-- 1 file changed, 110 insertions(+), 8 deletions(-) diff --git a/proxmox-backup-client/src/main.rs b/proxmox-backup-client/src/main.rs index cbdd9f43..478049f9 100644 --- a/proxmox-backup-client/src/main.rs +++ b/proxmox-backup-client/src/main.rs @@ -1,5 +1,6 @@ use std::collections::{HashSet, VecDeque}; use std::io::{self, Read, Seek, SeekFrom, Write}; +use std::os::unix::fs::OpenOptionsExt; use std::path::{Path, PathBuf}; use std::pin::Pin; use std::sync::{Arc, Mutex}; @@ -24,10 +25,11 @@ use proxmox_time::{epoch_i64, strftime_local}; use pxar::accessor::{MaybeReady, ReadAt, ReadAtOperation}; use pbs_api_types::{ - Authid, BackupDir, BackupGroup, BackupNamespace, BackupPart, BackupType, CryptMode, - Fingerprint, GroupListItem, PruneJobOptions, PruneListItem, RateLimitConfig, SnapshotListItem, - StorageStatus, BACKUP_ID_SCHEMA, BACKUP_NAMESPACE_SCHEMA, BACKUP_TIME_SCHEMA, - BACKUP_TYPE_SCHEMA, TRAFFIC_CONTROL_BURST_SCHEMA, TRAFFIC_CONTROL_RATE_SCHEMA, + Authid, BackupDetectionMode, BackupDir, BackupGroup, BackupNamespace, BackupPart, BackupType, + CryptMode, Fingerprint, GroupListItem, PruneJobOptions, PruneListItem, RateLimitConfig, + SnapshotListItem, StorageStatus, BACKUP_DETECTION_MODE_SCHEMA, BACKUP_ID_SCHEMA, + BACKUP_NAMESPACE_SCHEMA, BACKUP_TIME_SCHEMA, BACKUP_TYPE_SCHEMA, TRAFFIC_CONTROL_BURST_SCHEMA, + TRAFFIC_CONTROL_RATE_SCHEMA, }; use pbs_client::catalog_shell::Shell; use pbs_client::pxar::ErrorHandler as PxarErrorHandler; @@ -666,6 +668,10 @@ fn spawn_catalog_upload( schema: TRAFFIC_CONTROL_BURST_SCHEMA, optional: true, }, + "change-detection-mode": { + schema: BACKUP_DETECTION_MODE_SCHEMA, + optional: true, + }, "exclude": { type: Array, description: "List of paths or patterns for matching files to exclude.", @@ -849,7 +855,22 @@ async fn create_backup( let backup_time = backup_time_opt.unwrap_or_else(epoch_i64); - let client = connect_rate_limited(&repo, rate_limit)?; + let detection_mode: BackupDetectionMode = param["change-detection-mode"] + .as_str() + .unwrap_or("data") + .parse()?; + + let client = connect_rate_limited(&repo, rate_limit.clone())?; + let backup_group = BackupGroup::new(backup_type, backup_id); + + let previous_snapshot = if detection_mode == BackupDetectionMode::Metadata { + let snapshot = + api_datastore_latest_snapshot(&client, &repo.store(), &backup_ns, backup_group).await?; + Some(snapshot) + } else { + None + }; + record_repository(&repo); let snapshot = BackupDir::from((backup_type, backup_id.to_owned(), backup_time)); @@ -959,8 +980,8 @@ async fn create_backup( log::info!("{} {} '{}' to '{}' as {}", what, desc, file, repo, target); }; - for (backup_type, filename, target, size) in upload_list { - match (backup_type, dry_run) { + for (backup_spec_type, filename, target, size) in upload_list { + match (backup_spec_type, dry_run) { // dry-run (BackupSpecificationType::CONFIG, true) => log_file("config file", &filename, &target), (BackupSpecificationType::LOGFILE, true) => log_file("log file", &filename, &target), @@ -1006,12 +1027,44 @@ async fn create_backup( log_file("directory", &filename, &target); + let known_chunks = Arc::new(Mutex::new(HashSet::new())); + let previous_ref = if detection_mode == BackupDetectionMode::Metadata { + match previous_manifest { + None => None, + Some(ref manifest) => { + let reference_index = client + .download_previous_dynamic_index( + &target, + &manifest, + known_chunks.clone(), + ) + .await?; + + let reference_catalog = download_reference_catalog( + &repo, + previous_snapshot.as_ref().unwrap(), + &backup_ns, + crypt_config.clone(), + ) + .await?; + + Some(pbs_client::pxar::PxarPrevRef { + index: reference_index, + catalog: reference_catalog, + archive_name: target.clone(), + }) + } + } + } else { + None + }; + let pxar_options = pbs_client::pxar::PxarCreateOptions { device_set: devices.clone(), patterns: pattern_list.clone(), entries_max: entries_max as usize, skip_lost_and_found, - previous_ref: None, + previous_ref, archive_name: Some(std::ffi::CString::new(target.as_str())?), }; @@ -1112,6 +1165,55 @@ async fn create_backup( Ok(Value::Null) } +async fn download_reference_catalog( + repo: &BackupRepository, + previous_snapshot: &BackupDir, + backup_ns: &BackupNamespace, + crypt_config: Option>, +) -> Result, Error> { + let http_reader_client = connect(&repo)?; + let backup_reader = BackupReader::start( + http_reader_client, + crypt_config.clone(), + repo.store(), + &backup_ns, + &previous_snapshot, + true, + ) + .await?; + + let (manifest, _) = backup_reader.download_manifest().await?; + manifest.check_fingerprint(crypt_config.as_ref().map(Arc::as_ref))?; + + let index = backup_reader + .download_dynamic_index(&manifest, CATALOG_NAME) + .await?; + let most_used = index.find_most_used_chunks(8); + let file_info = manifest.lookup_file_info(CATALOG_NAME)?; + + let chunk_reader = RemoteChunkReader::new( + backup_reader, + crypt_config.clone(), + file_info.chunk_crypt_mode(), + most_used, + ); + + let mut reader = BufferedDynamicReader::new(index, chunk_reader); + + let mut catalogfile = std::fs::OpenOptions::new() + .write(true) + .read(true) + .custom_flags(libc::O_TMPFILE) + .open("/tmp")?; + + std::io::copy(&mut reader, &mut catalogfile) + .map_err(|err| format_err!("failed to download reference catalog - {}", err))?; + + catalogfile.seek(SeekFrom::Start(0))?; + + Ok(CatalogReader::new(catalogfile)) +} + async fn dump_image( client: Arc, crypt_config: Option>, -- 2.39.2