src/backup/backup_info.rs - compute_prune_list: remove unfinished backups

This commit is contained in:
Dietmar Maurer 2019-12-05 11:18:10 +01:00
parent 6b9f395f31
commit 9ce42759ec
6 changed files with 26 additions and 7 deletions

View File

@ -86,6 +86,9 @@ fn upgrade_to_backup_protocol(
if backup_dir.backup_time() <= last.backup_dir.backup_time() {
bail!("backup timestamp is older than last backup.");
}
// fixme: abort if last backup is still running - howto test?
// Idea: write upid into a file inside snapshot dir. then test if
// it is still running here.
}
let (path, is_new) = datastore.create_backup_dir(&backup_dir)?;

View File

@ -138,18 +138,34 @@ impl BackupGroup {
) -> Result<Vec<BackupInfo>, Error> {
let mut mark = HashMap::new();
BackupInfo::sort_list(&mut list, false);
if let Some(keep_last) = keep_last {
for _ in 0..keep_last {
if list.is_empty() { break; }
let info = list.remove(0);
// remove inclomplete snapshots
let mut keep_unfinished = true;
for info in list.iter() {
// backup is considered unfinished if there is no manifest
if info.files.iter().any(|name| name == super::MANIFEST_BLOB_NAME) {
// There is a new finished backup, so there is no need
// to keep older unfinished backups.
keep_unfinished = false;
} else {
let backup_id = info.backup_dir.relative_path();
mark.insert(backup_id, PruneMark::Keep);
if keep_unfinished { // keep first unfinished
mark.insert(backup_id, PruneMark::Keep);
} else {
mark.insert(backup_id, PruneMark::Remove);
}
keep_unfinished = false;
}
}
if let Some(keep_last) = keep_last {
Self::mark_selections(&mut mark, &list, keep_last as usize, |_local_time, info| {
BackupDir::backup_time_to_string(info.backup_dir.backup_time)
});
}
if let Some(keep_daily) = keep_daily {
Self::mark_selections(&mut mark, &list, keep_daily as usize, |local_time, _info| {
format!("{}/{}/{}", local_time.year(), local_time.month(), local_time.day())