From c34eb16651814b84f4a1df92e8bc00cd19909f21 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Thu, 20 Dec 2018 14:09:31 +0100 Subject: [PATCH] backup-clinet: specify target file name --- src/bin/backup-client.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/bin/backup-client.rs b/src/bin/backup-client.rs index 9ed931c4..65b66e72 100644 --- a/src/bin/backup-client.rs +++ b/src/bin/backup-client.rs @@ -22,12 +22,20 @@ fn backup_file(param: Value, _info: &ApiMethod) -> Result { let filename = required_string_param(¶m, "filename"); let store = required_string_param(¶m, "store"); + let target = required_string_param(¶m, "target"); let mut datastore = DataStore::open(store)?; println!("Backup file '{}' to '{}'", filename, store); - let target = "test1.idx"; + let mut target = std::path::PathBuf::from(target); + if let Some(ext) = target.extension() { + if ext != "iidx" { + bail!("got wrong file extension - expected '.iidx'"); + } + } else { + target.set_extension("iidx"); + } { let file = std::fs::File::open(filename)?; @@ -35,7 +43,7 @@ fn backup_file(param: Value, _info: &ApiMethod) -> Result { if stat.st_size <= 0 { bail!("got strange file size '{}'", stat.st_size); } let size = stat.st_size as usize; - let mut index = datastore.create_image_writer(target, size)?; + let mut index = datastore.create_image_writer(&target, size)?; tools::file_chunker(file, 64*1024, |pos, chunk| { index.add_chunk(pos, chunk)?; @@ -62,8 +70,9 @@ fn main() { ObjectSchema::new("Create backup from file.") .required("filename", StringSchema::new("Source file name.")) .required("store", StringSchema::new("Datastore name.")) + .required("target", StringSchema::new("Target name.")) )) - .arg_param(vec!["filename"]) + .arg_param(vec!["filename", "target"]) .completion_cb("store", proxmox_backup::config::datastore::complete_datastore_name);