mirror of https://github.com/dswd/zvault
Import
This commit is contained in:
parent
bc152b6609
commit
b43be07ed0
|
@ -12,7 +12,7 @@ pub enum Arguments {
|
||||||
compression: Option<Compression>,
|
compression: Option<Compression>,
|
||||||
encryption: bool,
|
encryption: bool,
|
||||||
hash: HashMethod,
|
hash: HashMethod,
|
||||||
remote: String
|
remote_path: String
|
||||||
},
|
},
|
||||||
Backup {
|
Backup {
|
||||||
repo_path: String,
|
repo_path: String,
|
||||||
|
@ -301,7 +301,7 @@ pub fn parse() -> Arguments {
|
||||||
encryption: args.is_present("encryption"),
|
encryption: args.is_present("encryption"),
|
||||||
hash: parse_hash(args.value_of("hash").unwrap_or(DEFAULT_HASH)),
|
hash: parse_hash(args.value_of("hash").unwrap_or(DEFAULT_HASH)),
|
||||||
repo_path: repository.to_string(),
|
repo_path: repository.to_string(),
|
||||||
remote: args.value_of("remote").unwrap().to_string()
|
remote_path: args.value_of("remote").unwrap().to_string()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Some(args) = args.subcommand_matches("backup") {
|
if let Some(args) = args.subcommand_matches("backup") {
|
||||||
|
|
|
@ -136,14 +136,14 @@ pub fn run() {
|
||||||
exit(-1)
|
exit(-1)
|
||||||
}
|
}
|
||||||
match args::parse() {
|
match args::parse() {
|
||||||
Arguments::Init{repo_path, bundle_size, chunker, compression, encryption, hash, remote} => {
|
Arguments::Init{repo_path, bundle_size, chunker, compression, encryption, hash, remote_path} => {
|
||||||
let mut repo = Repository::create(repo_path, Config {
|
let mut repo = Repository::create(repo_path, Config {
|
||||||
bundle_size: bundle_size,
|
bundle_size: bundle_size,
|
||||||
chunker: chunker,
|
chunker: chunker,
|
||||||
compression: compression,
|
compression: compression,
|
||||||
encryption: None,
|
encryption: None,
|
||||||
hash: hash
|
hash: hash
|
||||||
}, remote).unwrap();
|
}, remote_path).unwrap();
|
||||||
if encryption {
|
if encryption {
|
||||||
let (public, secret) = gen_keypair();
|
let (public, secret) = gen_keypair();
|
||||||
println!("Public key: {}", to_hex(&public[..]));
|
println!("Public key: {}", to_hex(&public[..]));
|
||||||
|
@ -284,9 +284,8 @@ pub fn run() {
|
||||||
println!();
|
println!();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Arguments::Import{..} => {
|
Arguments::Import{repo_path, remote_path} => {
|
||||||
error!("Import is not implemented yet");
|
Repository::import(repo_path, remote_path).unwrap();
|
||||||
return
|
|
||||||
},
|
},
|
||||||
Arguments::Configure{repo_path, bundle_size, chunker, compression, encryption, hash} => {
|
Arguments::Configure{repo_path, bundle_size, chunker, compression, encryption, hash} => {
|
||||||
let mut repo = open_repository(&repo_path);
|
let mut repo = open_repository(&repo_path);
|
||||||
|
|
|
@ -30,7 +30,7 @@ mod prelude;
|
||||||
// TODO: Remove backup subtrees
|
// TODO: Remove backup subtrees
|
||||||
// TODO: Recompress & combine bundles
|
// TODO: Recompress & combine bundles
|
||||||
// TODO: list --tree
|
// TODO: list --tree
|
||||||
// TODO: Import repository from remote folder
|
// TODO: Give crypto keys for import
|
||||||
// TODO: More detailed errors with nicer text
|
// TODO: More detailed errors with nicer text
|
||||||
// TODO: Allow to use tar files for backup and restore (--tar, http://alexcrichton.com/tar-rs/tar/index.html)
|
// TODO: Allow to use tar files for backup and restore (--tar, http://alexcrichton.com/tar-rs/tar/index.html)
|
||||||
|
|
||||||
|
|
|
@ -88,7 +88,8 @@ pub struct Backup {
|
||||||
pub file_count: usize,
|
pub file_count: usize,
|
||||||
pub dir_count: usize,
|
pub dir_count: usize,
|
||||||
pub host: String,
|
pub host: String,
|
||||||
pub path: String
|
pub path: String,
|
||||||
|
pub config: Config,
|
||||||
}
|
}
|
||||||
serde_impl!(Backup(u8) {
|
serde_impl!(Backup(u8) {
|
||||||
root: Vec<Chunk> => 0,
|
root: Vec<Chunk> => 0,
|
||||||
|
@ -104,7 +105,8 @@ serde_impl!(Backup(u8) {
|
||||||
file_count: usize => 10,
|
file_count: usize => 10,
|
||||||
dir_count: usize => 11,
|
dir_count: usize => 11,
|
||||||
host: String => 12,
|
host: String => 12,
|
||||||
path: String => 13
|
path: String => 13,
|
||||||
|
config: Config => 14
|
||||||
});
|
});
|
||||||
|
|
||||||
impl Backup {
|
impl Backup {
|
||||||
|
@ -307,6 +309,7 @@ impl Repository {
|
||||||
let mut save_stack = vec![];
|
let mut save_stack = vec![];
|
||||||
let mut directories = HashMap::new();
|
let mut directories = HashMap::new();
|
||||||
let mut backup = Backup::default();
|
let mut backup = Backup::default();
|
||||||
|
backup.config = self.config.clone();
|
||||||
backup.host = get_hostname().unwrap_or_else(|_| "".to_string());
|
backup.host = get_hostname().unwrap_or_else(|_| "".to_string());
|
||||||
backup.path = path.as_ref().to_string_lossy().to_string();
|
backup.path = path.as_ref().to_string_lossy().to_string();
|
||||||
let info_before = self.info();
|
let info_before = self.info();
|
||||||
|
|
|
@ -149,7 +149,7 @@ serde_impl!(ConfigYaml(String) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
pub compression: Option<Compression>,
|
pub compression: Option<Compression>,
|
||||||
pub encryption: Option<Encryption>,
|
pub encryption: Option<Encryption>,
|
||||||
|
@ -157,6 +157,25 @@ pub struct Config {
|
||||||
pub chunker: ChunkerType,
|
pub chunker: ChunkerType,
|
||||||
pub hash: HashMethod
|
pub hash: HashMethod
|
||||||
}
|
}
|
||||||
|
impl Default for Config {
|
||||||
|
fn default() -> Self {
|
||||||
|
Config {
|
||||||
|
compression: None,
|
||||||
|
encryption: None,
|
||||||
|
bundle_size: 25,
|
||||||
|
chunker: ChunkerType::from_string("fastcdc/16").unwrap(),
|
||||||
|
hash: HashMethod::Blake2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
serde_impl!(Config(u64) {
|
||||||
|
compression: Option<Compression> => 0,
|
||||||
|
encryption: Option<Encryption> => 1,
|
||||||
|
bundle_size: usize => 2,
|
||||||
|
chunker: ChunkerType => 3,
|
||||||
|
hash: HashMethod => 4
|
||||||
|
});
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
fn from_yaml(yaml: ConfigYaml) -> Result<Self, ConfigError> {
|
fn from_yaml(yaml: ConfigYaml) -> Result<Self, ConfigError> {
|
||||||
let compression = if let Some(c) = yaml.compression {
|
let compression = if let Some(c) = yaml.compression {
|
||||||
|
|
|
@ -11,6 +11,7 @@ use super::metadata::InodeError;
|
||||||
|
|
||||||
quick_error!{
|
quick_error!{
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
#[allow(unknown_lints,large_enum_variant)]
|
||||||
pub enum RepositoryError {
|
pub enum RepositoryError {
|
||||||
Index(err: IndexError) {
|
Index(err: IndexError) {
|
||||||
from()
|
from()
|
||||||
|
|
|
@ -109,6 +109,19 @@ impl Repository {
|
||||||
Ok(repo)
|
Ok(repo)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn import<P: AsRef<Path>, R: AsRef<Path>>(path: P, remote: R) -> Result<Self, RepositoryError> {
|
||||||
|
let path = path.as_ref();
|
||||||
|
try!(Repository::create(path, Config::default(), remote));
|
||||||
|
let mut repo = try!(Repository::open(path));
|
||||||
|
let mut backups: Vec<Backup> = try!(repo.get_backups()).into_iter().map(|(_, v)| v).collect();
|
||||||
|
backups.sort_by_key(|b| b.date);
|
||||||
|
if let Some(backup) = backups.pop() {
|
||||||
|
repo.config = backup.config;
|
||||||
|
try!(repo.save_config())
|
||||||
|
}
|
||||||
|
Ok(repo)
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn register_key(&mut self, public: PublicKey, secret: SecretKey) -> Result<(), RepositoryError> {
|
pub fn register_key(&mut self, public: PublicKey, secret: SecretKey) -> Result<(), RepositoryError> {
|
||||||
Ok(try!(self.crypto.lock().unwrap().register_secret_key(public, secret)))
|
Ok(try!(self.crypto.lock().unwrap().register_secret_key(public, secret)))
|
||||||
|
|
Loading…
Reference in New Issue