update to current PBS master

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
This commit is contained in:
Fabian Grünbichler 2025-01-17 10:13:09 +01:00
parent 961846befc
commit 16298c5fa0
6 changed files with 47 additions and 30 deletions

View File

@ -33,7 +33,7 @@ openssl = "0.10"
proxmox-async = "0.4" proxmox-async = "0.4"
proxmox-lang = "1" proxmox-lang = "1"
proxmox-schema = { version = "3", features = [ "api-macro" ] } proxmox-schema = { version = "4", features = [ "api-macro" ] }
proxmox-sortable-macro = "0.1.2" proxmox-sortable-macro = "0.1.2"
proxmox-sys = "0.6" proxmox-sys = "0.6"

12
debian/control vendored
View File

@ -50,19 +50,23 @@ Build-Depends: cargo:native,
librust-proxmox-io-1+default-dev (>= 1.0.1-~~), librust-proxmox-io-1+default-dev (>= 1.0.1-~~),
librust-proxmox-io-1+tokio-dev (>= 1.0.1-~~), librust-proxmox-io-1+tokio-dev (>= 1.0.1-~~),
librust-proxmox-lang-1+default-dev (>= 1.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+cli-dev,
librust-proxmox-router-3+server-dev, librust-proxmox-router-3+server-dev,
librust-proxmox-schema-3+api-macro-dev, librust-proxmox-schema-4+api-macro-dev,
librust-proxmox-schema-3+default-dev, librust-proxmox-schema-4+default-dev,
librust-proxmox-serde-0.1+default-dev (>= 0.1.1-~~), librust-proxmox-serde-0.1+default-dev (>= 0.1.1-~~),
librust-proxmox-serde-0.1+serde-json-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-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-time-2+default-dev,
librust-proxmox-uuid-1+default-dev, librust-proxmox-uuid-1+default-dev,
librust-proxmox-uuid-1+serde-dev, librust-proxmox-uuid-1+serde-dev,
librust-proxmox-worker-task-0.1+default-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-regex-1+default-dev (>= 1.5.5-~~),
librust-rustyline-9+default-dev, librust-rustyline-9+default-dev,
librust-serde-1+default-dev, librust-serde-1+default-dev,

View File

@ -234,10 +234,16 @@ impl BackupTask {
pub fn check_incremental(&self, device_name: String, size: u64) -> bool { pub fn check_incremental(&self, device_name: String, size: u64) -> bool {
match self.last_manifest() { match self.last_manifest() {
Some(ref 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( && check_last_encryption_mode(
Arc::clone(manifest), Arc::clone(manifest),
&device_name, &archive_name,
self.crypt_mode, self.crypt_mode,
) )
&& check_last_encryption_key(self.crypt_config.clone()) && check_last_encryption_key(self.crypt_config.clone())

View File

@ -6,11 +6,11 @@ use std::sync::{Arc, Mutex};
use futures::future::{Future, TryFutureExt}; use futures::future::{Future, TryFutureExt};
use serde_json::json; 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_client::{BackupWriter, H2Client, UploadOptions};
use pbs_datastore::data_blob::DataChunkBuilder; use pbs_datastore::data_blob::DataChunkBuilder;
use pbs_datastore::index::IndexFile; 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 pbs_tools::crypt_config::CryptConfig;
use crate::capi_types::DataPointer; use crate::capi_types::DataPointer;
@ -112,15 +112,16 @@ pub(crate) async fn add_config(
let stats = client let stats = client
.upload_blob_from_data(data, &blob_name, options) .upload_blob_from_data(data, &blob_name, options)
.await?; .await?;
let blob_name: BackupArchiveName = blob_name.parse()?;
let mut guard = manifest.lock().unwrap(); 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) Ok(0)
} }
fn archive_name(device_name: &str) -> String { pub(crate) fn archive_name(device_name: &str) -> Result<BackupArchiveName, Error> {
format!("{}.img.fidx", device_name) format!("{}.img.fidx", device_name).parse()
} }
const CRYPT_CONFIG_HASH_INPUT: &[u8] = const CRYPT_CONFIG_HASH_INPUT: &[u8] =
@ -135,12 +136,13 @@ pub(crate) fn crypt_config_digest(config: Arc<CryptConfig>) -> [u8; 32] {
pub(crate) fn check_last_incremental_csum( pub(crate) fn check_last_incremental_csum(
manifest: Arc<BackupManifest>, manifest: Arc<BackupManifest>,
archive_name: &BackupArchiveName,
device_name: &str, device_name: &str,
device_size: u64, device_size: u64,
) -> bool { ) -> bool {
match PREVIOUS_CSUMS.lock().unwrap().get(device_name) { match PREVIOUS_CSUMS.lock().unwrap().get(device_name) {
Some(csum) => manifest Some(csum) => manifest
.verify_file(&archive_name(device_name), csum, device_size) .verify_file(archive_name, csum, device_size)
.is_ok(), .is_ok(),
None => false, None => false,
} }
@ -148,10 +150,10 @@ pub(crate) fn check_last_incremental_csum(
pub(crate) fn check_last_encryption_mode( pub(crate) fn check_last_encryption_mode(
manifest: Arc<BackupManifest>, manifest: Arc<BackupManifest>,
device_name: &str, archive_name: &BackupArchiveName,
crypt_mode: CryptMode, crypt_mode: CryptMode,
) -> bool { ) -> 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) { Ok(file) => match (file.crypt_mode, crypt_mode) {
(CryptMode::Encrypt, CryptMode::Encrypt) => true, (CryptMode::Encrypt, CryptMode::Encrypt) => true,
(CryptMode::Encrypt, _) => false, (CryptMode::Encrypt, _) => false,
@ -189,7 +191,7 @@ pub(crate) async fn register_image(
chunk_size: u64, chunk_size: u64,
incremental: bool, incremental: bool,
) -> Result<c_int, Error> { ) -> Result<c_int, Error> {
let archive_name = archive_name(&device_name); let archive_name: BackupArchiveName = archive_name(&device_name)?;
let index = match manifest { let index = match manifest {
Some(manifest) => { Some(manifest) => {
@ -326,7 +328,7 @@ pub(crate) async fn close_image(
let mut guard = manifest.lock().unwrap(); let mut guard = manifest.lock().unwrap();
guard.add_file( guard.add_file(
format!("{}.img.fidx", device_name), &archive_name(&device_name)?,
device_size, device_size,
upload_result.csum, upload_result.csum,
crypt_mode, crypt_mode,
@ -475,21 +477,19 @@ pub(crate) async fn finish_backup(
manifest: Arc<Mutex<BackupManifest>>, manifest: Arc<Mutex<BackupManifest>>,
) -> Result<c_int, Error> { ) -> Result<c_int, Error> {
if let Some(rsa_encrypted_key) = rsa_encrypted_key { if let Some(rsa_encrypted_key) = rsa_encrypted_key {
let target = ENCRYPTED_KEY_BLOB_NAME; let target = &ENCRYPTED_KEY_BLOB_NAME;
let options = UploadOptions { let options = UploadOptions {
compress: false, compress: false,
encrypt: false, encrypt: false,
..UploadOptions::default() ..UploadOptions::default()
}; };
let stats = client let stats = client
.upload_blob_from_data(rsa_encrypted_key, target, options) .upload_blob_from_data(rsa_encrypted_key, &target.to_string(), options)
.await?; .await?;
manifest.lock().unwrap().add_file( manifest
target.to_string(), .lock()
stats.size, .unwrap()
stats.csum, .add_file(target, stats.size, stats.csum, CryptMode::Encrypt)?;
CryptMode::Encrypt,
)?;
}; };
let manifest = { let manifest = {
@ -518,7 +518,11 @@ pub(crate) async fn finish_backup(
}; };
client 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?; .await?;
client.finish().await?; client.finish().await?;

View File

@ -19,6 +19,7 @@ use pbs_tools::crypt_config::CryptConfig;
use super::BackupSetup; use super::BackupSetup;
use crate::capi_types::DataPointer; use crate::capi_types::DataPointer;
use crate::commands::archive_name;
use crate::registry::Registry; use crate::registry::Registry;
use crate::shared_cache::get_shared_chunk_cache; use crate::shared_cache::get_shared_chunk_cache;
@ -118,11 +119,12 @@ impl RestoreTask {
pub async fn restore_image( pub async fn restore_image(
&self, &self,
archive_name: String, archive_str: String,
write_data_callback: impl Fn(u64, &[u8]) -> i32, write_data_callback: impl Fn(u64, &[u8]) -> i32,
write_zero_callback: impl Fn(u64, u64) -> i32, write_zero_callback: impl Fn(u64, u64) -> i32,
verbose: bool, verbose: bool,
) -> Result<(), Error> { ) -> Result<(), Error> {
let archive_name = archive_name(&archive_str)?;
if verbose { if verbose {
eprintln!("download and verify backup index"); eprintln!("download and verify backup index");
} }
@ -216,7 +218,8 @@ impl RestoreTask {
Ok(info.archive_size) Ok(info.archive_size)
} }
pub async fn open_image(&self, archive_name: String) -> Result<u8, Error> { pub async fn open_image(&self, archive_str: String) -> Result<u8, Error> {
let archive_name = archive_name(&archive_str)?;
let client = match self.client.get() { let client = match self.client.get() {
Some(reader) => Arc::clone(reader), Some(reader) => Arc::clone(reader),
None => bail!("not connected"), None => bail!("not connected"),
@ -251,7 +254,7 @@ impl RestoreTask {
let info = ImageAccessInfo { let info = ImageAccessInfo {
archive_size, archive_size,
_archive_name: archive_name, _archive_name: archive_str,
// useful to debug // useful to debug
reader, reader,
}; };

@ -1 +1 @@
Subproject commit adbf59dd17515f1a14b2b5828cee31704bf122cf Subproject commit de875c0f0e358b3bd46b4d0e3c0aa75af7c9e887