backup-client: add optional chunk-size parameter
This commit is contained in:
parent
f0819fe5a5
commit
2d9d143a8f
|
@ -17,13 +17,24 @@ fn required_string_param<'a>(param: &'a Value, name: &str) -> &'a str {
|
||||||
param[name].as_str().expect(&format!("missing parameter '{}'", name))
|
param[name].as_str().expect(&format!("missing parameter '{}'", name))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn backup_file(param: Value, _info: &ApiMethod) -> Result<Value, Error> {
|
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 target = required_string_param(¶m, "target");
|
||||||
|
|
||||||
|
let mut chunk_size = 4*1024*1024;
|
||||||
|
|
||||||
|
if let Some(size) = param["chunk-size"].as_u64() {
|
||||||
|
static SIZES: [u64; 7] = [64, 128, 256, 512, 1024, 2048, 4096];
|
||||||
|
|
||||||
|
if SIZES.contains(&size) {
|
||||||
|
chunk_size = (size as usize) * 1024;
|
||||||
|
} else {
|
||||||
|
bail!("Got unsupported chunk size '{}'", size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let mut datastore = DataStore::open(store)?;
|
let mut datastore = DataStore::open(store)?;
|
||||||
|
|
||||||
println!("Backup file '{}' to '{}'", filename, store);
|
println!("Backup file '{}' to '{}'", filename, store);
|
||||||
|
@ -43,8 +54,6 @@ 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 chunk_size = 1024*1024;
|
|
||||||
|
|
||||||
let mut index = datastore.create_image_writer(&target, size, chunk_size)?;
|
let mut index = datastore.create_image_writer(&target, size, chunk_size)?;
|
||||||
|
|
||||||
tools::file_chunker(file, chunk_size, |pos, chunk| {
|
tools::file_chunker(file, chunk_size, |pos, chunk| {
|
||||||
|
@ -73,6 +82,13 @@ fn main() {
|
||||||
.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."))
|
.required("target", StringSchema::new("Target name."))
|
||||||
|
.optional(
|
||||||
|
"chunk-size",
|
||||||
|
IntegerSchema::new("Chunk size in KB. Must be a power of 2.")
|
||||||
|
.minimum(64)
|
||||||
|
.maximum(4096)
|
||||||
|
.default(4096)
|
||||||
|
)
|
||||||
))
|
))
|
||||||
.arg_param(vec!["filename", "target"])
|
.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