backup-client: add optional chunk-size parameter

This commit is contained in:
Dietmar Maurer 2018-12-21 11:18:08 +01:00
parent f0819fe5a5
commit 2d9d143a8f
1 changed files with 19 additions and 3 deletions

View File

@ -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))
}
fn backup_file(param: Value, _info: &ApiMethod) -> Result<Value, Error> {
let filename = required_string_param(&param, "filename");
let store = required_string_param(&param, "store");
let target = required_string_param(&param, "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)?;
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); }
let size = stat.st_size as usize;
let chunk_size = 1024*1024;
let mut index = datastore.create_image_writer(&target, size, chunk_size)?;
tools::file_chunker(file, chunk_size, |pos, chunk| {
@ -73,6 +82,13 @@ fn main() {
.required("filename", StringSchema::new("Source file name."))
.required("store", StringSchema::new("Datastore 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"])
.completion_cb("store", proxmox_backup::config::datastore::complete_datastore_name);