diff --git a/src/job.rs b/src/job.rs index d370758..4539f39 100644 --- a/src/job.rs +++ b/src/job.rs @@ -10,7 +10,6 @@ pub struct Job { target: String, source_zfs_command: Vec, target_zfs_command: Vec, - dryrun: bool, retain: usize, sender: Option>, } @@ -33,7 +32,6 @@ impl Job { println!("Target: {}", self.target); println!("Source ZFS Command: {:?}", self.source_zfs_command); println!("Target ZFS Command: {:?}", self.target_zfs_command); - println!("Dryrun: {}", self.dryrun); } fn send_event(&self, event: BackupEvent) { @@ -191,7 +189,7 @@ impl Job { res } - pub fn run(&self) -> Result<(), String> { + pub fn run(&self, execute: bool) -> Result<(), String> { for (index, source) in self.datasets.iter().enumerate() { // Check the source exists let mut cmd = self.get_side_command(JobSide::Source); @@ -222,7 +220,7 @@ impl Job { let snapshot = self.create_snapshot(source, JobSide::Source)?; let total = self.estimate(&snapshot, Some(&inc_snapshot)).ok(); - if self.dryrun { + if !execute { self.send_event(BackupEvent::DryrunCompleted(source.clone())); self.delete_snapshot(Snapshot { snapshot: snapshot.clone(), @@ -240,7 +238,7 @@ impl Job { }); let snapshot = self.create_snapshot(source, JobSide::Source)?; let total = self.estimate(&snapshot, None).ok(); - if self.dryrun { + if !execute { self.send_event(BackupEvent::DryrunCompleted(source.clone())); self.delete_snapshot(Snapshot { snapshot: snapshot.clone(), @@ -266,7 +264,6 @@ pub struct JobBuilder { target: String, source_zfs_command: Vec, target_zfs_command: Vec, - dryrun: bool, retain: usize, sender: Option>, } @@ -324,7 +321,6 @@ impl JobBuilder { target, source_zfs_command: vec!["zfs".to_string()], target_zfs_command: vec!["zfs".to_string()], - dryrun: false, retain: 2, sender: None, } @@ -349,11 +345,6 @@ impl JobBuilder { self } - pub fn dryrun(mut self) -> Self { - self.dryrun = true; - self - } - pub fn retain(mut self, retain: usize) -> Self { self.retain = retain; self @@ -389,13 +380,19 @@ impl JobBuilder { target: self.target, source_zfs_command: self.source_zfs_command, target_zfs_command: self.target_zfs_command, - dryrun: self.dryrun, retain: self.retain, sender: self.sender, }) } } +struct JobConfig { + sources: Vec, + target: String, + source_zfs_command: Option, + target_zfs_command: Option, +} + #[cfg(test)] mod tests { use super::*; diff --git a/src/main.rs b/src/main.rs index 3f3f823..64a3257 100644 --- a/src/main.rs +++ b/src/main.rs @@ -35,9 +35,6 @@ struct Args { fn main() -> Result<(), Box> { let args = Args::parse(); let mut builder = JobBuilder::new(args.datasets, args.target); - if args.dry_run { - builder = builder.dryrun(); - } if let Some(cmd) = args.zfs_command { builder = builder.zfs_command(&cmd); } @@ -62,6 +59,6 @@ fn main() -> Result<(), Box> { builder = builder.sender(tx); let job = builder.build()?; - job.run()?; + job.run(!args.dry_run)?; Ok(()) }