backup-clinet: specify target file name
This commit is contained in:
parent
c2d9b3914a
commit
c34eb16651
|
@ -22,12 +22,20 @@ fn backup_file(param: Value, _info: &ApiMethod) -> Result<Value, Error> {
|
||||||
|
|
||||||
let filename = required_string_param(¶m, "filename");
|
let filename = required_string_param(¶m, "filename");
|
||||||
let store = required_string_param(¶m, "store");
|
let store = required_string_param(¶m, "store");
|
||||||
|
let target = required_string_param(¶m, "target");
|
||||||
|
|
||||||
let mut datastore = DataStore::open(store)?;
|
let mut datastore = DataStore::open(store)?;
|
||||||
|
|
||||||
println!("Backup file '{}' to '{}'", filename, 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)?;
|
let file = std::fs::File::open(filename)?;
|
||||||
|
@ -35,7 +43,7 @@ fn backup_file(param: Value, _info: &ApiMethod) -> Result<Value, Error> {
|
||||||
if stat.st_size <= 0 { bail!("got strange file size '{}'", stat.st_size); }
|
if stat.st_size <= 0 { bail!("got strange file size '{}'", stat.st_size); }
|
||||||
let size = stat.st_size as usize;
|
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| {
|
tools::file_chunker(file, 64*1024, |pos, chunk| {
|
||||||
index.add_chunk(pos, chunk)?;
|
index.add_chunk(pos, chunk)?;
|
||||||
|
@ -62,8 +70,9 @@ fn main() {
|
||||||
ObjectSchema::new("Create backup from file.")
|
ObjectSchema::new("Create backup from file.")
|
||||||
.required("filename", StringSchema::new("Source file name."))
|
.required("filename", StringSchema::new("Source file name."))
|
||||||
.required("store", StringSchema::new("Datastore 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);
|
.completion_cb("store", proxmox_backup::config::datastore::complete_datastore_name);
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue