sync: Show time elapsed per send
This commit is contained in:
@ -1,10 +1,12 @@
|
|||||||
use crate::local;
|
use crate::local;
|
||||||
use crate::planner::{self, TransferKind};
|
use crate::planner::{self, TransferKind};
|
||||||
use crate::remote;
|
use crate::remote;
|
||||||
|
use crate::util::format_duration;
|
||||||
use crate::Opt;
|
use crate::Opt;
|
||||||
use ssh2::Session;
|
use ssh2::Session;
|
||||||
use std::io::{self, Read};
|
use std::io::{self, Read};
|
||||||
use std::process::{Command, Stdio};
|
use std::process::{Command, Stdio};
|
||||||
|
use std::time::Instant;
|
||||||
|
|
||||||
pub fn run(opt: &Opt, sync_all: bool) -> anyhow::Result<()> {
|
pub fn run(opt: &Opt, sync_all: bool) -> anyhow::Result<()> {
|
||||||
// TODO: currently we only sync the latest local files
|
// TODO: currently we only sync the latest local files
|
||||||
@ -50,7 +52,11 @@ fn send_snapshot(
|
|||||||
snapshot: &str,
|
snapshot: &str,
|
||||||
parent: Option<&str>,
|
parent: Option<&str>,
|
||||||
) -> anyhow::Result<()> {
|
) -> 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
|
// spawn btrfs send
|
||||||
let mut send = Command::new("btrfs")
|
let mut send = Command::new("btrfs")
|
||||||
@ -79,8 +85,8 @@ fn send_snapshot(
|
|||||||
receive.exec(&format!(r#"btrfs receive "{}""#, remote_path,))?;
|
receive.exec(&format!(r#"btrfs receive "{}""#, remote_path,))?;
|
||||||
|
|
||||||
// pipe send to receive
|
// pipe send to receive
|
||||||
|
let start_time = Instant::now();
|
||||||
let num_bytes = io::copy(&mut send_stdout, &mut receive)?;
|
let num_bytes = io::copy(&mut send_stdout, &mut receive)?;
|
||||||
info!("[{}] sent {} bytes", snapshot, num_bytes);
|
|
||||||
|
|
||||||
// wait for send to complete
|
// wait for send to complete
|
||||||
let local_out = send.wait_with_output()?;
|
let local_out = send.wait_with_output()?;
|
||||||
@ -100,5 +106,13 @@ fn send_snapshot(
|
|||||||
anyhow::bail!("btrfs receive failed\nstderr:\n{}", remote_err);
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,6 +6,7 @@ mod local;
|
|||||||
mod planner;
|
mod planner;
|
||||||
mod remote;
|
mod remote;
|
||||||
mod snapshot;
|
mod snapshot;
|
||||||
|
mod util;
|
||||||
|
|
||||||
use actions::{list, show_plan, sync};
|
use actions::{list, show_plan, sync};
|
||||||
use chrono::{DateTime, FixedOffset};
|
use chrono::{DateTime, FixedOffset};
|
||||||
|
|||||||
14
src/util.rs
Normal file
14
src/util.rs
Normal file
@ -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),
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user