verify-job: move snapshot filter into function

preparatory steps for fixing #3459

Signed-off-by: Hannes Laimer <h.laimer@proxmox.com>
Reviewed-By: Dominik Csapak <d.csapak@proxmox.com>
Tested-By: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
Hannes Laimer 2021-06-22 09:56:18 +02:00 committed by Thomas Lamprecht
parent c7024b282a
commit 037e6c0ca8
2 changed files with 36 additions and 24 deletions

View File

@ -575,3 +575,30 @@ pub fn verify_all_backups(
Ok(errors) Ok(errors)
} }
/// Filter for the verification of snapshots
pub fn verify_filter(
ignore_verified_snapshots: bool,
outdated_after: Option<i64>,
manifest: &BackupManifest,
) -> bool {
if !ignore_verified_snapshots {
return true;
}
let raw_verify_state = manifest.unprotected["verify_state"].clone();
match serde_json::from_value::<SnapshotVerifyState>(raw_verify_state) {
Err(_) => true, // no last verification, always include
Ok(last_verify) => {
match outdated_after {
None => false, // never re-verify if ignored and no max age
Some(max_age) => {
let now = proxmox::tools::time::epoch_i64();
let days_since_last_verify = (now - last_verify.upid.starttime) / 86400;
days_since_last_verify > max_age
}
}
}
}
}

View File

@ -7,7 +7,7 @@ use crate::{
config::verify::VerificationJobConfig, config::verify::VerificationJobConfig,
backup::{ backup::{
DataStore, DataStore,
BackupManifest, verify_filter,
verify_all_backups, verify_all_backups,
}, },
task_log, task_log,
@ -26,28 +26,6 @@ pub fn do_verification_job(
let outdated_after = verification_job.outdated_after; let outdated_after = verification_job.outdated_after;
let ignore_verified_snapshots = verification_job.ignore_verified.unwrap_or(true); let ignore_verified_snapshots = verification_job.ignore_verified.unwrap_or(true);
let filter = move |manifest: &BackupManifest| {
if !ignore_verified_snapshots {
return true;
}
let raw_verify_state = manifest.unprotected["verify_state"].clone();
match serde_json::from_value::<SnapshotVerifyState>(raw_verify_state) {
Err(_) => true, // no last verification, always include
Ok(last_verify) => {
match outdated_after {
None => false, // never re-verify if ignored and no max age
Some(max_age) => {
let now = proxmox::tools::time::epoch_i64();
let days_since_last_verify = (now - last_verify.upid.starttime) / 86400;
days_since_last_verify > max_age
}
}
}
}
};
let (email, notify) = crate::server::lookup_datastore_notify_settings(&verification_job.store); let (email, notify) = crate::server::lookup_datastore_notify_settings(&verification_job.store);
let job_id = format!("{}:{}", let job_id = format!("{}:{}",
@ -68,7 +46,14 @@ pub fn do_verification_job(
} }
let verify_worker = crate::backup::VerifyWorker::new(worker.clone(), datastore); let verify_worker = crate::backup::VerifyWorker::new(worker.clone(), datastore);
let result = verify_all_backups(&verify_worker, worker.upid(), None, Some(&filter)); let result = verify_all_backups(
&verify_worker,
worker.upid(),
None,
Some(&move |manifest| {
verify_filter(ignore_verified_snapshots, outdated_after, manifest)
}),
);
let job_result = match result { let job_result = match result {
Ok(ref failed_dirs) if failed_dirs.is_empty() => Ok(()), Ok(ref failed_dirs) if failed_dirs.is_empty() => Ok(()),
Ok(ref failed_dirs) => { Ok(ref failed_dirs) => {