]> git.proxmox.com Git - proxmox-backup.git/blame - src/bin/backup-client.rs
install backup-client binary
[proxmox-backup.git] / src / bin / backup-client.rs
CommitLineData
ff5d3707 1extern crate apitest;
2
3use failure::*;
4
43eeef28 5use apitest::tools;
ff5d3707 6use apitest::cli::command::*;
7use apitest::api::schema::*;
8use apitest::api::router::*;
9use apitest::backup::chunk_store::*;
43eeef28 10use serde_json::{Value};
ff5d3707 11
12use apitest::config::datastore;
13
a914a774 14fn required_string_param<'a>(param: &'a Value, name: &str) -> &'a str {
15 param[name].as_str().expect(&format!("missing parameter '{}'", name))
16}
17
18
ff5d3707 19fn backup_file(param: Value, _info: &ApiMethod) -> Result<Value, Error> {
20
a914a774 21 let filename = required_string_param(&param, "filename");
22 let store = required_string_param(&param, "store");
23
24 let config = datastore::config()?;
25 let (_, store_config) = config.sections.get(store)
26 .ok_or(format_err!("no such datastore '{}'", store))?;
27
28 let path = store_config["path"].as_str().unwrap();
29
30 let _store = ChunkStore::open(path)?;
31
32 println!("Backup file '{}' to '{}'", filename, store);
33
34 let file = std::fs::File::open(filename)?;
35
43eeef28 36 tools::file_chunker(file, 64*1024, |pos, chunk| {
a914a774 37 println!("CHUNK {} {}", pos, chunk.len());
38 Ok(true)
39 })?;
40
ff5d3707 41 Ok(Value::Null)
42}
43
44
45fn main() {
46
47 let cmd_def = CliCommand::new(
48 ApiMethod::new(
49 backup_file,
50 ObjectSchema::new("Create backup from file.")
51 .required("filename", StringSchema::new("Source file name."))
52 .required("store", StringSchema::new("Datastore name."))
53 ))
54 .arg_param(vec!["filename"]);
a914a774 55
ff5d3707 56 if let Err(err) = run_cli_command(&cmd_def.into()) {
57 eprintln!("Error: {}", err);
58 print_cli_usage();
59 std::process::exit(-1);
60 }
61
62}