From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <pbs-devel-bounces@lists.proxmox.com> Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 5DF1B1FF170 for <inbox@lore.proxmox.com>; Thu, 29 May 2025 16:32:35 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id B785C15D85; Thu, 29 May 2025 16:32:36 +0200 (CEST) From: Christian Ebner <c.ebner@proxmox.com> To: pbs-devel@lists.proxmox.com Date: Thu, 29 May 2025 16:31:48 +0200 Message-Id: <20250529143207.694497-24-c.ebner@proxmox.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250529143207.694497-1-c.ebner@proxmox.com> References: <20250529143207.694497-1-c.ebner@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.033 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy 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 Subject: [pbs-devel] [RFC v2 proxmox-backup 23/42] sync: pull: conditionally upload content to S3 backend X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion <pbs-devel.lists.proxmox.com> List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pbs-devel>, <mailto:pbs-devel-request@lists.proxmox.com?subject=unsubscribe> List-Archive: <http://lists.proxmox.com/pipermail/pbs-devel/> List-Post: <mailto:pbs-devel@lists.proxmox.com> List-Help: <mailto:pbs-devel-request@lists.proxmox.com?subject=help> List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel>, <mailto:pbs-devel-request@lists.proxmox.com?subject=subscribe> Reply-To: Proxmox Backup Server development discussion <pbs-devel@lists.proxmox.com> Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pbs-devel-bounces@lists.proxmox.com Sender: "pbs-devel" <pbs-devel-bounces@lists.proxmox.com> If the datastore is backed by an S3 object store, not only insert the pulled contents to the local cache store, but also upload it to the S3 backend. Signed-off-by: Christian Ebner <c.ebner@proxmox.com> --- src/server/pull.rs | 58 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 2 deletions(-) diff --git a/src/server/pull.rs b/src/server/pull.rs index b1724c142..f36efd7c8 100644 --- a/src/server/pull.rs +++ b/src/server/pull.rs @@ -8,6 +8,7 @@ use std::time::SystemTime; use anyhow::{bail, format_err, Error}; use proxmox_human_byte::HumanByte; +use tokio::io::AsyncReadExt; use tracing::info; use pbs_api_types::{ @@ -24,7 +25,7 @@ use pbs_datastore::fixed_index::FixedIndexReader; use pbs_datastore::index::IndexFile; use pbs_datastore::manifest::{BackupManifest, FileInfo}; use pbs_datastore::read_chunk::AsyncReadChunk; -use pbs_datastore::{check_backup_owner, DataStore, StoreProgress}; +use pbs_datastore::{check_backup_owner, DataStore, DatastoreBackend, StoreProgress}; use pbs_tools::sha::sha256; use super::sync::{ @@ -167,7 +168,18 @@ async fn pull_index_chunks<I: IndexFile>( move |(chunk, digest, size): (DataBlob, [u8; 32], u64)| { // println!("verify and write {}", hex::encode(&digest)); chunk.verify_unencrypted(size as usize, &digest)?; - target2.insert_chunk(&chunk, &digest)?; + match target2.backend()? { + DatastoreBackend::Filesystem => { + target2.insert_chunk(&chunk, &digest)?; + } + DatastoreBackend::S3(s3_client) => { + let data = chunk.raw_data().to_vec(); + let upload_body = hyper::Body::from(data); + proxmox_async::runtime::block_on( + s3_client.put_object(digest.into(), upload_body), + )?; + } + } Ok(()) }, ); @@ -331,6 +343,20 @@ async fn pull_single_archive<'a>( if let Err(err) = std::fs::rename(&tmp_path, &path) { bail!("Atomic rename file {:?} failed - {}", path, err); } + if let DatastoreBackend::S3(s3_client) = snapshot.datastore().backend()? { + let archive_path = snapshot.relative_path().join(archive_name); + let object_key = archive_path + .as_os_str() + .to_str() + .ok_or_else(|| format_err!("invalid archive path"))?; + + let archive = tokio::fs::File::open(&path).await?; + let mut reader = tokio::io::BufReader::new(archive); + let mut contents = Vec::new(); + reader.read_to_end(&mut contents).await?; + let data = hyper::body::Body::from(contents); + s3_client.put_object(object_key.into(), data).await?; + } Ok(sync_stats) } @@ -401,6 +427,7 @@ async fn pull_snapshot<'a>( } } + let manifest_data = tmp_manifest_blob.raw_data().to_vec(); let manifest = BackupManifest::try_from(tmp_manifest_blob)?; if ignore_not_verified_or_encrypted( @@ -467,9 +494,36 @@ async fn pull_snapshot<'a>( if let Err(err) = std::fs::rename(&tmp_manifest_name, &manifest_name) { bail!("Atomic rename file {:?} failed - {}", manifest_name, err); } + if let DatastoreBackend::S3(s3_client) = snapshot.datastore().backend()? { + let object_path = snapshot.relative_path().join(MANIFEST_BLOB_NAME.as_ref()); + let object_key = object_path + .as_os_str() + .to_str() + .ok_or_else(|| format_err!("invalid archive path"))?; + + let data = hyper::body::Body::from(manifest_data); + s3_client.put_object(object_key.into(), data).await?; + } if !client_log_name.exists() { reader.try_download_client_log(&client_log_name).await?; + if client_log_name.exists() { + if let DatastoreBackend::S3(s3_client) = snapshot.datastore().backend()? { + let object_path = snapshot.relative_path().join(CLIENT_LOG_BLOB_NAME.as_ref()); + let object_key = object_path + .as_os_str() + .to_str() + .ok_or_else(|| format_err!("invalid archive path"))?; + + let log_file = tokio::fs::File::open(&client_log_name).await?; + let mut reader = tokio::io::BufReader::new(log_file); + let mut contents = Vec::new(); + reader.read_to_end(&mut contents).await?; + + let data = hyper::body::Body::from(contents); + s3_client.put_object(object_key.into(), data).await?; + } + } }; snapshot .cleanup_unreferenced_files(&manifest) -- 2.39.5 _______________________________________________ pbs-devel mailing list pbs-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel