public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Gabriel Goller <g.goller@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup 2/3] client: unify parameters and write to file
Date: Wed,  6 Mar 2024 15:34:12 +0100	[thread overview]
Message-ID: <20240306143422.114335-3-g.goller@proxmox.com> (raw)
In-Reply-To: <20240306143422.114335-1-g.goller@proxmox.com>

Merge all the existing parameters of `create_backup` to the
`serde_json::Value` parameter. Now only a single variable needs to be
written to the `.pxar_creation_params` file.
Pass the parameters down and encode it into the pxar archive.

Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
---
 pbs-client/src/pxar/create.rs                 |  9 ++++++
 pbs-client/src/pxar_backup_stream.rs          |  5 +++-
 proxmox-backup-client/src/main.rs             | 29 ++++++++++++-------
 .../src/proxmox_restore_daemon/api.rs         |  2 +-
 pxar-bin/src/main.rs                          |  1 +
 tests/catar.rs                                |  1 +
 6 files changed, 35 insertions(+), 12 deletions(-)

diff --git a/pbs-client/src/pxar/create.rs b/pbs-client/src/pxar/create.rs
index 0d5e8b68..437bf05b 100644
--- a/pbs-client/src/pxar/create.rs
+++ b/pbs-client/src/pxar/create.rs
@@ -142,6 +142,7 @@ pub async fn create_archive<T, F>(
     callback: F,
     catalog: Option<Arc<Mutex<dyn BackupCatalogWriter + Send>>>,
     options: PxarCreateOptions,
+    creation_command: String,
 ) -> Result<(), Error>
 where
     T: SeqWrite + Send,
@@ -199,6 +200,14 @@ where
         skip_e2big_xattr: options.skip_e2big_xattr,
     };
 
+    archiver
+        .encode_file(
+            &mut encoder,
+            &CString::new(".pxar_creation_params").unwrap(),
+            creation_command.as_bytes(),
+        )
+        .await
+        .unwrap();
     archiver
         .archive_dir_contents(&mut encoder, source_dir, true)
         .await?;
diff --git a/pbs-client/src/pxar_backup_stream.rs b/pbs-client/src/pxar_backup_stream.rs
index 22a6ffdc..52ed8f3c 100644
--- a/pbs-client/src/pxar_backup_stream.rs
+++ b/pbs-client/src/pxar_backup_stream.rs
@@ -40,6 +40,7 @@ impl PxarBackupStream {
         dir: Dir,
         catalog: Arc<Mutex<CatalogWriter<W>>>,
         options: crate::pxar::PxarCreateOptions,
+        creation_command: String,
     ) -> Result<Self, Error> {
         let (tx, rx) = std::sync::mpsc::sync_channel(10);
 
@@ -64,6 +65,7 @@ impl PxarBackupStream {
                 },
                 Some(catalog),
                 options,
+                creation_command,
             )
             .await
             {
@@ -87,10 +89,11 @@ impl PxarBackupStream {
         dirname: &Path,
         catalog: Arc<Mutex<CatalogWriter<W>>>,
         options: crate::pxar::PxarCreateOptions,
+        creation_command: String,
     ) -> Result<Self, Error> {
         let dir = nix::dir::Dir::open(dirname, OFlag::O_DIRECTORY, Mode::empty())?;
 
-        Self::new(dir, catalog, options)
+        Self::new(dir, catalog, options, creation_command)
     }
 }
 
