List backups by folder (re #5)

pull/10/head
Dennis Schwerdel 6 years ago
parent 14ae015865
commit 650ab331c0

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

@ -155,7 +155,7 @@ impl<'a> FuseFilesystem<'a> {
pub fn from_repository(repository: &'a mut Repository) -> Result<Self, RepositoryError> {
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));
backups.push((name, backup, inode));
}

@ -38,10 +38,14 @@ pub enum DiffType {
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())))
}
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]
pub fn has_backup(&self, name: &str) -> bool {
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> {
try!(self.write_mode());
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,
Err(RepositoryError::BackupFile(BackupFileError::PartialBackupsList(backup_map, _failed))) => {
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> {
let path = path.as_ref();
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) {
Ok(inode) => {
versions.insert((inode.file_type, inode.timestamp, inode.size), (name, inode));

@ -171,7 +171,7 @@ impl Backup {
if relpath.extension() != Some("backup".as_ref()) {
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) {
backups.insert(name, backup);
} else {

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

@ -262,7 +262,7 @@ impl Repository {
};
info!("Checking backups...");
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,
Err(RepositoryError::BackupFile(BackupFileError::PartialBackupsList(backup_map, _failed))) => {
warn!("Some backups could not be read, ignoring them");

@ -163,7 +163,7 @@ impl Repository {
try!(repo.crypto.lock().unwrap().register_keyfile(file));
}
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);
if let Some((name, backup)) = backups.pop() {
info!("Taking configuration from the last backup '{}'", name);

Loading…
Cancel
Save