[pbs-devel] [PATCH proxmox-backup 2/3] client: unify parameters and write to file
Gabriel Goller
g.goller at proxmox.com
Wed Mar 6 15:34:12 CET 2024
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 at 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
More information about the pbs-devel
mailing list