diff options
Diffstat (limited to 'src/backup.rs')
-rw-r--r-- | src/backup.rs | 19 |
1 files changed, 14 insertions, 5 deletions
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 { | |||
45 | 45 | ||
46 | pub fn save(&self, config: &Config) -> Result<()> { | 46 | pub fn save(&self, config: &Config) -> Result<()> { |
47 | info!("Save Backup {:?}", self.get_location(config)); | 47 | info!("Save Backup {:?}", self.get_location(config)); |
48 | self.get_location(config).append_to_root(config)?; | 48 | let loc = self.get_location(config); |
49 | loc.append_to_root(config)?; | ||
49 | 50 | ||
50 | let backup_root = self.get_location(config).get_absolute_dir(config); | 51 | let backup_root = loc.get_absolute_dir(config); |
51 | create_dir_all(&backup_root).unwrap(); | 52 | create_dir_all(&backup_root).unwrap(); |
52 | let path = format!("{backup_root}/index.json"); | 53 | let path = format!("{backup_root}/index.json"); |
53 | let mut f = File::create(path).unwrap(); | 54 | let mut f = File::create(path).unwrap(); |
@@ -66,7 +67,7 @@ impl Backup { | |||
66 | let list: Vec<IndexEntry> = match Self::get_json_content(&backup_index_root) { | 67 | let list: Vec<IndexEntry> = match Self::get_json_content(&backup_index_root) { |
67 | Ok(list) => list, | 68 | Ok(list) => list, |
68 | Err(err) => { | 69 | Err(err) => { |
69 | if err.to_string() == "io: No such file or directory (os error 2)" { | 70 | if err.to_string() == "No such file or directory (os error 2)" { |
70 | return Ok(None); | 71 | return Ok(None); |
71 | }; | 72 | }; |
72 | return Err(err); | 73 | return Err(err); |
@@ -112,8 +113,16 @@ impl Backup { | |||
112 | format!("{loc}/{rel_location}") | 113 | format!("{loc}/{rel_location}") |
113 | } | 114 | } |
114 | 115 | ||
115 | pub fn restore(&self) { | 116 | pub fn restore(&self, config: &Config) -> Result<()> { |
116 | todo!() | 117 | info!(?self.id, ?self.timestamp, "Restore Backup"); |
118 | |||
119 | let backup_root = self.get_location(config).get_absolute_dir(config); | ||
120 | |||
121 | for path in &self.files { | ||
122 | path.restore(config, &backup_root)?; | ||
123 | } | ||
124 | |||
125 | Ok(()) | ||
117 | } | 126 | } |
118 | 127 | ||
119 | fn get_json_content<T: for<'a> Deserialize<'a>>(path: &str) -> Result<T> { | 128 | fn get_json_content<T: for<'a> Deserialize<'a>>(path: &str) -> Result<T> { |