diff --git a/proxmox-backup-client/src/main.rs b/proxmox-backup-client/src/main.rs
index 546275cb..0160a177 100644
--- a/proxmox-backup-client/src/main.rs
+++ b/proxmox-backup-client/src/main.rs
@@ -191,8 +191,14 @@ async fn backup_directory<P: AsRef<Path>>(
     catalog: Arc<Mutex<CatalogWriter<TokioWriterAdapter<StdChannelWriter<Error>>>>>,
     pxar_create_options: pbs_client::pxar::PxarCreateOptions,
     upload_options: UploadOptions,
+    creation_command: String,
 ) -> Result<BackupStats, Error> {
-    let pxar_stream = PxarBackupStream::open(dir_path.as_ref(), catalog, pxar_create_options)?;
+    let pxar_stream = PxarBackupStream::open(
+        dir_path.as_ref(),
+        catalog,
+        pxar_create_options,
+        creation_command,
+    )?;
     let mut chunk_stream = ChunkStream::new(pxar_stream, chunk_size);
 
     let (tx, rx) = mpsc::channel(10); // allow to buffer 10 chunks
@@ -677,10 +683,6 @@ fn spawn_catalog_upload(
 /// Create (host) backup.
 async fn create_backup(
     param: Value,
-    all_file_systems: bool,
-    skip_lost_and_found: bool,
-    dry_run: bool,
-    skip_e2big_xattr: bool,
     _info: &ApiMethod,
     _rpcenv: &mut dyn RpcEnvironment,
 ) -> Result<Value, Error> {
@@ -737,14 +739,14 @@ async fn create_backup(
         );
     }
 
-    let mut devices = if all_file_systems {
+    let mut devices = if param["all-file-systems"].as_bool().unwrap_or(false) {
         None
     } else {
         Some(HashSet::new())
     };
 
     if let Some(include_dev) = include_dev {
-        if all_file_systems {
+        if param["all-file-systems"].as_bool().unwrap_or(false) {
             bail!("option 'all-file-systems' conflicts with option 'include-dev'");
         }
 
@@ -940,12 +942,16 @@ async fn create_backup(
     let mut catalog_result_rx = None;
 
     let log_file = |desc: &str, file: &str, target: &str| {
-        let what = if dry_run { "Would upload" } else { "Upload" };
+        let what = if param["dry-run"].as_bool().unwrap_or(false) {
+            "Would upload"
+        } else {
+            "Upload"
+        };
         log::info!("{} {} '{}' to '{}' as {}", what, desc, file, repo, target);
     };
 
     for (backup_type, filename, target, size) in upload_list {
-        match (backup_type, dry_run) {
+        match (backup_type, param["dry-run"].as_bool().unwrap_or(false)) {
             // dry-run
             (BackupSpecificationType::CONFIG, true) => log_file("config file", &filename, &target),
             (BackupSpecificationType::LOGFILE, true) => log_file("log file", &filename, &target),
@@ -995,6 +1001,8 @@ async fn create_backup(
                     .unwrap()
                     .start_directory(std::ffi::CString::new(target.as_str())?.as_c_str())?;
 
+                let skip_lost_and_found = param["skip-lost-and-found"].as_bool().unwrap_or(false);
+                let skip_e2big_xattr = param["skip-e2big-xattr"].as_bool().unwrap_or(false);
                 let pxar_options = pbs_client::pxar::PxarCreateOptions {
                     device_set: devices.clone(),
                     patterns: pattern_list.clone(),
@@ -1018,6 +1026,7 @@ async fn create_backup(
                     catalog.clone(),
                     pxar_options,
                     upload_options,
+                    param.to_string(),
                 )
                 .await?;
                 manifest.add_file(target, stats.size, stats.csum, crypto.mode)?;
@@ -1041,7 +1050,7 @@ async fn create_backup(
         }
     }
 
-    if dry_run {
+    if param["dry-run"].as_bool().unwrap_or(false) {
         log::info!("dry-run: no upload happened");
         return Ok(Value::Null);
     }
diff --git a/proxmox-restore-daemon/src/proxmox_restore_daemon/api.rs b/proxmox-restore-daemon/src/proxmox_restore_daemon/api.rs
index c2055222..d1f141af 100644
--- a/proxmox-restore-daemon/src/proxmox_restore_daemon/api.rs
+++ b/proxmox-restore-daemon/src/proxmox_restore_daemon/api.rs
@@ -356,7 +356,7 @@ fn extract(
                     };
 
                     let pxar_writer = TokioWriter::new(writer);
-                    create_archive(dir, pxar_writer, Flags::DEFAULT, |_| Ok(()), None, options)
+                    create_archive(dir, pxar_writer, Flags::DEFAULT, |_| Ok(()), None, options, "".to_string())
                         .await
                 }
                 .await;
diff --git a/pxar-bin/src/main.rs b/pxar-bin/src/main.rs
index 2bbe90e3..277d0b46 100644
--- a/pxar-bin/src/main.rs
+++ b/pxar-bin/src/main.rs
@@ -384,6 +384,7 @@ async fn create_archive(
         },
         None,
         options,
+        "".to_string(),
     )
     .await?;
 
diff --git a/tests/catar.rs b/tests/catar.rs
index 36bb4f3b..22a23925 100644
--- a/tests/catar.rs
+++ b/tests/catar.rs
@@ -40,6 +40,7 @@ fn run_test(dir_name: &str) -> Result<(), Error> {
         |_| Ok(()),
         None,
         options,
+        "".to_string(),
     ))?;
 
     Command::new("cmp")
-- 
2.43.0





  parent reply	other threads:[~2024-03-06 14:35 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-06 14:34 [pbs-devel] [RFC proxmox-backup 0/3] Encode creation parameters into pxar archive Gabriel Goller
2024-03-06 14:34 ` [pbs-devel] [PATCH proxmox-backup 1/3] pxar: factor out encode_file Gabriel Goller
2024-03-06 14:34 ` Gabriel Goller [this message]
2024-03-06 14:34 ` [pbs-devel] [PATCH proxmox-backup 3/3] pxar: added creation parameters Gabriel Goller
2024-03-06 15:13 ` [pbs-devel] [RFC proxmox-backup 0/3] Encode creation parameters into pxar archive Christian Ebner
2024-03-07  9:22   ` Gabriel Goller
2024-03-07  9:50   ` Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240306143422.114335-3-g.goller@proxmox.com \
    --to=g.goller@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal