From: Hannes Laimer <h.laimer@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup v1 1/1] close #3770: pbs-client: add quiet backup flag
Date: Tue, 22 Feb 2022 12:27:29 +0000 [thread overview]
Message-ID: <20220222122729.46421-1-h.laimer@proxmox.com> (raw)
Signed-off-by: Hannes Laimer <h.laimer@proxmox.com>
---
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<Arc<CryptConfig>>,
}
@@ -71,12 +72,14 @@ impl BackupWriter {
abort: AbortHandle,
crypt_config: Option<Arc<CryptConfig>>,
verbose: bool,
+ quiet: bool,
) -> Arc<Self> {
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<Arc<BackupWriter>, 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<Value>) -> Result<Value, Error> {
@@ -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<Value, Error> {
@@ -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
next reply other threads:[~2022-02-22 12:27 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-22 12:27 Hannes Laimer [this message]
2022-03-04 9:12 ` Wolfgang Bumiller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220222122729.46421-1-h.laimer@proxmox.com \
--to=h.laimer@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.