1 use anyhow
::{format_err, Error}
;
7 config
::verify
::VerificationJobConfig
,
16 /// Runs a verification job.
17 pub fn do_verification_job(
19 verification_job
: VerificationJobConfig
,
21 schedule
: Option
<String
>,
22 ) -> Result
<String
, Error
> {
24 let datastore
= DataStore
::lookup_datastore(&verification_job
.store
)?
;
26 let outdated_after
= verification_job
.outdated_after
.clone();
27 let ignore_verified_snapshots
= verification_job
.ignore_verified
.unwrap_or(true);
29 let filter
= move |manifest
: &BackupManifest
| {
30 if !ignore_verified_snapshots
{
34 let raw_verify_state
= manifest
.unprotected
["verify_state"].clone();
35 match serde_json
::from_value
::<SnapshotVerifyState
>(raw_verify_state
) {
36 Err(_
) => return true, // no last verification, always include
38 match outdated_after
{
39 None
=> false, // never re-verify if ignored and no max age
41 let now
= proxmox
::tools
::time
::epoch_i64();
42 let days_since_last_verify
= (now
- last_verify
.upid
.starttime
) / 86400;
44 days_since_last_verify
> max_age
51 let (email
, notify
) = crate::server
::lookup_datastore_notify_settings(&verification_job
.store
);
53 let job_id
= job
.jobname().to_string();
54 let worker_type
= job
.jobtype().to_string();
55 let upid_str
= WorkerTask
::new_thread(
57 Some(job
.jobname().to_string()),
61 job
.start(&worker
.upid().to_string())?
;
63 task_log
!(worker
,"Starting datastore verify job '{}'", job_id
);
64 if let Some(event_str
) = schedule
{
65 task_log
!(worker
,"task triggered by schedule '{}'", event_str
);
68 let result
= verify_all_backups(datastore
, worker
.clone(), worker
.upid(), None
, Some(&filter
));
69 let job_result
= match result
{
70 Ok(ref errors
) if errors
.is_empty() => Ok(()),
71 Ok(_
) => Err(format_err
!("verification failed - please check the log for details")),
72 Err(_
) => Err(format_err
!("verification failed - job aborted")),
75 let status
= worker
.create_state(&job_result
);
77 match job
.finish(status
) {
78 Err(err
) => eprintln
!(
79 "could not finish job state for {}: {}",
80 job
.jobtype().to_string(),
86 if let Some(email
) = email
{
87 if let Err(err
) = crate::server
::send_verify_status(&email
, notify
, verification_job
, &result
) {
88 eprintln
!("send verify notification failed: {}", err
);