summaryrefslogtreecommitdiff
path: root/src/backup.rs
diff options
context:
space:
mode:
authorfxqnlr <[email protected]>2024-09-14 18:59:23 +0200
committerfxqnlr <[email protected]>2024-09-14 18:59:23 +0200
commit0ed94b3f011a2d3c22bdc4affb502720be22c371 (patch)
tree9fb2cdbdccfa8c9cf5d9b8d3ccc48443fe6706a6 /src/backup.rs
parent1b99a4a1ed7772c9b68e59f46e493ea5b4715239 (diff)
downloadarbs-0ed94b3f011a2d3c22bdc4affb502720be22c371.tar
arbs-0ed94b3f011a2d3c22bdc4affb502720be22c371.tar.gz
arbs-0ed94b3f011a2d3c22bdc4affb502720be22c371.zip
add restoration of files and packages
Diffstat (limited to 'src/backup.rs')
-rw-r--r--src/backup.rs19
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> {