Backup trees and removing backups

pull/10/head
Dennis Schwerdel 2017-03-18 16:54:43 +01:00 committed by Dennis Schwerdel
parent 032848466f
commit 0a807b16ab
3 changed files with 19 additions and 6 deletions

View File

@ -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, ..} => {

View File

@ -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

View File

@ -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<P: AsRef<Path>>(&mut self, inode: Inode, path: P) -> Result<(), RepositoryError> {
let mut queue = VecDeque::new();
queue.push_back((path.as_ref().to_owned(), inode));