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 1467C61999 for ; Fri, 20 Nov 2020 17:40:05 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 1260D15229 for ; Fri, 20 Nov 2020 17:40:05 +0100 (CET) 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)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 792B61521F for ; Fri, 20 Nov 2020 17:40:04 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 4265143D48 for ; Fri, 20 Nov 2020 17:40:04 +0100 (CET) From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= To: pbs-devel@lists.proxmox.com Date: Fri, 20 Nov 2020 17:38:40 +0100 Message-Id: <20201120163845.1225080-11-f.gruenbichler@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201120163845.1225080-1-f.gruenbichler@proxmox.com> References: <20201120163845.1225080-1-f.gruenbichler@proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.025 Adjusted score from AWL reputation of From: address 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-client.rs, backup.rs] Subject: [pbs-devel] [RFC proxmox-backup 10/13] expose previous backup time in backup env 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: Fri, 20 Nov 2020 16:40:05 -0000 and use this information to add more information to client backup log and guide the download manifest decision. Signed-off-by: Fabian Grünbichler --- Notes: new in v2 backwards-compatible API change! src/api2/backup.rs | 26 ++++++++++++++++ src/bin/proxmox-backup-client.rs | 51 ++++++++++++++++++++++---------- src/client/backup_writer.rs | 7 +++++ 3 files changed, 68 insertions(+), 16 deletions(-) diff --git a/src/api2/backup.rs b/src/api2/backup.rs index ce9a34ae..f4eed074 100644 --- a/src/api2/backup.rs +++ b/src/api2/backup.rs @@ -311,6 +311,10 @@ pub const BACKUP_API_SUBDIRS: SubdirMap = &[ "previous", &Router::new() .download(&API_METHOD_DOWNLOAD_PREVIOUS) ), + ( + "previous_backup_time", &Router::new() + .get(&API_METHOD_GET_PREVIOUS_BACKUP_TIME) + ), ( "speedtest", &Router::new() .upload(&API_METHOD_UPLOAD_SPEEDTEST) @@ -694,6 +698,28 @@ fn finish_backup ( Ok(Value::Null) } +#[sortable] +pub const API_METHOD_GET_PREVIOUS_BACKUP_TIME: ApiMethod = ApiMethod::new( + &ApiHandler::Sync(&get_previous_backup_time), + &ObjectSchema::new( + "Get previous backup time.", + &[], + ) +); + +fn get_previous_backup_time( + _param: Value, + _info: &ApiMethod, + rpcenv: &mut dyn RpcEnvironment, +) -> Result { + + let env: &BackupEnvironment = rpcenv.as_ref(); + + let backup_time = env.last_backup.as_ref().map(|info| info.backup_dir.backup_time()); + + Ok(json!(backup_time)) +} + #[sortable] pub const API_METHOD_DOWNLOAD_PREVIOUS: ApiMethod = ApiMethod::new( &ApiHandler::AsyncHttp(&download_previous), diff --git a/src/bin/proxmox-backup-client.rs b/src/bin/proxmox-backup-client.rs index b4f87071..3e9931b8 100644 --- a/src/bin/proxmox-backup-client.rs +++ b/src/bin/proxmox-backup-client.rs @@ -1100,23 +1100,42 @@ async fn create_backup( false ).await?; - let previous_manifest = match client.download_previous_manifest().await { - Ok(previous_manifest) => { - match previous_manifest.check_fingerprint(crypt_config.as_ref().map(Arc::as_ref)) { - Ok(()) => { - println!("Successfully downloaded previous manifest."); - Some(Arc::new(previous_manifest)) - }, - Err(err) => { - println!("Couldn't re-use pevious manifest - {}", err); - None - }, + let download_previous_manifest = match client.previous_backup_time().await { + Ok(Some(backup_time)) => { + println!( + "Downloading previous manifest ({})", + strftime_local("%c", backup_time)? + ); + true + } + Ok(None) => { + println!("No previous manifest available."); + false + } + Err(_) => { + // Fallback for outdated server, TODO remove/bubble up with 2.0 + true + } + }; + + let previous_manifest = if download_previous_manifest { + match client.download_previous_manifest().await { + Ok(previous_manifest) => { + match previous_manifest.check_fingerprint(crypt_config.as_ref().map(Arc::as_ref)) { + Ok(()) => Some(Arc::new(previous_manifest)), + Err(err) => { + println!("Couldn't re-use previous manifest - {}", err); + None + } + } } - }, - Err(err) => { - println!("Couldn't download pevious manifest - {}", err); - None - }, + Err(err) => { + println!("Couldn't download previous manifest - {}", err); + None + } + } + } else { + None }; let snapshot = BackupDir::new(backup_type, backup_id, backup_time)?; diff --git a/src/client/backup_writer.rs b/src/client/backup_writer.rs index c5ce5b42..39cd574d 100644 --- a/src/client/backup_writer.rs +++ b/src/client/backup_writer.rs @@ -475,6 +475,13 @@ impl BackupWriter { Ok(index) } + /// Retrieve backup time of last backup + pub async fn previous_backup_time(&self) -> Result, Error> { + let data = self.h2.get("previous_backup_time", None).await?; + serde_json::from_value(data) + .map_err(|err| format_err!("Failed to parse backup time value returned by server - {}", err)) + } + /// Download backup manifest (index.json) of last backup pub async fn download_previous_manifest(&self) -> Result { -- 2.20.1