src/backup/backup_info.rs: improve prune algorithm

This commit is contained in:
Dietmar Maurer
2019-12-05 08:55:19 +01:00
parent 0c875cf379
commit 2c034f8d0a
2 changed files with 57 additions and 20 deletions

View File

@ -81,20 +81,16 @@ fn test_prune_simple() -> Result<(), Error> {
// keep-last, keep-daily mixed
let list = orig_list.clone();
let remove_list = get_prune_list(list, Some(2), Some(2), None, None, None);
let expect: Vec<PathBuf> = vec![
PathBuf::from("host/elsa/2019-12-02T11:59:15Z"),
];
let expect: Vec<PathBuf> = vec![];
assert_eq!(remove_list, expect);
// keep-daily test
let list = orig_list.clone();
let remove_list = get_prune_list(list, None, Some(3), None, None, None);
let expect: Vec<PathBuf> = vec![PathBuf::from("host/elsa/2019-12-04T11:59:15Z")];
assert_eq!(remove_list, expect);
// keep-daily test
let list = orig_list.clone();
let remove_list = get_prune_list(list, None, Some(2), None, None, None);
let expect: Vec<PathBuf> = vec![
@ -106,6 +102,7 @@ fn test_prune_simple() -> Result<(), Error> {
// keep-weekly
let list = orig_list.clone();
let remove_list = get_prune_list(list, None, None, Some(5), None, None);
// all backup are within the same week, so we only keep a single file
let expect: Vec<PathBuf> = vec![
PathBuf::from("host/elsa/2019-12-02T11:59:15Z"),
PathBuf::from("host/elsa/2019-12-03T11:59:15Z"),
@ -113,9 +110,19 @@ fn test_prune_simple() -> Result<(), Error> {
];
assert_eq!(remove_list, expect);
// keep-monthly
// keep-daily + keep-weekly
let list = orig_list.clone();
let remove_list = get_prune_list(list, None, Some(1), Some(5), None, None);
let expect: Vec<PathBuf> = vec![
PathBuf::from("host/elsa/2019-12-02T11:59:15Z"),
PathBuf::from("host/elsa/2019-12-04T11:59:15Z"),
];
assert_eq!(remove_list, expect);
// keep-monthly
let list = orig_list.clone();
let remove_list = get_prune_list(list, None, None, None, Some(6), None);
// all backup are within the same month, so we only keep a single file
let expect: Vec<PathBuf> = vec![
PathBuf::from("host/elsa/2019-12-02T11:59:15Z"),
PathBuf::from("host/elsa/2019-12-03T11:59:15Z"),
@ -123,9 +130,21 @@ fn test_prune_simple() -> Result<(), Error> {
];
assert_eq!(remove_list, expect);
// keep-yearly
// keep-yearly
let list = orig_list.clone();
let remove_list = get_prune_list(list, None, None, None, None, Some(7));
// all backup are within the same year, so we only keep a single file
let expect: Vec<PathBuf> = vec![
PathBuf::from("host/elsa/2019-12-02T11:59:15Z"),
PathBuf::from("host/elsa/2019-12-03T11:59:15Z"),
PathBuf::from("host/elsa/2019-12-04T11:59:15Z"),
];
assert_eq!(remove_list, expect);
// keep-weekly + keep-monthly + keep-yearly
let list = orig_list.clone();
let remove_list = get_prune_list(list, None, None, Some(5), Some(6), Some(7));
// all backup are within one week, so we only keep a single file
let expect: Vec<PathBuf> = vec![
PathBuf::from("host/elsa/2019-12-02T11:59:15Z"),
PathBuf::from("host/elsa/2019-12-03T11:59:15Z"),