mirror of https://github.com/dswd/zvault
Partial restore
This commit is contained in:
parent
9fc70ea0fb
commit
542ecb4ae0
12
src/main.rs
12
src/main.rs
|
@ -30,7 +30,7 @@ static USAGE: &'static str = "
|
||||||
Usage:
|
Usage:
|
||||||
zvault init [--bundle-size SIZE] [--chunker METHOD] [--chunk-size SIZE] [--compression COMPRESSION] <repo>
|
zvault init [--bundle-size SIZE] [--chunker METHOD] [--chunk-size SIZE] [--compression COMPRESSION] <repo>
|
||||||
zvault backup [--full] <backup> <path>
|
zvault backup [--full] <backup> <path>
|
||||||
zvault restore <backup> <path>
|
zvault restore <backup> [<src>] <dst>
|
||||||
zvault check [--full] <repo>
|
zvault check [--full] <repo>
|
||||||
zvault backups <repo>
|
zvault backups <repo>
|
||||||
zvault info <backup>
|
zvault info <backup>
|
||||||
|
@ -68,6 +68,8 @@ struct Args {
|
||||||
|
|
||||||
arg_repo: Option<String>,
|
arg_repo: Option<String>,
|
||||||
arg_path: Option<String>,
|
arg_path: Option<String>,
|
||||||
|
arg_src: Option<String>,
|
||||||
|
arg_dst: Option<String>,
|
||||||
arg_backup: Option<String>,
|
arg_backup: Option<String>,
|
||||||
|
|
||||||
flag_full: bool,
|
flag_full: bool,
|
||||||
|
@ -188,7 +190,13 @@ fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if args.cmd_restore {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -72,9 +72,9 @@ impl Repository {
|
||||||
Ok(try!(msgpack::encode_to_stream(backup, &mut file)))
|
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();
|
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() {
|
while let Some((path, inode)) = queue.pop_front() {
|
||||||
try!(self.save_inode_at(&inode, &path));
|
try!(self.save_inode_at(&inode, &path));
|
||||||
if inode.file_type == FileType::Directory {
|
if inode.file_type == FileType::Directory {
|
||||||
|
@ -88,6 +88,12 @@ impl Repository {
|
||||||
Ok(())
|
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)]
|
#[allow(dead_code)]
|
||||||
pub fn create_full_backup<P: AsRef<Path>>(&mut self, path: P) -> Result<Backup, RepositoryError> {
|
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()];
|
let mut scan_stack = vec![path.as_ref().to_owned()];
|
||||||
|
|
Loading…
Reference in New Issue