Partial restore

pull/10/head
Dennis Schwerdel 2017-03-16 14:14:35 +01:00
parent 9fc70ea0fb
commit 542ecb4ae0
2 changed files with 18 additions and 4 deletions

View File

@ -30,7 +30,7 @@ static USAGE: &'static str = "
Usage:
zvault init [--bundle-size SIZE] [--chunker METHOD] [--chunk-size SIZE] [--compression COMPRESSION] <repo>
zvault backup [--full] <backup> <path>
zvault restore <backup> <path>
zvault restore <backup> [<src>] <dst>
zvault check [--full] <repo>
zvault backups <repo>
zvault info <backup>
@ -68,6 +68,8 @@ struct Args {
arg_repo: Option<String>,
arg_path: Option<String>,
arg_src: Option<String>,
arg_dst: Option<String>,
arg_backup: Option<String>,
flag_full: bool,
@ -188,7 +190,13 @@ fn main() {
}
if args.cmd_restore {
repo.restore_backup(&backup, &args.arg_path.unwrap()).unwrap();
let dst = args.arg_dst.unwrap();
if let Some(src) = args.arg_src {
let inode = repo.get_backup_inode(&backup, src).unwrap();
repo.restore_inode_tree(inode, &dst).unwrap();
} else {
repo.restore_backup(&backup, &dst).unwrap();
}
return
}

View File

@ -72,9 +72,9 @@ impl Repository {
Ok(try!(msgpack::encode_to_stream(backup, &mut file)))
}
pub fn restore_backup<P: AsRef<Path>>(&mut self, backup: &Backup, 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();
queue.push_back((path.as_ref().to_owned(), try!(self.get_inode(&backup.root))));
queue.push_back((path.as_ref().to_owned(), inode));
while let Some((path, inode)) = queue.pop_front() {
try!(self.save_inode_at(&inode, &path));
if inode.file_type == FileType::Directory {
@ -88,6 +88,12 @@ impl Repository {
Ok(())
}
#[inline]
pub fn restore_backup<P: AsRef<Path>>(&mut self, backup: &Backup, path: P) -> Result<(), RepositoryError> {
let inode = try!(self.get_inode(&backup.root));
self.restore_inode_tree(inode, path)
}
#[allow(dead_code)]
pub fn create_full_backup<P: AsRef<Path>>(&mut self, path: P) -> Result<Backup, RepositoryError> {
let mut scan_stack = vec![path.as_ref().to_owned()];