From f53b9a092380bdda75f5241e823797e9f7722eb9 Mon Sep 17 00:00:00 2001 From: Dennis Schwerdel Date: Fri, 24 Mar 2017 09:05:41 +0100 Subject: [PATCH] Remote backups --- README.md | 1 - src/repository/backup.rs | 8 ++++---- src/repository/mod.rs | 7 +++++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 5b8eed3..dcfc1ef 100644 --- a/README.md +++ b/README.md @@ -98,7 +98,6 @@ Recommended: Brotli/2-7 ## TODO ### Core functionality -- Keep backup files also remotely and sync them - Options for creating backups (same filesystem, exclude/include patterns) - Recompress & combine bundles - Allow to use tar files for backup and restore (--tar, http://alexcrichton.com/tar-rs/tar/index.html) diff --git a/src/repository/backup.rs b/src/repository/backup.rs index dfcbbd0..6f2970c 100644 --- a/src/repository/backup.rs +++ b/src/repository/backup.rs @@ -195,21 +195,21 @@ quick_error!{ impl Repository { pub fn get_backups(&self) -> Result, RepositoryError> { - Ok(try!(Backup::get_all_from(&self.crypto.lock().unwrap(), self.path.join("backups")))) + Ok(try!(Backup::get_all_from(&self.crypto.lock().unwrap(), &self.backups_path))) } pub fn get_backup(&self, name: &str) -> Result { - Ok(try!(Backup::read_from(&self.crypto.lock().unwrap(), self.path.join("backups").join(name)))) + Ok(try!(Backup::read_from(&self.crypto.lock().unwrap(), self.backups_path.join(name)))) } pub fn save_backup(&mut self, backup: &Backup, name: &str) -> Result<(), RepositoryError> { - let path = self.path.join("backups").join(name); + let path = &self.backups_path.join(name); try!(fs::create_dir_all(path.parent().unwrap())); Ok(try!(backup.save_to(&self.crypto.lock().unwrap(), self.config.encryption.clone(), path))) } pub fn delete_backup(&self, name: &str) -> Result<(), RepositoryError> { - let mut path = self.path.join("backups").join(name); + let mut path = self.backups_path.join(name); try!(fs::remove_file(&path)); loop { path = path.parent().unwrap().to_owned(); diff --git a/src/repository/mod.rs b/src/repository/mod.rs index 4c402e2..6e4bd58 100644 --- a/src/repository/mod.rs +++ b/src/repository/mod.rs @@ -28,6 +28,7 @@ use self::bundle_map::BundleMap; pub struct Repository { path: PathBuf, + backups_path: PathBuf, pub config: Config, index: Index, crypto: Arc>, @@ -60,8 +61,9 @@ impl Repository { try!(config.save(path.join("config.yaml"))); let bundle_map = BundleMap::create(); try!(bundle_map.save(path.join("bundles.map"))); - try!(fs::create_dir(&path.join("backups"))); - Ok(Repository{ + try!(fs::create_dir_all(&path.join("remote/backups"))); + Ok(Repository { + backups_path: path.join("remote/backups"), path: path, chunker: config.chunker.create(), config: config, @@ -90,6 +92,7 @@ impl Repository { let index = try!(Index::open(&path.join("index"))); let bundle_map = try!(BundleMap::load(path.join("bundles.map"))); let mut repo = Repository { + backups_path: path.join("remote/backups"), path: path, chunker: config.chunker.create(), config: config,