Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 05abd729a8 | |||
| 3251a97e1a |
Generated
+1
-1
@@ -435,7 +435,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "zfsbackup"
|
||||
version = "0.4.2"
|
||||
version = "0.5.0"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"clap",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "zfsbackup"
|
||||
version = "0.4.2"
|
||||
version = "0.5.0"
|
||||
edition = "2024"
|
||||
publish = false
|
||||
|
||||
|
||||
+18
-2
@@ -5,7 +5,7 @@ use std::io::IsTerminal;
|
||||
use std::sync::mpsc::channel;
|
||||
use std::thread;
|
||||
use zfsbackup::job::JobBuilder;
|
||||
use zfsbackup::progress::{Progressor, log, terminal};
|
||||
use zfsbackup::progress::{Progressor, curt, log, terminal};
|
||||
|
||||
#[derive(Parser)]
|
||||
#[command(version, about, long_about = None)]
|
||||
@@ -29,6 +29,9 @@ struct Args {
|
||||
#[arg(short, long)]
|
||||
retain: Option<usize>,
|
||||
|
||||
#[arg(short, long)]
|
||||
progressor: Option<String>,
|
||||
|
||||
datasets: Vec<String>,
|
||||
}
|
||||
|
||||
@@ -49,10 +52,23 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
}
|
||||
|
||||
let (tx, rx) = channel();
|
||||
let mut pr: Box<dyn Progressor> = if std::io::stdout().is_terminal() {
|
||||
let mut pr: Box<dyn Progressor> = match args.progressor {
|
||||
Some(name) => match name.as_str() {
|
||||
"curt" => Box::new(curt::Progressor::new(rx)),
|
||||
"terminal" => Box::new(terminal::Progressor::new(rx)),
|
||||
"log" => Box::new(log::Progressor::new(rx)),
|
||||
_ => {
|
||||
eprintln!("progressor {} not found, defaulting to 'log'", name);
|
||||
Box::new(log::Progressor::new(rx))
|
||||
}
|
||||
},
|
||||
None => {
|
||||
if std::io::stdout().is_terminal() {
|
||||
Box::new(terminal::Progressor::new(rx))
|
||||
} else {
|
||||
Box::new(log::Progressor::new(rx))
|
||||
}
|
||||
}
|
||||
};
|
||||
let handle = thread::spawn(move || pr.run());
|
||||
builder = builder.sender(tx);
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
use super::{BackupEvent, human_bytes};
|
||||
use std::io::Write;
|
||||
use std::sync::mpsc::Receiver;
|
||||
|
||||
pub struct Progressor {
|
||||
receiver: Receiver<BackupEvent>,
|
||||
source: String,
|
||||
}
|
||||
|
||||
impl super::Progressor for Progressor {
|
||||
fn run(&mut self) {
|
||||
while let Ok(event) = self.receiver.recv() {
|
||||
match event {
|
||||
BackupEvent::Estimate(_) => {}
|
||||
BackupEvent::FullBackupStart {
|
||||
source,
|
||||
dest: _,
|
||||
index: _,
|
||||
total: _,
|
||||
} => {
|
||||
self.source = source;
|
||||
print!("{}\r", self.source);
|
||||
}
|
||||
BackupEvent::IncrementalBackupStart {
|
||||
source,
|
||||
dest: _,
|
||||
index: _,
|
||||
total: _,
|
||||
} => {
|
||||
self.source = source;
|
||||
print!("{}\r", self.source);
|
||||
}
|
||||
BackupEvent::SnapshotCreate(_) => {}
|
||||
BackupEvent::SnapshotDelete(_) => {}
|
||||
BackupEvent::BytesTransferred {
|
||||
bytes,
|
||||
estimated_total,
|
||||
} => {
|
||||
match estimated_total {
|
||||
Some(total) => {
|
||||
let percent: f64 = if total > 0 {
|
||||
bytes as f64 / total as f64
|
||||
} else {
|
||||
0.0
|
||||
};
|
||||
|
||||
print!("\x1b[2K{}: {:>3.0}%\r", self.source, percent * 100.0,);
|
||||
}
|
||||
None => {
|
||||
print!(
|
||||
"\x1b[2K{}: {} transferred\r",
|
||||
self.source,
|
||||
human_bytes(bytes as f64)
|
||||
);
|
||||
}
|
||||
}
|
||||
std::io::stdout().flush().ok();
|
||||
}
|
||||
BackupEvent::SendComplete(bytes) => {
|
||||
print!(
|
||||
"\x1b[2K{}: send complete ({})\r",
|
||||
self.source,
|
||||
human_bytes(bytes as f64)
|
||||
);
|
||||
}
|
||||
BackupEvent::DatasetComplete(_) => {
|
||||
println!("\x1b[2K{}: complete", self.source);
|
||||
}
|
||||
BackupEvent::DryrunComplete(_) => {
|
||||
println!("\x1b[2K{}: complete", self.source);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Progressor {
|
||||
pub fn new(receiver: Receiver<BackupEvent>) -> Self {
|
||||
Self {
|
||||
receiver,
|
||||
source: String::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
pub mod curt;
|
||||
pub mod filter;
|
||||
pub mod log;
|
||||
mod rate;
|
||||
|
||||
Reference in New Issue
Block a user