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 1EF24611F8 for ; Fri, 18 Feb 2022 11:13:00 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 14ADE2889B for ; Fri, 18 Feb 2022 11:13:00 +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) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id A03B72888B for ; Fri, 18 Feb 2022 11:12:58 +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 7A476461BD for ; Fri, 18 Feb 2022 11:12:58 +0100 (CET) Message-ID: <9a8310b6-ac1a-ffa9-abdc-fd0c762e59a4@proxmox.com> Date: Fri, 18 Feb 2022 11:12:57 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.6.0 Content-Language: en-US To: pbs-devel@lists.proxmox.com References: <20220218095538.2868974-1-m.frank@proxmox.com> From: Markus Frank In-Reply-To: <20220218095538.2868974-1-m.frank@proxmox.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.002 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment NICE_REPLY_A -0.001 Looks like a legit reply (A) 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: Re: [pbs-devel] [PATCH v2 proxmox-backup] fix #3323: dry-run for cli backup subcommand 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: Fri, 18 Feb 2022 10:13:00 -0000 I gave git two Froms. Should I make a new patch? If not and the code is okay, please delete the first line, thanks. On 2/18/22 10:55, markus frank wrote: > From: Markus Frank > > adds a dry-run parameter for "proxmox-backup-client backup". > With this parameter on it simply prints out what would be uploaded, > instead of uploading it. > > Signed-off-by: Markus Frank > --- > version 2: > * tuple matching > * print closure > > proxmox-backup-client/src/main.rs | 50 +++++++++++++++++++++++++------ > 1 file changed, 41 insertions(+), 9 deletions(-) > > diff --git a/proxmox-backup-client/src/main.rs b/proxmox-backup-client/src/main.rs > index 081028f2..437c1400 100644 > --- a/proxmox-backup-client/src/main.rs > +++ b/proxmox-backup-client/src/main.rs > @@ -613,6 +613,11 @@ fn spawn_catalog_upload( > description: "Verbose output.", > optional: true, > }, > + "dry-run": { > + type: Boolean, > + description: "Just show what backup would do, but do not upload anything.", > + optional: true, > + }, > } > } > )] > @@ -633,6 +638,8 @@ async fn create_backup( > > let verbose = param["verbose"].as_bool().unwrap_or(false); > > + let dry_run = param["dry-run"].as_bool().unwrap_or(false); > + > let backup_time_opt = param["backup-time"].as_i64(); > > let chunk_size_opt = param["chunk-size"].as_u64().map(|v| (v*1024) as usize); > @@ -844,35 +851,55 @@ async fn create_backup( > let mut catalog = None; > let mut catalog_result_rx = None; > > + let printfileinfo = |butype:&str, filename:&str, repo:&pbs_client::BackupRepository, target:&str| { > + if dry_run{ > + println!("Would upload {} '{}' to '{}' as {}", butype, filename, repo, target); > + } else { > + println!("Upload {} '{}' to '{}' as {}", butype, filename, repo, target); > + } > + }; > + > for (backup_type, filename, target, size) in upload_list { > - match backup_type { > - BackupSpecificationType::CONFIG => { > + match (backup_type, dry_run) { > + (BackupSpecificationType::CONFIG, true) => { > + printfileinfo("config file", &filename, &repo, &target); > + } > + (BackupSpecificationType::LOGFILE, true) => { > + printfileinfo("log file", &filename, &repo, &target); > + } > + (BackupSpecificationType::PXAR, true) => { > + printfileinfo("directory", &filename, &repo, &target); > + } > + (BackupSpecificationType::IMAGE, true) => { > + printfileinfo("image", &filename, &repo, &target); > + } > + (BackupSpecificationType::CONFIG, false) => { > let upload_options = UploadOptions { > compress: true, > encrypt: crypto.mode == CryptMode::Encrypt, > ..UploadOptions::default() > }; > > - println!("Upload config file '{}' to '{}' as {}", filename, repo, target); > + printfileinfo("config file", &filename, &repo, &target); > let stats = client > .upload_blob_from_file(&filename, &target, upload_options) > .await?; > manifest.add_file(target, stats.size, stats.csum, crypto.mode)?; > } > - BackupSpecificationType::LOGFILE => { // fixme: remove - not needed anymore ? > + (BackupSpecificationType::LOGFILE, false) => { // fixme: remove - not needed anymore ? > let upload_options = UploadOptions { > compress: true, > encrypt: crypto.mode == CryptMode::Encrypt, > ..UploadOptions::default() > }; > > - println!("Upload log file '{}' to '{}' as {}", filename, repo, target); > + printfileinfo("log file", &filename, &repo, &target); > let stats = client > .upload_blob_from_file(&filename, &target, upload_options) > .await?; > manifest.add_file(target, stats.size, stats.csum, crypto.mode)?; > } > - BackupSpecificationType::PXAR => { > + (BackupSpecificationType::PXAR, false) => { > // start catalog upload on first use > if catalog.is_none() { > let catalog_upload_res = spawn_catalog_upload(client.clone(), crypto.mode == CryptMode::Encrypt)?; > @@ -881,7 +908,7 @@ async fn create_backup( > } > let catalog = catalog.as_ref().unwrap(); > > - println!("Upload directory '{}' to '{}' as {}", filename, repo, target); > + printfileinfo("directory", &filename, &repo, &target); > catalog.lock().unwrap().start_directory(std::ffi::CString::new(target.as_str())?.as_c_str())?; > > let pxar_options = pbs_client::pxar::PxarCreateOptions { > @@ -911,8 +938,8 @@ async fn create_backup( > manifest.add_file(target, stats.size, stats.csum, crypto.mode)?; > catalog.lock().unwrap().end_directory()?; > } > - BackupSpecificationType::IMAGE => { > - println!("Upload image '{}' to '{:?}' as {}", filename, repo, target); > + (BackupSpecificationType::IMAGE, false) => { > + printfileinfo("image", &filename, &repo, &target); > > let upload_options = UploadOptions { > previous_manifest: previous_manifest.clone(), > @@ -933,6 +960,11 @@ async fn create_backup( > } > } > > + if dry_run { > + println!("dry-run: no upload happend"); > + return Ok(Value::Null); > + } > + > // finalize and upload catalog > if let Some(catalog) = catalog { > let mutex = Arc::try_unwrap(catalog)