List backups by folder (re #5)

pull/10/head
Dennis Schwerdel 2017-04-13 13:32:59 +02:00
parent 14ae015865
commit 650ab331c0
7 changed files with 40 additions and 30 deletions

View File

@ -110,7 +110,7 @@ fn find_reference_backup(repo: &Repository, path: &str) -> Result<Option<(String
Ok(hostname) => hostname, Ok(hostname) => hostname,
Err(_) => return Ok(None) Err(_) => return Ok(None)
}; };
let backup_map = match repo.get_backups() { let backup_map = match repo.get_all_backups() {
Ok(backup_map) => backup_map, Ok(backup_map) => backup_map,
Err(RepositoryError::BackupFile(BackupFileError::PartialBackupsList(backup_map, _failed))) => { Err(RepositoryError::BackupFile(BackupFileError::PartialBackupsList(backup_map, _failed))) => {
warn!("Some backups could not be read, ignoring them"); warn!("Some backups could not be read, ignoring them");
@ -444,30 +444,36 @@ pub fn run() -> Result<(), ErrorCode> {
}, },
Arguments::List{repo_path, backup_name, inode} => { Arguments::List{repo_path, backup_name, inode} => {
let mut repo = try!(open_repository(&repo_path)); let mut repo = try!(open_repository(&repo_path));
if let Some(backup_name) = backup_name { let backup_map = if let Some(backup_name) = backup_name {
let backup = try!(get_backup(&repo, &backup_name)); if repo.layout.backups_path().join(&backup_name).is_dir() {
let inode = checked!(repo.get_backup_inode(&backup, inode.as_ref().map(|v| v as &str).unwrap_or("/")), "load subpath inode", ErrorCode::LoadInode); repo.get_backups(&backup_name)
println!("{}", format_inode_one_line(&inode)); } else {
if let Some(children) = inode.children { let backup = try!(get_backup(&repo, &backup_name));
for chunks in children.values() { let inode = checked!(repo.get_backup_inode(&backup, inode.as_ref().map(|v| v as &str).unwrap_or("/")), "load subpath inode", ErrorCode::LoadInode);
let inode = checked!(repo.get_inode(chunks), "load child inode", ErrorCode::LoadInode); println!("{}", format_inode_one_line(&inode));
println!("- {}", format_inode_one_line(&inode)); if let Some(children) = inode.children {
for chunks in children.values() {
let inode = checked!(repo.get_inode(chunks), "load child inode", ErrorCode::LoadInode);
println!("- {}", format_inode_one_line(&inode));
}
} }
return Ok(())
} }
} else { } else {
let backup_map = match repo.get_backups() { repo.get_all_backups()
Ok(backup_map) => backup_map, };
Err(RepositoryError::BackupFile(BackupFileError::PartialBackupsList(backup_map, _failed))) => { let backup_map = match backup_map {
warn!("Some backups could not be read, ignoring them"); Ok(backup_map) => backup_map,
backup_map Err(RepositoryError::BackupFile(BackupFileError::PartialBackupsList(backup_map, _failed))) => {
}, warn!("Some backups could not be read, ignoring them");
Err(err) => { backup_map
error!("Failed to load backup files: {}", err); },
return Err(ErrorCode::LoadBackup) Err(err) => {
} error!("Failed to load backup files: {}", err);
}; return Err(ErrorCode::LoadBackup)
print_backups(&backup_map); }
} };
print_backups(&backup_map);
}, },
Arguments::Info{repo_path, backup_name, inode} => { Arguments::Info{repo_path, backup_name, inode} => {
let mut repo = try!(open_repository(&repo_path)); let mut repo = try!(open_repository(&repo_path));

View File

@ -155,7 +155,7 @@ impl<'a> FuseFilesystem<'a> {
pub fn from_repository(repository: &'a mut Repository) -> Result<Self, RepositoryError> { pub fn from_repository(repository: &'a mut Repository) -> Result<Self, RepositoryError> {
let mut backups = vec![]; let mut backups = vec![];
for (name, backup) in try!(repository.get_backups()) { for (name, backup) in try!(repository.get_all_backups()) {
let inode = try!(repository.get_inode(&backup.root)); let inode = try!(repository.get_inode(&backup.root));
backups.push((name, backup, inode)); backups.push((name, backup, inode));
} }

View File

@ -38,10 +38,14 @@ pub enum DiffType {
impl Repository { impl Repository {
pub fn get_backups(&self) -> Result<HashMap<String, Backup>, RepositoryError> { pub fn get_all_backups(&self) -> Result<HashMap<String, Backup>, RepositoryError> {
Ok(try!(Backup::get_all_from(&self.crypto.lock().unwrap(), self.layout.backups_path()))) Ok(try!(Backup::get_all_from(&self.crypto.lock().unwrap(), self.layout.backups_path())))
} }
pub fn get_backups<P: AsRef<Path>>(&self, path: P) -> Result<HashMap<String, Backup>, RepositoryError> {
Ok(try!(Backup::get_all_from(&self.crypto.lock().unwrap(), self.layout.backups_path().join(path))))
}
#[inline] #[inline]
pub fn has_backup(&self, name: &str) -> bool { pub fn has_backup(&self, name: &str) -> bool {
self.layout.backup_path(name).exists() self.layout.backup_path(name).exists()
@ -75,7 +79,7 @@ impl Repository {
pub fn prune_backups(&mut self, prefix: &str, daily: usize, weekly: usize, monthly: usize, yearly: usize, force: bool) -> Result<(), RepositoryError> { pub fn prune_backups(&mut self, prefix: &str, daily: usize, weekly: usize, monthly: usize, yearly: usize, force: bool) -> Result<(), RepositoryError> {
try!(self.write_mode()); try!(self.write_mode());
let mut backups = Vec::new(); let mut backups = Vec::new();
let backup_map = match self.get_backups() { let backup_map = match self.get_all_backups() {
Ok(backup_map) => backup_map, Ok(backup_map) => backup_map,
Err(RepositoryError::BackupFile(BackupFileError::PartialBackupsList(backup_map, _failed))) => { Err(RepositoryError::BackupFile(BackupFileError::PartialBackupsList(backup_map, _failed))) => {
warn!("Some backups could not be read, ignoring them"); warn!("Some backups could not be read, ignoring them");
@ -341,7 +345,7 @@ impl Repository {
pub fn find_versions<P: AsRef<Path>>(&mut self, path: P) -> Result<Vec<(String, Inode)>, RepositoryError> { pub fn find_versions<P: AsRef<Path>>(&mut self, path: P) -> Result<Vec<(String, Inode)>, RepositoryError> {
let path = path.as_ref(); let path = path.as_ref();
let mut versions = HashMap::new(); let mut versions = HashMap::new();
for (name, backup) in try!(self.get_backups()) { for (name, backup) in try!(self.get_all_backups()) {
match self.get_backup_inode(&backup, path) { match self.get_backup_inode(&backup, path) {
Ok(inode) => { Ok(inode) => {
versions.insert((inode.file_type, inode.timestamp, inode.size), (name, inode)); versions.insert((inode.file_type, inode.timestamp, inode.size), (name, inode));

View File

@ -171,7 +171,7 @@ impl Backup {
if relpath.extension() != Some("backup".as_ref()) { if relpath.extension() != Some("backup".as_ref()) {
continue continue
} }
let name = relpath.file_stem().unwrap().to_string_lossy().to_string(); let name = relpath.with_file_name(relpath.file_stem().unwrap()).to_string_lossy().to_string();
if let Ok(backup) = Backup::read_from(crypto, &path) { if let Ok(backup) = Backup::read_from(crypto, &path) {
backups.insert(name, backup); backups.insert(name, backup);
} else { } else {

View File

@ -74,7 +74,7 @@ impl Repository {
used_raw_size: 0 used_raw_size: 0
}); });
} }
let backups = try!(self.get_backups()); let backups = try!(self.get_all_backups());
let mut todo = VecDeque::new(); let mut todo = VecDeque::new();
for (_name, backup) in backups { for (_name, backup) in backups {
todo.push_back(backup.root); todo.push_back(backup.root);

View File

@ -262,7 +262,7 @@ impl Repository {
}; };
info!("Checking backups..."); info!("Checking backups...");
let mut checked = Bitmap::new(self.index.capacity()); let mut checked = Bitmap::new(self.index.capacity());
let backup_map = match self.get_backups() { let backup_map = match self.get_all_backups() {
Ok(backup_map) => backup_map, Ok(backup_map) => backup_map,
Err(RepositoryError::BackupFile(BackupFileError::PartialBackupsList(backup_map, _failed))) => { Err(RepositoryError::BackupFile(BackupFileError::PartialBackupsList(backup_map, _failed))) => {
warn!("Some backups could not be read, ignoring them"); warn!("Some backups could not be read, ignoring them");

View File

@ -163,7 +163,7 @@ impl Repository {
try!(repo.crypto.lock().unwrap().register_keyfile(file)); try!(repo.crypto.lock().unwrap().register_keyfile(file));
} }
repo = try!(Repository::open(path)); repo = try!(Repository::open(path));
let mut backups: Vec<(String, Backup)> = try!(repo.get_backups()).into_iter().collect(); let mut backups: Vec<(String, Backup)> = try!(repo.get_all_backups()).into_iter().collect();
backups.sort_by_key(|&(_, ref b)| b.date); backups.sort_by_key(|&(_, ref b)| b.date);
if let Some((name, backup)) = backups.pop() { if let Some((name, backup)) = backups.pop() {
info!("Taking configuration from the last backup '{}'", name); info!("Taking configuration from the last backup '{}'", name);