From 16298c5fa0d7af81ab14e2f18c7870c66d1d1eee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= Date: Fri, 17 Jan 2025 10:13:09 +0100 Subject: [PATCH] update to current PBS master MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fabian Grünbichler --- Cargo.toml | 2 +- debian/control | 12 +++++++---- src/backup.rs | 10 ++++++++-- src/commands.rs | 42 +++++++++++++++++++++------------------ src/restore.rs | 9 ++++++--- submodules/proxmox-backup | 2 +- 6 files changed, 47 insertions(+), 30 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index be9b261..b24c5eb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,7 +33,7 @@ openssl = "0.10" proxmox-async = "0.4" proxmox-lang = "1" -proxmox-schema = { version = "3", features = [ "api-macro" ] } +proxmox-schema = { version = "4", features = [ "api-macro" ] } proxmox-sortable-macro = "0.1.2" proxmox-sys = "0.6" diff --git a/debian/control b/debian/control index 41c7926..12113e2 100644 --- a/debian/control +++ b/debian/control @@ -50,19 +50,23 @@ Build-Depends: cargo:native, librust-proxmox-io-1+default-dev (>= 1.0.1-~~), librust-proxmox-io-1+tokio-dev (>= 1.0.1-~~), librust-proxmox-lang-1+default-dev (>= 1.1-~~), + librust-proxmox-log-0.2+default-dev (>= 0.2.6-~~), + librust-proxmox-notify-0.5+default-dev (>= 0.5.1-~~), + librust-proxmox-notify-0.5+pbs-context-dev (>= 0.5.1-~~), librust-proxmox-router-3+cli-dev, librust-proxmox-router-3+server-dev, - librust-proxmox-schema-3+api-macro-dev, - librust-proxmox-schema-3+default-dev, + librust-proxmox-schema-4+api-macro-dev, + librust-proxmox-schema-4+default-dev, librust-proxmox-serde-0.1+default-dev (>= 0.1.1-~~), librust-proxmox-serde-0.1+serde-json-dev (>= 0.1.1-~~), + librust-proxmox-shared-memory-0.3+default-dev, librust-proxmox-sortable-macro-0.1+default-dev (>= 0.1.2-~~), - librust-proxmox-sys-0.6+default-dev, + librust-proxmox-sys-0.6+default-dev (>= 0.6.5-~~), librust-proxmox-time-2+default-dev, librust-proxmox-uuid-1+default-dev, librust-proxmox-uuid-1+serde-dev, librust-proxmox-worker-task-0.1+default-dev, - librust-pxar-0.12+default-dev, + librust-pxar-0.12+default-dev (>= 0.12.1-~~), librust-regex-1+default-dev (>= 1.5.5-~~), librust-rustyline-9+default-dev, librust-serde-1+default-dev, diff --git a/src/backup.rs b/src/backup.rs index 1c491de..32037ce 100644 --- a/src/backup.rs +++ b/src/backup.rs @@ -234,10 +234,16 @@ impl BackupTask { pub fn check_incremental(&self, device_name: String, size: u64) -> bool { match self.last_manifest() { Some(ref manifest) => { - check_last_incremental_csum(Arc::clone(manifest), &device_name, size) + let archive_name = if let Ok(archive) = archive_name(&device_name) { + archive + } else { + return false; + }; + + check_last_incremental_csum(Arc::clone(manifest), &archive_name, &device_name, size) && check_last_encryption_mode( Arc::clone(manifest), - &device_name, + &archive_name, self.crypt_mode, ) && check_last_encryption_key(self.crypt_config.clone()) diff --git a/src/commands.rs b/src/commands.rs index ba1832f..bf1b872 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -6,11 +6,11 @@ use std::sync::{Arc, Mutex}; use futures::future::{Future, TryFutureExt}; use serde_json::json; -use pbs_api_types::CryptMode; +use pbs_api_types::{BackupArchiveName, CryptMode, ENCRYPTED_KEY_BLOB_NAME, MANIFEST_BLOB_NAME}; use pbs_client::{BackupWriter, H2Client, UploadOptions}; use pbs_datastore::data_blob::DataChunkBuilder; use pbs_datastore::index::IndexFile; -use pbs_datastore::manifest::{BackupManifest, ENCRYPTED_KEY_BLOB_NAME, MANIFEST_BLOB_NAME}; +use pbs_datastore::manifest::BackupManifest; use pbs_tools::crypt_config::CryptConfig; use crate::capi_types::DataPointer; @@ -112,15 +112,16 @@ pub(crate) async fn add_config( let stats = client .upload_blob_from_data(data, &blob_name, options) .await?; + let blob_name: BackupArchiveName = blob_name.parse()?; let mut guard = manifest.lock().unwrap(); - guard.add_file(blob_name, stats.size, stats.csum, crypt_mode)?; + guard.add_file(&blob_name, stats.size, stats.csum, crypt_mode)?; Ok(0) } -fn archive_name(device_name: &str) -> String { - format!("{}.img.fidx", device_name) +pub(crate) fn archive_name(device_name: &str) -> Result { + format!("{}.img.fidx", device_name).parse() } const CRYPT_CONFIG_HASH_INPUT: &[u8] = @@ -135,12 +136,13 @@ pub(crate) fn crypt_config_digest(config: Arc) -> [u8; 32] { pub(crate) fn check_last_incremental_csum( manifest: Arc, + archive_name: &BackupArchiveName, device_name: &str, device_size: u64, ) -> bool { match PREVIOUS_CSUMS.lock().unwrap().get(device_name) { Some(csum) => manifest - .verify_file(&archive_name(device_name), csum, device_size) + .verify_file(archive_name, csum, device_size) .is_ok(), None => false, } @@ -148,10 +150,10 @@ pub(crate) fn check_last_incremental_csum( pub(crate) fn check_last_encryption_mode( manifest: Arc, - device_name: &str, + archive_name: &BackupArchiveName, crypt_mode: CryptMode, ) -> bool { - match manifest.lookup_file_info(&archive_name(device_name)) { + match manifest.lookup_file_info(archive_name) { Ok(file) => match (file.crypt_mode, crypt_mode) { (CryptMode::Encrypt, CryptMode::Encrypt) => true, (CryptMode::Encrypt, _) => false, @@ -189,7 +191,7 @@ pub(crate) async fn register_image( chunk_size: u64, incremental: bool, ) -> Result { - let archive_name = archive_name(&device_name); + let archive_name: BackupArchiveName = archive_name(&device_name)?; let index = match manifest { Some(manifest) => { @@ -326,7 +328,7 @@ pub(crate) async fn close_image( let mut guard = manifest.lock().unwrap(); guard.add_file( - format!("{}.img.fidx", device_name), + &archive_name(&device_name)?, device_size, upload_result.csum, crypt_mode, @@ -475,21 +477,19 @@ pub(crate) async fn finish_backup( manifest: Arc>, ) -> Result { if let Some(rsa_encrypted_key) = rsa_encrypted_key { - let target = ENCRYPTED_KEY_BLOB_NAME; + let target = &ENCRYPTED_KEY_BLOB_NAME; let options = UploadOptions { compress: false, encrypt: false, ..UploadOptions::default() }; let stats = client - .upload_blob_from_data(rsa_encrypted_key, target, options) + .upload_blob_from_data(rsa_encrypted_key, &target.to_string(), options) .await?; - manifest.lock().unwrap().add_file( - target.to_string(), - stats.size, - stats.csum, - CryptMode::Encrypt, - )?; + manifest + .lock() + .unwrap() + .add_file(target, stats.size, stats.csum, CryptMode::Encrypt)?; }; let manifest = { @@ -518,7 +518,11 @@ pub(crate) async fn finish_backup( }; client - .upload_blob_from_data(manifest.into_bytes(), MANIFEST_BLOB_NAME, options) + .upload_blob_from_data( + manifest.into_bytes(), + &MANIFEST_BLOB_NAME.to_string(), + options, + ) .await?; client.finish().await?; diff --git a/src/restore.rs b/src/restore.rs index 0381309..d3818e9 100644 --- a/src/restore.rs +++ b/src/restore.rs @@ -19,6 +19,7 @@ use pbs_tools::crypt_config::CryptConfig; use super::BackupSetup; use crate::capi_types::DataPointer; +use crate::commands::archive_name; use crate::registry::Registry; use crate::shared_cache::get_shared_chunk_cache; @@ -118,11 +119,12 @@ impl RestoreTask { pub async fn restore_image( &self, - archive_name: String, + archive_str: String, write_data_callback: impl Fn(u64, &[u8]) -> i32, write_zero_callback: impl Fn(u64, u64) -> i32, verbose: bool, ) -> Result<(), Error> { + let archive_name = archive_name(&archive_str)?; if verbose { eprintln!("download and verify backup index"); } @@ -216,7 +218,8 @@ impl RestoreTask { Ok(info.archive_size) } - pub async fn open_image(&self, archive_name: String) -> Result { + pub async fn open_image(&self, archive_str: String) -> Result { + let archive_name = archive_name(&archive_str)?; let client = match self.client.get() { Some(reader) => Arc::clone(reader), None => bail!("not connected"), @@ -251,7 +254,7 @@ impl RestoreTask { let info = ImageAccessInfo { archive_size, - _archive_name: archive_name, + _archive_name: archive_str, // useful to debug reader, }; diff --git a/submodules/proxmox-backup b/submodules/proxmox-backup index adbf59d..de875c0 160000 --- a/submodules/proxmox-backup +++ b/submodules/proxmox-backup @@ -1 +1 @@ -Subproject commit adbf59dd17515f1a14b2b5828cee31704bf122cf +Subproject commit de875c0f0e358b3bd46b4d0e3c0aa75af7c9e887