Remote backups

This commit is contained in:
Dennis Schwerdel 2017-03-24 09:05:41 +01:00
parent 828bcc6dc9
commit f53b9a0923
3 changed files with 9 additions and 7 deletions

View File

@ -98,7 +98,6 @@ Recommended: Brotli/2-7
## TODO ## TODO
### Core functionality ### Core functionality
- Keep backup files also remotely and sync them
- Options for creating backups (same filesystem, exclude/include patterns) - Options for creating backups (same filesystem, exclude/include patterns)
- Recompress & combine bundles - Recompress & combine bundles
- Allow to use tar files for backup and restore (--tar, http://alexcrichton.com/tar-rs/tar/index.html) - Allow to use tar files for backup and restore (--tar, http://alexcrichton.com/tar-rs/tar/index.html)

View File

@ -195,21 +195,21 @@ quick_error!{
impl Repository { impl Repository {
pub fn get_backups(&self) -> Result<HashMap<String, Backup>, RepositoryError> { pub fn get_backups(&self) -> Result<HashMap<String, Backup>, 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<Backup, RepositoryError> { pub fn get_backup(&self, name: &str) -> Result<Backup, RepositoryError> {
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> { 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())); try!(fs::create_dir_all(path.parent().unwrap()));
Ok(try!(backup.save_to(&self.crypto.lock().unwrap(), self.config.encryption.clone(), path))) Ok(try!(backup.save_to(&self.crypto.lock().unwrap(), self.config.encryption.clone(), path)))
} }
pub fn delete_backup(&self, name: &str) -> Result<(), RepositoryError> { 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)); try!(fs::remove_file(&path));
loop { loop {
path = path.parent().unwrap().to_owned(); path = path.parent().unwrap().to_owned();

View File

@ -28,6 +28,7 @@ use self::bundle_map::BundleMap;
pub struct Repository { pub struct Repository {
path: PathBuf, path: PathBuf,
backups_path: PathBuf,
pub config: Config, pub config: Config,
index: Index, index: Index,
crypto: Arc<Mutex<Crypto>>, crypto: Arc<Mutex<Crypto>>,
@ -60,8 +61,9 @@ impl Repository {
try!(config.save(path.join("config.yaml"))); try!(config.save(path.join("config.yaml")));
let bundle_map = BundleMap::create(); let bundle_map = BundleMap::create();
try!(bundle_map.save(path.join("bundles.map"))); try!(bundle_map.save(path.join("bundles.map")));
try!(fs::create_dir(&path.join("backups"))); try!(fs::create_dir_all(&path.join("remote/backups")));
Ok(Repository{ Ok(Repository {
backups_path: path.join("remote/backups"),
path: path, path: path,
chunker: config.chunker.create(), chunker: config.chunker.create(),
config: config, config: config,
@ -90,6 +92,7 @@ impl Repository {
let index = try!(Index::open(&path.join("index"))); let index = try!(Index::open(&path.join("index")));
let bundle_map = try!(BundleMap::load(path.join("bundles.map"))); let bundle_map = try!(BundleMap::load(path.join("bundles.map")));
let mut repo = Repository { let mut repo = Repository {
backups_path: path.join("remote/backups"),
path: path, path: path,
chunker: config.chunker.create(), chunker: config.chunker.create(),
config: config, config: config,