diff --git a/src/cli/mod.rs b/src/cli/mod.rs index 19f26fe..3b0c4c0 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -64,13 +64,13 @@ pub fn run() { }, Arguments::Remove{repo_path, backup_name, inode} => { let repo = open_repository(&repo_path); - let _backup = get_backup(&repo, &backup_name); if let Some(_inode) = inode { + let _backup = get_backup(&repo, &backup_name); error!("Removing backup subtrees is not implemented yet"); return } else { - error!("Removing backups is not implemented yet"); - return + repo.delete_backup(&backup_name).unwrap(); + info!("The backup has been deleted, run vacuum to reclaim space"); } }, Arguments::Vacuum{repo_path, ..} => { diff --git a/src/main.rs b/src/main.rs index 424f60c..2f1e1c3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,10 +27,9 @@ mod cli; // TODO: - Load and compare remote bundles to bundle map // TODO: - Write backup files there as well // TODO: Store list of hashes and hash method in bundle -// TODO: Remove backups/subtrees +// TODO: Remove backup subtrees // TODO: Recompress & combine bundles // TODO: Prune backups (based on age like attic) -// TODO: Backup files tree structure // TODO: Check backup integrity too // TODO: Encryption // TODO: list --tree diff --git a/src/repository/backup.rs b/src/repository/backup.rs index 2a592a2..2d8c252 100644 --- a/src/repository/backup.rs +++ b/src/repository/backup.rs @@ -68,10 +68,24 @@ impl Repository { } pub fn save_backup(&mut self, backup: &Backup, name: &str) -> Result<(), RepositoryError> { - let mut file = try!(File::create(self.path.join("backups").join(name))); + let path = self.path.join("backups").join(name); + try!(fs::create_dir_all(path.parent().unwrap())); + let mut file = try!(File::create(path)); Ok(try!(msgpack::encode_to_stream(backup, &mut file))) } + pub fn delete_backup(&self, name: &str) -> Result<(), RepositoryError> { + let mut path = self.path.join("backups").join(name); + try!(fs::remove_file(&path)); + loop { + path = path.parent().unwrap().to_owned(); + if fs::remove_dir(&path).is_err() { + break + } + } + Ok(()) + } + pub fn restore_inode_tree>(&mut self, inode: Inode, path: P) -> Result<(), RepositoryError> { let mut queue = VecDeque::new(); queue.push_back((path.as_ref().to_owned(), inode));