From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id D1DED611C2 for ; Tue, 20 Oct 2020 11:11:09 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id CAEC1C45B for ; Tue, 20 Oct 2020 11:10:39 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id A29AAC42E for ; Tue, 20 Oct 2020 11:10:38 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 6746E45E42 for ; Tue, 20 Oct 2020 11:10:38 +0200 (CEST) From: Hannes Laimer To: pbs-devel@lists.proxmox.com Date: Tue, 20 Oct 2020 11:10:06 +0200 Message-Id: <20201020091012.82723-5-h.laimer@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201020091012.82723-1-h.laimer@proxmox.com> References: <20201020091012.82723-1-h.laimer@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [proxmox-backup-proxy.rs] Subject: [pbs-devel] [PATCH v4 proxmox-backup 04/10] proxy: add scheduling for verification jobs X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 20 Oct 2020 09:11:09 -0000 Signed-off-by: Hannes Laimer --- src/bin/proxmox-backup-proxy.rs | 62 +++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/src/bin/proxmox-backup-proxy.rs b/src/bin/proxmox-backup-proxy.rs index c946c20c..398488fa 100644 --- a/src/bin/proxmox-backup-proxy.rs +++ b/src/bin/proxmox-backup-proxy.rs @@ -29,6 +29,7 @@ use proxmox_backup::tools::{ }; use proxmox_backup::api2::pull::do_sync_job; +use proxmox_backup::backup::do_verification_job; fn main() -> Result<(), Error> { proxmox_backup::tools::setup_safe_path_env(); @@ -213,6 +214,7 @@ async fn schedule_tasks() -> Result<(), Error> { schedule_datastore_prune().await; schedule_datastore_verification().await; schedule_datastore_sync_jobs().await; + schedule_datastore_verify_jobs().await; schedule_task_log_rotate().await; Ok(()) @@ -672,6 +674,66 @@ async fn schedule_datastore_sync_jobs() { } } +async fn schedule_datastore_verify_jobs() { + use proxmox_backup::{ + config::{verify::{self, VerificationJobConfig}, jobstate::{self, Job}}, + tools::systemd::time::{parse_calendar_event, compute_next_event}, + }; + let config = match verify::config() { + Err(err) => { + eprintln!("unable to read verification job config - {}", err); + return; + } + Ok((config, _digest)) => config, + }; + for (job_id, (_, job_config)) in config.sections { + let job_config: VerificationJobConfig = match serde_json::from_value(job_config) { + Ok(c) => c, + Err(err) => { + eprintln!("verification job config from_value failed - {}", err); + continue; + } + }; + let event_str = match job_config.schedule { + Some(ref event_str) => event_str.clone(), + None => continue, + }; + let event = match parse_calendar_event(&event_str) { + Ok(event) => event, + Err(err) => { + eprintln!("unable to parse schedule '{}' - {}", event_str, err); + continue; + } + }; + let worker_type = "verificationjob"; + let last = match jobstate::last_run_time(worker_type, &job_id) { + Ok(time) => time, + Err(err) => { + eprintln!("could not get last run time of {} {}: {}", worker_type, job_id, err); + continue; + } + }; + let next = match compute_next_event(&event, last, false) { + Ok(Some(next)) => next, + Ok(None) => continue, + Err(err) => { + eprintln!("compute_next_event for '{}' failed - {}", event_str, err); + continue; + } + }; + let now = proxmox::tools::time::epoch_i64(); + if next > now { continue; } + let job = match Job::new(worker_type, &job_id) { + Ok(job) => job, + Err(_) => continue, // could not get lock + }; + let userid = Userid::backup_userid().clone(); + if let Err(err) = do_verification_job(job, job_config, &userid, Some(event_str)) { + eprintln!("unable to start datastore verification job {} - {}", &job_id, err); + } + } +} + async fn schedule_task_log_rotate() { use proxmox_backup::{ config::jobstate::{self, Job}, -- 2.20.1