2 Commits

Author SHA1 Message Date
james 05abd729a8 chore: Release zfsbackup version 0.5.0
Release / release (push) Successful in 1m44s
2026-06-03 10:50:33 +02:00
james 3251a97e1a Add curt progressor and progressor selection 2026-06-03 10:50:13 +02:00
5 changed files with 108 additions and 7 deletions
Generated
+1 -1
View File
@@ -435,7 +435,7 @@ dependencies = [
[[package]] [[package]]
name = "zfsbackup" name = "zfsbackup"
version = "0.4.2" version = "0.5.0"
dependencies = [ dependencies = [
"chrono", "chrono",
"clap", "clap",
+1 -1
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "zfsbackup" name = "zfsbackup"
version = "0.4.2" version = "0.5.0"
edition = "2024" edition = "2024"
publish = false publish = false
+21 -5
View File
@@ -5,7 +5,7 @@ use std::io::IsTerminal;
use std::sync::mpsc::channel; use std::sync::mpsc::channel;
use std::thread; use std::thread;
use zfsbackup::job::JobBuilder; use zfsbackup::job::JobBuilder;
use zfsbackup::progress::{Progressor, log, terminal}; use zfsbackup::progress::{Progressor, curt, log, terminal};
#[derive(Parser)] #[derive(Parser)]
#[command(version, about, long_about = None)] #[command(version, about, long_about = None)]
@@ -29,6 +29,9 @@ struct Args {
#[arg(short, long)] #[arg(short, long)]
retain: Option<usize>, retain: Option<usize>,
#[arg(short, long)]
progressor: Option<String>,
datasets: Vec<String>, datasets: Vec<String>,
} }
@@ -49,10 +52,23 @@ fn main() -> Result<(), Box<dyn Error>> {
} }
let (tx, rx) = channel(); 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 {
Box::new(terminal::Progressor::new(rx)) Some(name) => match name.as_str() {
} else { "curt" => Box::new(curt::Progressor::new(rx)),
Box::new(log::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()); let handle = thread::spawn(move || pr.run());
builder = builder.sender(tx); builder = builder.sender(tx);
+84
View File
@@ -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
View File
@@ -1,3 +1,4 @@
pub mod curt;
pub mod filter; pub mod filter;
pub mod log; pub mod log;
mod rate; mod rate;