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) server-digest SHA256) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 16ACD62A18 for ; Tue, 22 Feb 2022 13:27:45 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 069A524188 for ; Tue, 22 Feb 2022 13:27:45 +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 id 2BD7F2417F for ; Tue, 22 Feb 2022 13:27:44 +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 F3B4644966 for ; Tue, 22 Feb 2022 13:27:43 +0100 (CET) From: Hannes Laimer To: pbs-devel@lists.proxmox.com Date: Tue, 22 Feb 2022 12:27:29 +0000 Message-Id: <20220222122729.46421-1-h.laimer@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.008 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 PROLO_LEO1 0.1 Meta Catches all Leo drug variations so far 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 - URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [benchmark.rs, main.rs] Subject: [pbs-devel] [PATCH proxmox-backup v1 1/1] close #3770: pbs-client: add quiet backup flag 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: Tue, 22 Feb 2022 12:27:45 -0000 Signed-off-by: Hannes Laimer --- this feels 'chunky', having quiet and verbose(which is sometimes called debug). Maybe some kind general verbosity enum might make sense, but then it should not just be used here. pbs-client/src/backup_writer.rs | 12 +++-- proxmox-backup-client/src/benchmark.rs | 1 + proxmox-backup-client/src/main.rs | 62 ++++++++++++++++---------- 3 files changed, 47 insertions(+), 28 deletions(-) diff --git a/pbs-client/src/backup_writer.rs b/pbs-client/src/backup_writer.rs index b02798bd..1f53f52b 100644 --- a/pbs-client/src/backup_writer.rs +++ b/pbs-client/src/backup_writer.rs @@ -29,6 +29,7 @@ pub struct BackupWriter { h2: H2Client, abort: AbortHandle, verbose: bool, + quiet: bool, crypt_config: Option>, } @@ -71,12 +72,14 @@ impl BackupWriter { abort: AbortHandle, crypt_config: Option>, verbose: bool, + quiet: bool, ) -> Arc { Arc::new(Self { h2, abort, crypt_config, verbose, + quiet, }) } @@ -90,6 +93,7 @@ impl BackupWriter { backup_id: &str, backup_time: i64, debug: bool, + quiet: bool, benchmark: bool, ) -> Result, Error> { let param = json!({ @@ -114,7 +118,7 @@ impl BackupWriter { .start_h2_connection(req, String::from(PROXMOX_BACKUP_PROTOCOL_ID_V1!())) .await?; - Ok(BackupWriter::new(h2, abort, crypt_config, debug)) + Ok(BackupWriter::new(h2, abort, crypt_config, debug, quiet)) } pub async fn get(&self, path: &str, param: Option) -> Result { @@ -340,7 +344,7 @@ impl BackupWriter { } else { pbs_tools::format::strip_server_file_extension(archive_name) }; - if archive_name != CATALOG_NAME { + if !self.quiet && archive_name != CATALOG_NAME { let speed: HumanByte = ((size_dirty * 1_000_000) / (upload_stats.duration.as_micros() as usize)).into(); let size_dirty: HumanByte = size_dirty.into(); @@ -354,11 +358,11 @@ impl BackupWriter { upload_stats.duration.as_secs_f64() ); println!("{}: average backup speed: {}/s", archive, speed); - } else { + } else if !self.quiet { println!("Uploaded backup catalog ({})", size); } - if upload_stats.size_reused > 0 && upload_stats.size > 1024 * 1024 { + if !self.quiet && upload_stats.size_reused > 0 && upload_stats.size > 1024 * 1024 { let reused_percent = upload_stats.size_reused as f64 * 100. / upload_stats.size as f64; let reused: HumanByte = upload_stats.size_reused.into(); println!( diff --git a/proxmox-backup-client/src/benchmark.rs b/proxmox-backup-client/src/benchmark.rs index 6a97b117..fdc4d989 100644 --- a/proxmox-backup-client/src/benchmark.rs +++ b/proxmox-backup-client/src/benchmark.rs @@ -235,6 +235,7 @@ async fn test_upload_speed( "benchmark", backup_time, false, + false, true ).await?; diff --git a/proxmox-backup-client/src/main.rs b/proxmox-backup-client/src/main.rs index 7c022fad..94987ad1 100644 --- a/proxmox-backup-client/src/main.rs +++ b/proxmox-backup-client/src/main.rs @@ -611,6 +611,12 @@ fn spawn_catalog_upload( optional: true, default: false, }, + "quiet": { + type: Boolean, + description: "Quiet output.", + optional: true, + default: false, + }, "dry-run": { type: Boolean, description: "Just show what backup would do, but do not upload anything.", @@ -627,6 +633,7 @@ async fn create_backup( skip_lost_and_found: bool, dry_run: bool, verbose: bool, + quiet: bool, _info: &ApiMethod, _rpcenv: &mut dyn RpcEnvironment, ) -> Result { @@ -781,21 +788,21 @@ async fn create_backup( let client = connect_rate_limited(&repo, rate_limit)?; record_repository(&repo); - println!( - "Starting backup: {}/{}/{}", - backup_type, - backup_id, - BackupDir::backup_time_to_string(backup_time)? - ); - - println!("Client name: {}", proxmox_sys::nodename()); - let start_time = std::time::Instant::now(); - println!( - "Starting backup protocol: {}", - strftime_local("%c", epoch_i64())? - ); + if !quiet { + println!( + "Starting backup: {}/{}/{}", + backup_type, + backup_id, + BackupDir::backup_time_to_string(backup_time)? + ); + println!("Client name: {}", proxmox_sys::nodename()); + println!( + "Starting backup protocol: {}", + strftime_local("%c", epoch_i64())? + ); + } let (crypt_config, rsa_encrypted_key) = match crypto.enc_key { None => (None, None), @@ -837,20 +844,25 @@ async fn create_backup( backup_id, backup_time, verbose, + quiet, false, ) .await?; let download_previous_manifest = match client.previous_backup_time().await { Ok(Some(backup_time)) => { - println!( - "Downloading previous manifest ({})", - strftime_local("%c", backup_time)? - ); + if !quiet { + println!( + "Downloading previous manifest ({})", + strftime_local("%c", backup_time)? + ); + } true } Ok(None) => { - println!("No previous manifest available."); + if !quiet { + println!("No previous manifest available."); + } false } Err(_) => { @@ -887,7 +899,9 @@ async fn create_backup( let log_file = |desc: &str, file: &str, target: &str| { let what = if dry_run { "Would upload" } else { "Upload" }; - println!("{} {} '{}' to '{}' as {}", what, desc, file, repo, target); + if !quiet { + println!("{} {} '{}' to '{}' as {}", what, desc, file, repo, target); + } }; for (backup_type, filename, target, size) in upload_list { @@ -1010,7 +1024,7 @@ async fn create_backup( if let Some(rsa_encrypted_key) = rsa_encrypted_key { let target = ENCRYPTED_KEY_BLOB_NAME; - println!("Upload RSA encoded key to '{:?}' as {}", repo, target); + if !quiet { println!("Upload RSA encoded key to '{:?}' as {}", repo, target); } let options = UploadOptions { compress: false, encrypt: false, @@ -1043,10 +1057,10 @@ async fn create_backup( let end_time = std::time::Instant::now(); let elapsed = end_time.duration_since(start_time); - println!("Duration: {:.2}s", elapsed.as_secs_f64()); - - println!("End Time: {}", strftime_local("%c", epoch_i64())?); - + if !quiet { + println!("Duration: {:.2}s", elapsed.as_secs_f64()); + println!("End Time: {}", strftime_local("%c", epoch_i64())?); + } Ok(Value::Null) } -- 2.30.2