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 ECF9197F4C for ; Wed, 6 Mar 2024 15:35:00 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id CE0361A51A for ; Wed, 6 Mar 2024 15:34:30 +0100 (CET) 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 ; Wed, 6 Mar 2024 15:34:30 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id C428048850 for ; Wed, 6 Mar 2024 15:34:29 +0100 (CET) From: Gabriel Goller To: pbs-devel@lists.proxmox.com Date: Wed, 6 Mar 2024 15:34:12 +0100 Message-ID: <20240306143422.114335-3-g.goller@proxmox.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240306143422.114335-1-g.goller@proxmox.com> References: <20240306143422.114335-1-g.goller@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.095 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 2/3] client: unify parameters and write to file 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: Wed, 06 Mar 2024 14:35:01 -0000 Merge all the existing parameters of `create_backup` to the `serde_json::Value` parameter. Now only a single variable needs to be written to the `.pxar_creation_params` file. Pass the parameters down and encode it into the pxar archive. Signed-off-by: Gabriel Goller --- pbs-client/src/pxar/create.rs | 9 ++++++ pbs-client/src/pxar_backup_stream.rs | 5 +++- proxmox-backup-client/src/main.rs | 29 ++++++++++++------- .../src/proxmox_restore_daemon/api.rs | 2 +- pxar-bin/src/main.rs | 1 + tests/catar.rs | 1 + 6 files changed, 35 insertions(+), 12 deletions(-) diff --git a/pbs-client/src/pxar/create.rs b/pbs-client/src/pxar/create.rs index 0d5e8b68..437bf05b 100644 --- a/pbs-client/src/pxar/create.rs +++ b/pbs-client/src/pxar/create.rs @@ -142,6 +142,7 @@ pub async fn create_archive( callback: F, catalog: Option>>, options: PxarCreateOptions, + creation_command: String, ) -> Result<(), Error> where T: SeqWrite + Send, @@ -199,6 +200,14 @@ where skip_e2big_xattr: options.skip_e2big_xattr, }; + archiver + .encode_file( + &mut encoder, + &CString::new(".pxar_creation_params").unwrap(), + creation_command.as_bytes(), + ) + .await + .unwrap(); archiver .archive_dir_contents(&mut encoder, source_dir, true) .await?; diff --git a/pbs-client/src/pxar_backup_stream.rs b/pbs-client/src/pxar_backup_stream.rs index 22a6ffdc..52ed8f3c 100644 --- a/pbs-client/src/pxar_backup_stream.rs +++ b/pbs-client/src/pxar_backup_stream.rs @@ -40,6 +40,7 @@ impl PxarBackupStream { dir: Dir, catalog: Arc>>, options: crate::pxar::PxarCreateOptions, + creation_command: String, ) -> Result { let (tx, rx) = std::sync::mpsc::sync_channel(10); @@ -64,6 +65,7 @@ impl PxarBackupStream { }, Some(catalog), options, + creation_command, ) .await { @@ -87,10 +89,11 @@ impl PxarBackupStream { dirname: &Path, catalog: Arc>>, options: crate::pxar::PxarCreateOptions, + creation_command: String, ) -> Result { let dir = nix::dir::Dir::open(dirname, OFlag::O_DIRECTORY, Mode::empty())?; - Self::new(dir, catalog, options) + Self::new(dir, catalog, options, creation_command) } } diff --git a/proxmox-backup-client/src/main.rs b/proxmox-backup-client/src/main.rs index 546275cb..0160a177 100644 --- a/proxmox-backup-client/src/main.rs +++ b/proxmox-backup-client/src/main.rs @@ -191,8 +191,14 @@ async fn backup_directory>( catalog: Arc>>>>, pxar_create_options: pbs_client::pxar::PxarCreateOptions, upload_options: UploadOptions, + creation_command: String, ) -> Result { - let pxar_stream = PxarBackupStream::open(dir_path.as_ref(), catalog, pxar_create_options)?; + let pxar_stream = PxarBackupStream::open( + dir_path.as_ref(), + catalog, + pxar_create_options, + creation_command, + )?; let mut chunk_stream = ChunkStream::new(pxar_stream, chunk_size); let (tx, rx) = mpsc::channel(10); // allow to buffer 10 chunks @@ -677,10 +683,6 @@ fn spawn_catalog_upload( /// Create (host) backup. async fn create_backup( param: Value, - all_file_systems: bool, - skip_lost_and_found: bool, - dry_run: bool, - skip_e2big_xattr: bool, _info: &ApiMethod, _rpcenv: &mut dyn RpcEnvironment, ) -> Result { @@ -737,14 +739,14 @@ async fn create_backup( ); } - let mut devices = if all_file_systems { + let mut devices = if param["all-file-systems"].as_bool().unwrap_or(false) { None } else { Some(HashSet::new()) }; if let Some(include_dev) = include_dev { - if all_file_systems { + if param["all-file-systems"].as_bool().unwrap_or(false) { bail!("option 'all-file-systems' conflicts with option 'include-dev'"); } @@ -940,12 +942,16 @@ async fn create_backup( let mut catalog_result_rx = None; let log_file = |desc: &str, file: &str, target: &str| { - let what = if dry_run { "Would upload" } else { "Upload" }; + let what = if param["dry-run"].as_bool().unwrap_or(false) { + "Would upload" + } else { + "Upload" + }; log::info!("{} {} '{}' to '{}' as {}", what, desc, file, repo, target); }; for (backup_type, filename, target, size) in upload_list { - match (backup_type, dry_run) { + match (backup_type, param["dry-run"].as_bool().unwrap_or(false)) { // dry-run (BackupSpecificationType::CONFIG, true) => log_file("config file", &filename, &target), (BackupSpecificationType::LOGFILE, true) => log_file("log file", &filename, &target), @@ -995,6 +1001,8 @@ async fn create_backup( .unwrap() .start_directory(std::ffi::CString::new(target.as_str())?.as_c_str())?; + let skip_lost_and_found = param["skip-lost-and-found"].as_bool().unwrap_or(false); + let skip_e2big_xattr = param["skip-e2big-xattr"].as_bool().unwrap_or(false); let pxar_options = pbs_client::pxar::PxarCreateOptions { device_set: devices.clone(), patterns: pattern_list.clone(), @@ -1018,6 +1026,7 @@ async fn create_backup( catalog.clone(), pxar_options, upload_options, + param.to_string(), ) .await?; manifest.add_file(target, stats.size, stats.csum, crypto.mode)?; @@ -1041,7 +1050,7 @@ async fn create_backup( } } - if dry_run { + if param["dry-run"].as_bool().unwrap_or(false) { log::info!("dry-run: no upload happened"); return Ok(Value::Null); } diff --git a/proxmox-restore-daemon/src/proxmox_restore_daemon/api.rs b/proxmox-restore-daemon/src/proxmox_restore_daemon/api.rs index c2055222..d1f141af 100644 --- a/proxmox-restore-daemon/src/proxmox_restore_daemon/api.rs +++ b/proxmox-restore-daemon/src/proxmox_restore_daemon/api.rs @@ -356,7 +356,7 @@ fn extract( }; let pxar_writer = TokioWriter::new(writer); - create_archive(dir, pxar_writer, Flags::DEFAULT, |_| Ok(()), None, options) + create_archive(dir, pxar_writer, Flags::DEFAULT, |_| Ok(()), None, options, "".to_string()) .await } .await; diff --git a/pxar-bin/src/main.rs b/pxar-bin/src/main.rs index 2bbe90e3..277d0b46 100644 --- a/pxar-bin/src/main.rs +++ b/pxar-bin/src/main.rs @@ -384,6 +384,7 @@ async fn create_archive( }, None, options, + "".to_string(), ) .await?; diff --git a/tests/catar.rs b/tests/catar.rs index 36bb4f3b..22a23925 100644 --- a/tests/catar.rs +++ b/tests/catar.rs @@ -40,6 +40,7 @@ fn run_test(dir_name: &str) -> Result<(), Error> { |_| Ok(()), None, options, + "".to_string(), ))?; Command::new("cmp") -- 2.43.0