From 0ed94b3f011a2d3c22bdc4affb502720be22c371 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Sat, 14 Sep 2024 18:59:23 +0200 Subject: add restoration of files and packages --- src/backup.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'src/backup.rs') diff --git a/src/backup.rs b/src/backup.rs index f9de139..3d07ace 100644 --- a/src/backup.rs +++ b/src/backup.rs @@ -45,9 +45,10 @@ impl Backup { pub fn save(&self, config: &Config) -> Result<()> { info!("Save Backup {:?}", self.get_location(config)); - self.get_location(config).append_to_root(config)?; + let loc = self.get_location(config); + loc.append_to_root(config)?; - let backup_root = self.get_location(config).get_absolute_dir(config); + let backup_root = loc.get_absolute_dir(config); create_dir_all(&backup_root).unwrap(); let path = format!("{backup_root}/index.json"); let mut f = File::create(path).unwrap(); @@ -66,7 +67,7 @@ impl Backup { let list: Vec = match Self::get_json_content(&backup_index_root) { Ok(list) => list, Err(err) => { - if err.to_string() == "io: No such file or directory (os error 2)" { + if err.to_string() == "No such file or directory (os error 2)" { return Ok(None); }; return Err(err); @@ -112,8 +113,16 @@ impl Backup { format!("{loc}/{rel_location}") } - pub fn restore(&self) { - todo!() + pub fn restore(&self, config: &Config) -> Result<()> { + info!(?self.id, ?self.timestamp, "Restore Backup"); + + let backup_root = self.get_location(config).get_absolute_dir(config); + + for path in &self.files { + path.restore(config, &backup_root)?; + } + + Ok(()) } fn get_json_content Deserialize<'a>>(path: &str) -> Result { -- cgit v1.2.3