diff --git a/src/api2/backup.rs b/src/api2/backup.rs index 13463716..74bd5fb8 100644 --- a/src/api2/backup.rs +++ b/src/api2/backup.rs @@ -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)?; diff --git a/src/backup/backup_info.rs b/src/backup/backup_info.rs index 78858dd6..8562635d 100644 --- a/src/backup/backup_info.rs +++ b/src/backup/backup_info.rs @@ -138,18 +138,34 @@ impl BackupGroup { ) -> Result, 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()) diff --git a/tests/prune_data/simple1/host/elsa/2019-12-02T11:59:15Z/index.json b/tests/prune_data/simple1/host/elsa/2019-12-02T11:59:15Z/index.json.blob similarity index 100% rename from tests/prune_data/simple1/host/elsa/2019-12-02T11:59:15Z/index.json rename to tests/prune_data/simple1/host/elsa/2019-12-02T11:59:15Z/index.json.blob diff --git a/tests/prune_data/simple1/host/elsa/2019-12-03T11:59:15Z/index.json b/tests/prune_data/simple1/host/elsa/2019-12-03T11:59:15Z/index.json.blob similarity index 100% rename from tests/prune_data/simple1/host/elsa/2019-12-03T11:59:15Z/index.json rename to tests/prune_data/simple1/host/elsa/2019-12-03T11:59:15Z/index.json.blob diff --git a/tests/prune_data/simple1/host/elsa/2019-12-04T11:59:15Z/index.json b/tests/prune_data/simple1/host/elsa/2019-12-04T11:59:15Z/index.json.blob similarity index 100% rename from tests/prune_data/simple1/host/elsa/2019-12-04T11:59:15Z/index.json rename to tests/prune_data/simple1/host/elsa/2019-12-04T11:59:15Z/index.json.blob diff --git a/tests/prune_data/simple1/host/elsa/2019-12-04T12:59:15Z/index.json b/tests/prune_data/simple1/host/elsa/2019-12-04T12:59:15Z/index.json.blob similarity index 100% rename from tests/prune_data/simple1/host/elsa/2019-12-04T12:59:15Z/index.json rename to tests/prune_data/simple1/host/elsa/2019-12-04T12:59:15Z/index.json.blob