Backup trees and removing backups

This commit is contained in:
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} => { Arguments::Remove{repo_path, backup_name, inode} => {
let repo = open_repository(&repo_path); let repo = open_repository(&repo_path);
let _backup = get_backup(&repo, &backup_name);
if let Some(_inode) = inode { if let Some(_inode) = inode {
let _backup = get_backup(&repo, &backup_name);
error!("Removing backup subtrees is not implemented yet"); error!("Removing backup subtrees is not implemented yet");
return return
} else { } else {
error!("Removing backups is not implemented yet"); repo.delete_backup(&backup_name).unwrap();
return info!("The backup has been deleted, run vacuum to reclaim space");
} }
}, },
Arguments::Vacuum{repo_path, ..} => { Arguments::Vacuum{repo_path, ..} => {

View File

@ -27,10 +27,9 @@ mod cli;
// TODO: - Load and compare remote bundles to bundle map // TODO: - Load and compare remote bundles to bundle map
// TODO: - Write backup files there as well // TODO: - Write backup files there as well
// TODO: Store list of hashes and hash method in bundle // TODO: Store list of hashes and hash method in bundle
// TODO: Remove backups/subtrees // TODO: Remove backup subtrees
// TODO: Recompress & combine bundles // TODO: Recompress & combine bundles
// TODO: Prune backups (based on age like attic) // TODO: Prune backups (based on age like attic)
// TODO: Backup files tree structure
// TODO: Check backup integrity too // TODO: Check backup integrity too
// TODO: Encryption // TODO: Encryption
// TODO: list --tree // TODO: list --tree

View File

@ -68,10 +68,24 @@ impl Repository {
} }
pub fn save_backup(&mut self, backup: &Backup, name: &str) -> Result<(), RepositoryError> { 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))) 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> { pub fn restore_inode_tree<P: AsRef<Path>>(&mut self, inode: Inode, path: P) -> Result<(), RepositoryError> {
let mut queue = VecDeque::new(); let mut queue = VecDeque::new();
queue.push_back((path.as_ref().to_owned(), inode)); queue.push_back((path.as_ref().to_owned(), inode));