2018-12-14 07:28:56 +00:00
|
|
|
extern crate apitest;
|
|
|
|
|
|
|
|
use failure::*;
|
|
|
|
|
2018-12-15 10:14:41 +00:00
|
|
|
use apitest::tools;
|
2018-12-14 07:28:56 +00:00
|
|
|
use apitest::cli::command::*;
|
|
|
|
use apitest::api::schema::*;
|
|
|
|
use apitest::api::router::*;
|
|
|
|
use apitest::backup::chunk_store::*;
|
2018-12-15 10:14:41 +00:00
|
|
|
use serde_json::{Value};
|
2018-12-14 07:28:56 +00:00
|
|
|
|
|
|
|
use apitest::config::datastore;
|
|
|
|
|
2018-12-14 12:39:41 +00:00
|
|
|
fn required_string_param<'a>(param: &'a Value, name: &str) -> &'a str {
|
|
|
|
param[name].as_str().expect(&format!("missing parameter '{}'", name))
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-12-14 07:28:56 +00:00
|
|
|
fn backup_file(param: Value, _info: &ApiMethod) -> Result<Value, Error> {
|
|
|
|
|
2018-12-14 12:39:41 +00:00
|
|
|
let filename = required_string_param(¶m, "filename");
|
|
|
|
let store = required_string_param(¶m, "store");
|
|
|
|
|
|
|
|
let config = datastore::config()?;
|
|
|
|
let (_, store_config) = config.sections.get(store)
|
|
|
|
.ok_or(format_err!("no such datastore '{}'", store))?;
|
|
|
|
|
|
|
|
let path = store_config["path"].as_str().unwrap();
|
|
|
|
|
|
|
|
let _store = ChunkStore::open(path)?;
|
|
|
|
|
|
|
|
println!("Backup file '{}' to '{}'", filename, store);
|
|
|
|
|
|
|
|
let file = std::fs::File::open(filename)?;
|
|
|
|
|
2018-12-15 10:14:41 +00:00
|
|
|
tools::file_chunker(file, 64*1024, |pos, chunk| {
|
2018-12-14 12:39:41 +00:00
|
|
|
println!("CHUNK {} {}", pos, chunk.len());
|
|
|
|
Ok(true)
|
|
|
|
})?;
|
|
|
|
|
2018-12-14 07:28:56 +00:00
|
|
|
Ok(Value::Null)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
|
|
|
|
let cmd_def = CliCommand::new(
|
|
|
|
ApiMethod::new(
|
|
|
|
backup_file,
|
|
|
|
ObjectSchema::new("Create backup from file.")
|
|
|
|
.required("filename", StringSchema::new("Source file name."))
|
|
|
|
.required("store", StringSchema::new("Datastore name."))
|
|
|
|
))
|
|
|
|
.arg_param(vec!["filename"]);
|
2018-12-14 12:39:41 +00:00
|
|
|
|
2018-12-14 07:28:56 +00:00
|
|
|
if let Err(err) = run_cli_command(&cmd_def.into()) {
|
|
|
|
eprintln!("Error: {}", err);
|
|
|
|
print_cli_usage();
|
|
|
|
std::process::exit(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|