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 AAF2E6B663 for ; Wed, 4 Aug 2021 10:10:54 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id A89341C321 for ; Wed, 4 Aug 2021 10:10:54 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (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 firstgate.proxmox.com (Proxmox) with ESMTPS id D57FA1C30D for ; Wed, 4 Aug 2021 10:10:53 +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 ADEBB42DA0; Wed, 4 Aug 2021 10:10:53 +0200 (CEST) From: Dietmar Maurer To: pbs-devel@lists.proxmox.com Date: Wed, 4 Aug 2021 10:10:48 +0200 Message-Id: <20210804081050.497395-2-dietmar@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210804081050.497395-1-dietmar@proxmox.com> References: <20210804081050.497395-1-dietmar@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.693 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment 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. [backup.rs, job.id] URIBL_SBL_A 0.1 Contains URL's A record listed in the Spamhaus SBL blocklist [job.id] Subject: [pbs-devel] [PATCH proxmox-backup 2/4] tape: compute next-media-label for each tape backup job 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: Wed, 04 Aug 2021 08:10:54 -0000 --- src/api2/tape/backup.rs | 28 +++++++++++++++++++++++++--- src/config/tape_job.rs | 3 +++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/api2/tape/backup.rs b/src/api2/tape/backup.rs index 8119482f..9f815cad 100644 --- a/src/api2/tape/backup.rs +++ b/src/api2/tape/backup.rs @@ -126,9 +126,11 @@ pub fn list_tape_backup_jobs( let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?; let user_info = CachedUserInfo::new()?; - let (config, digest) = config::tape_job::config()?; + let (job_config, digest) = config::tape_job::config()?; + let (pool_config, _pool_digest) = config::media_pool::config()?; + let (drive_config, _digest) = config::drive::config()?; - let job_list_iter = config + let job_list_iter = job_config .convert_to_typed_array("backup")? .into_iter() .filter(|_job: &TapeBackupJobConfig| { @@ -137,6 +139,8 @@ pub fn list_tape_backup_jobs( }); let mut list = Vec::new(); + let status_path = Path::new(TAPE_STATUS_DIR); + let current_time = proxmox::tools::time::epoch_i64(); for job in job_list_iter { let privs = user_info.lookup_privs(&auth_id, &["tape", "job", &job.id]); @@ -149,7 +153,25 @@ pub fn list_tape_backup_jobs( let status = compute_schedule_status(&last_state, job.schedule.as_deref())?; - list.push(TapeBackupJobStatus { config: job, status }); + let next_run = status.next_run.unwrap_or(current_time); + + let mut next_media_label = None; + + if let Ok(pool) = pool_config.lookup::("pool", &job.setup.pool) { + let mut changer_name = None; + if let Ok(Some((_, name))) = media_changer(&drive_config, &job.setup.drive) { + changer_name = Some(name); + } + if let Ok(mut pool) = MediaPool::with_config(status_path, &pool, changer_name, true) { + if pool.start_write_session(next_run, false).is_ok() { + if let Ok(media_id) = pool.guess_next_writable_media(next_run) { + next_media_label = Some(media_id.label.label_text); + } + } + } + } + + list.push(TapeBackupJobStatus { config: job, status, next_media_label }); } rpcenv["digest"] = proxmox::tools::digest_to_hex(&digest).into(); diff --git a/src/config/tape_job.rs b/src/config/tape_job.rs index f09200fc..3c265b93 100644 --- a/src/config/tape_job.rs +++ b/src/config/tape_job.rs @@ -127,6 +127,9 @@ pub struct TapeBackupJobStatus { pub config: TapeBackupJobConfig, #[serde(flatten)] pub status: JobScheduleStatus, + /// Next tape used (best guess) + #[serde(skip_serializing_if="Option::is_none")] + pub next_media_label: Option, } fn init() -> SectionConfig { -- 2.30.2