diff --git a/src/actions/sync.rs b/src/actions/sync.rs index aae03b2..55af3e9 100644 --- a/src/actions/sync.rs +++ b/src/actions/sync.rs @@ -1,10 +1,12 @@ use crate::local; use crate::planner::{self, TransferKind}; use crate::remote; +use crate::util::format_duration; use crate::Opt; use ssh2::Session; use std::io::{self, Read}; use std::process::{Command, Stdio}; +use std::time::Instant; pub fn run(opt: &Opt, sync_all: bool) -> anyhow::Result<()> { // TODO: currently we only sync the latest local files @@ -50,7 +52,11 @@ fn send_snapshot( snapshot: &str, parent: Option<&str>, ) -> anyhow::Result<()> { - info!("[{}] transmitting delta", snapshot); + if parent.is_none() { + info!("[{}] sending full snapshot data", snapshot); + } else { + info!("[{}] sending snapshot delta", snapshot); + } // spawn btrfs send let mut send = Command::new("btrfs") @@ -79,8 +85,8 @@ fn send_snapshot( receive.exec(&format!(r#"btrfs receive "{}""#, remote_path,))?; // pipe send to receive + let start_time = Instant::now(); let num_bytes = io::copy(&mut send_stdout, &mut receive)?; - info!("[{}] sent {} bytes", snapshot, num_bytes); // wait for send to complete let local_out = send.wait_with_output()?; @@ -100,5 +106,13 @@ fn send_snapshot( anyhow::bail!("btrfs receive failed\nstderr:\n{}", remote_err); } + let time_elapsed = start_time.elapsed(); + info!( + "[{}] sent {} bytes in {}", + snapshot, + num_bytes, + format_duration(time_elapsed) + ); + Ok(()) } diff --git a/src/main.rs b/src/main.rs index c144613..eef9192 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,6 +6,7 @@ mod local; mod planner; mod remote; mod snapshot; +mod util; use actions::{list, show_plan, sync}; use chrono::{DateTime, FixedOffset}; diff --git a/src/util.rs b/src/util.rs new file mode 100644 index 0000000..8107138 --- /dev/null +++ b/src/util.rs @@ -0,0 +1,14 @@ +use std::time::Duration; + +pub fn format_duration(d: Duration) -> String { + let seconds = d.as_secs_f32() % 60.0; + let minutes = d.as_secs() / 60 % 60; + let hours = d.as_secs() / 60 / 60; + + match (hours, minutes) { + (0, 0) => format!("{:.2}s", seconds), + (0, _) => format!("{}m {:.2}s", minutes, seconds), + (_, 0) => format!("{}h {:.2}s", hours, seconds), + (_, _) => format!("{}h {}m {:.2}s", hours, minutes, seconds), + } +}