Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 05abd729a8 | |||
| 3251a97e1a | |||
| 0e52fd8fde | |||
| 201a46c322 |
Generated
+1
-1
@@ -435,7 +435,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zfsbackup"
|
name = "zfsbackup"
|
||||||
version = "0.4.1"
|
version = "0.5.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"clap",
|
"clap",
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "zfsbackup"
|
name = "zfsbackup"
|
||||||
version = "0.4.1"
|
version = "0.5.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
|
|||||||
+7
-7
@@ -58,7 +58,7 @@ impl Job {
|
|||||||
let mut cmd = self.get_side_command(side);
|
let mut cmd = self.get_side_command(side);
|
||||||
cmd.extend(["snapshot", &name]);
|
cmd.extend(["snapshot", &name]);
|
||||||
command::exec(&cmd)?;
|
command::exec(&cmd)?;
|
||||||
self.send_event(BackupEvent::SnapshotCreated(name.clone()));
|
self.send_event(BackupEvent::SnapshotCreate(name.clone()));
|
||||||
Ok(snapshot)
|
Ok(snapshot)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,7 +108,7 @@ impl Job {
|
|||||||
None => vec![],
|
None => vec![],
|
||||||
};
|
};
|
||||||
command::exec_pipe(&send_cmd, &receive_cmd, filters)?;
|
command::exec_pipe(&send_cmd, &receive_cmd, filters)?;
|
||||||
self.send_event(BackupEvent::DatasetCompleted(source.to_string()));
|
self.send_event(BackupEvent::DatasetComplete(source.to_string()));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -196,7 +196,7 @@ impl Job {
|
|||||||
let name = snapshot.to_string();
|
let name = snapshot.to_string();
|
||||||
cmd.extend(["destroy", &name]);
|
cmd.extend(["destroy", &name]);
|
||||||
command::exec(&cmd)?;
|
command::exec(&cmd)?;
|
||||||
self.send_event(BackupEvent::SnapshotDeleted(name.clone()));
|
self.send_event(BackupEvent::SnapshotDelete(name.clone()));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -217,7 +217,7 @@ impl Job {
|
|||||||
|
|
||||||
// Run backup
|
// Run backup
|
||||||
if dest_exists {
|
if dest_exists {
|
||||||
self.send_event(BackupEvent::StartingIncrementalBackup {
|
self.send_event(BackupEvent::IncrementalBackupStart {
|
||||||
source: source.clone(),
|
source: source.clone(),
|
||||||
dest: dest.clone(),
|
dest: dest.clone(),
|
||||||
index: index + 1,
|
index: index + 1,
|
||||||
@@ -234,13 +234,13 @@ impl Job {
|
|||||||
.estimate(&snapshot.to_string(), Some(&inc_snapshot))
|
.estimate(&snapshot.to_string(), Some(&inc_snapshot))
|
||||||
.ok();
|
.ok();
|
||||||
if !execute {
|
if !execute {
|
||||||
self.send_event(BackupEvent::DryrunCompleted(source.clone()));
|
self.send_event(BackupEvent::DryrunComplete(source.clone()));
|
||||||
self.delete_snapshot(snapshot)?;
|
self.delete_snapshot(snapshot)?;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
self.send_receive(&snapshot.to_string(), &dest, Some(&inc_snapshot), total)?;
|
self.send_receive(&snapshot.to_string(), &dest, Some(&inc_snapshot), total)?;
|
||||||
} else {
|
} else {
|
||||||
self.send_event(BackupEvent::StartingFullBackup {
|
self.send_event(BackupEvent::FullBackupStart {
|
||||||
source: source.clone(),
|
source: source.clone(),
|
||||||
dest: dest.clone(),
|
dest: dest.clone(),
|
||||||
index: index + 1,
|
index: index + 1,
|
||||||
@@ -249,7 +249,7 @@ impl Job {
|
|||||||
let snapshot = self.create_snapshot(source, JobSide::Source)?;
|
let snapshot = self.create_snapshot(source, JobSide::Source)?;
|
||||||
let total = self.estimate(&snapshot.to_string(), None).ok();
|
let total = self.estimate(&snapshot.to_string(), None).ok();
|
||||||
if !execute {
|
if !execute {
|
||||||
self.send_event(BackupEvent::DryrunCompleted(source.clone()));
|
self.send_event(BackupEvent::DryrunComplete(source.clone()));
|
||||||
self.delete_snapshot(snapshot)?;
|
self.delete_snapshot(snapshot)?;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
+18
-2
@@ -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 {
|
||||||
|
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))
|
Box::new(terminal::Progressor::new(rx))
|
||||||
} else {
|
} else {
|
||||||
Box::new(log::Progressor::new(rx))
|
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);
|
||||||
|
|||||||
@@ -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(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -31,9 +31,7 @@ impl<R: Read> Read for ByteCountReader<R> {
|
|||||||
|
|
||||||
impl<R: Read> Drop for ByteCountReader<R> {
|
impl<R: Read> Drop for ByteCountReader<R> {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
self.sender
|
self.sender.send(BackupEvent::SendComplete(self.bytes)).ok();
|
||||||
.send(BackupEvent::SendCompleted(self.bytes))
|
|
||||||
.ok();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+7
-7
@@ -14,7 +14,7 @@ impl super::Progressor for Progressor {
|
|||||||
println!("Estimated total backup size: {} bytes", size);
|
println!("Estimated total backup size: {} bytes", size);
|
||||||
self.estimated_size = size;
|
self.estimated_size = size;
|
||||||
}
|
}
|
||||||
BackupEvent::StartingFullBackup {
|
BackupEvent::FullBackupStart {
|
||||||
source,
|
source,
|
||||||
dest,
|
dest,
|
||||||
index,
|
index,
|
||||||
@@ -25,7 +25,7 @@ impl super::Progressor for Progressor {
|
|||||||
source, dest, index, total
|
source, dest, index, total
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
BackupEvent::StartingIncrementalBackup {
|
BackupEvent::IncrementalBackupStart {
|
||||||
source,
|
source,
|
||||||
dest,
|
dest,
|
||||||
index,
|
index,
|
||||||
@@ -36,21 +36,21 @@ impl super::Progressor for Progressor {
|
|||||||
source, dest, index, total
|
source, dest, index, total
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
BackupEvent::SnapshotCreated(name) => {
|
BackupEvent::SnapshotCreate(name) => {
|
||||||
println!("Created snapshot: {}", name);
|
println!("Created snapshot: {}", name);
|
||||||
}
|
}
|
||||||
BackupEvent::SnapshotDeleted(name) => {
|
BackupEvent::SnapshotDelete(name) => {
|
||||||
println!("Deleted snapshot: {}", name);
|
println!("Deleted snapshot: {}", name);
|
||||||
}
|
}
|
||||||
BackupEvent::BytesTransferred { .. } => {}
|
BackupEvent::BytesTransferred { .. } => {}
|
||||||
BackupEvent::SendCompleted(bytes) => {
|
BackupEvent::SendComplete(bytes) => {
|
||||||
println!("Send completed: {} bytes", bytes);
|
println!("Send completed: {} bytes", bytes);
|
||||||
}
|
}
|
||||||
BackupEvent::DatasetCompleted(name) => {
|
BackupEvent::DatasetComplete(name) => {
|
||||||
println!("Completed backup of dataset: {}", name);
|
println!("Completed backup of dataset: {}", name);
|
||||||
self.estimated_size = 0;
|
self.estimated_size = 0;
|
||||||
}
|
}
|
||||||
BackupEvent::DryrunCompleted(name) => {
|
BackupEvent::DryrunComplete(name) => {
|
||||||
println!("Completed dry run backup of dataset: {}", name);
|
println!("Completed dry run backup of dataset: {}", name);
|
||||||
self.estimated_size = 0;
|
self.estimated_size = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-7
@@ -1,3 +1,4 @@
|
|||||||
|
pub mod curt;
|
||||||
pub mod filter;
|
pub mod filter;
|
||||||
pub mod log;
|
pub mod log;
|
||||||
mod rate;
|
mod rate;
|
||||||
@@ -29,25 +30,25 @@ fn format_eta(seconds: f64) -> String {
|
|||||||
|
|
||||||
pub enum BackupEvent {
|
pub enum BackupEvent {
|
||||||
Estimate(u64),
|
Estimate(u64),
|
||||||
StartingFullBackup {
|
FullBackupStart {
|
||||||
source: String,
|
source: String,
|
||||||
dest: String,
|
dest: String,
|
||||||
index: usize,
|
index: usize,
|
||||||
total: usize,
|
total: usize,
|
||||||
},
|
},
|
||||||
StartingIncrementalBackup {
|
IncrementalBackupStart {
|
||||||
source: String,
|
source: String,
|
||||||
dest: String,
|
dest: String,
|
||||||
index: usize,
|
index: usize,
|
||||||
total: usize,
|
total: usize,
|
||||||
},
|
},
|
||||||
SnapshotCreated(String),
|
SnapshotCreate(String),
|
||||||
SnapshotDeleted(String),
|
SnapshotDelete(String),
|
||||||
BytesTransferred {
|
BytesTransferred {
|
||||||
bytes: u64,
|
bytes: u64,
|
||||||
estimated_total: Option<u64>,
|
estimated_total: Option<u64>,
|
||||||
},
|
},
|
||||||
SendCompleted(u64),
|
SendComplete(u64),
|
||||||
DatasetCompleted(String),
|
DatasetComplete(String),
|
||||||
DryrunCompleted(String),
|
DryrunComplete(String),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ impl super::Progressor for Progressor {
|
|||||||
println!("Estimated total backup size: {}", human_bytes(size as f64));
|
println!("Estimated total backup size: {}", human_bytes(size as f64));
|
||||||
self.estimated_size = size;
|
self.estimated_size = size;
|
||||||
}
|
}
|
||||||
BackupEvent::StartingFullBackup {
|
BackupEvent::FullBackupStart {
|
||||||
source,
|
source,
|
||||||
dest,
|
dest,
|
||||||
index,
|
index,
|
||||||
@@ -29,7 +29,7 @@ impl super::Progressor for Progressor {
|
|||||||
source, dest, index, total
|
source, dest, index, total
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
BackupEvent::StartingIncrementalBackup {
|
BackupEvent::IncrementalBackupStart {
|
||||||
source,
|
source,
|
||||||
dest,
|
dest,
|
||||||
index,
|
index,
|
||||||
@@ -40,10 +40,10 @@ impl super::Progressor for Progressor {
|
|||||||
source, dest, index, total
|
source, dest, index, total
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
BackupEvent::SnapshotCreated(name) => {
|
BackupEvent::SnapshotCreate(name) => {
|
||||||
println!("Created snapshot: {}", name);
|
println!("Created snapshot: {}", name);
|
||||||
}
|
}
|
||||||
BackupEvent::SnapshotDeleted(name) => {
|
BackupEvent::SnapshotDelete(name) => {
|
||||||
println!("Deleted snapshot: {}", name);
|
println!("Deleted snapshot: {}", name);
|
||||||
}
|
}
|
||||||
BackupEvent::BytesTransferred {
|
BackupEvent::BytesTransferred {
|
||||||
@@ -89,16 +89,16 @@ impl super::Progressor for Progressor {
|
|||||||
}
|
}
|
||||||
std::io::stdout().flush().ok();
|
std::io::stdout().flush().ok();
|
||||||
}
|
}
|
||||||
BackupEvent::SendCompleted(bytes) => {
|
BackupEvent::SendComplete(bytes) => {
|
||||||
println!(
|
println!(
|
||||||
"\x1b[2KSend completed at {}, awaiting receive completion",
|
"\x1b[2KSend completed at {}, awaiting receive completion",
|
||||||
human_bytes(bytes as f64)
|
human_bytes(bytes as f64)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
BackupEvent::DatasetCompleted(name) => {
|
BackupEvent::DatasetComplete(name) => {
|
||||||
println!("\x1b[2KCompleted backup of dataset: {}", name);
|
println!("\x1b[2KCompleted backup of dataset: {}", name);
|
||||||
}
|
}
|
||||||
BackupEvent::DryrunCompleted(name) => {
|
BackupEvent::DryrunComplete(name) => {
|
||||||
println!("\x1b[2KCompleted dry run backup of dataset: {}", name);
|
println!("\x1b[2KCompleted dry run backup of dataset: {}", name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user