backup: only allow finished backups as base snapshot

If the datastore holds broken backups for some reason, do not attempt to
base following snapshots on those. This would lead to an error on
/previous, leaving the client no choice but to upload all chunks, even
though there might be potential for incremental savings.

Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
This commit is contained in:
Stefan Reiter 2020-08-04 12:42:00 +02:00 committed by Dietmar Maurer
parent 747c3bc087
commit 4dbe129284
2 changed files with 7 additions and 3 deletions

View File

@ -97,7 +97,7 @@ async move {
bail!("backup owner check failed ({} != {})", username, owner); bail!("backup owner check failed ({} != {})", username, owner);
} }
let last_backup = BackupInfo::last_backup(&datastore.base_path(), &backup_group).unwrap_or(None); let last_backup = BackupInfo::last_backup(&datastore.base_path(), &backup_group, true).unwrap_or(None);
let backup_dir = BackupDir::new_with_group(backup_group.clone(), backup_time); let backup_dir = BackupDir::new_with_group(backup_group.clone(), backup_time);
if let Some(last) = &last_backup { if let Some(last) = &last_backup {

View File

@ -313,9 +313,13 @@ impl BackupInfo {
} }
/// Finds the latest backup inside a backup group /// Finds the latest backup inside a backup group
pub fn last_backup(base_path: &Path, group: &BackupGroup) -> Result<Option<BackupInfo>, Error> { pub fn last_backup(base_path: &Path, group: &BackupGroup, only_finished: bool)
-> Result<Option<BackupInfo>, Error>
{
let backups = group.list_backups(base_path)?; let backups = group.list_backups(base_path)?;
Ok(backups.into_iter().max_by_key(|item| item.backup_dir.backup_time())) Ok(backups.into_iter()
.filter(|item| !only_finished || item.is_finished())
.max_by_key(|item| item.backup_dir.backup_time()))
} }
pub fn sort_list(list: &mut Vec<BackupInfo>, ascendending: bool) { pub fn sort_list(list: &mut Vec<BackupInfo>, ascendending: bool) {