]> git.proxmox.com Git - proxmox-backup.git/blob - src/bin/backup-client.rs
backup-client: add bash completion for datastore names
[proxmox-backup.git] / src / bin / backup-client.rs
1 extern crate apitest;
2
3 use failure::*;
4
5 use apitest::tools;
6 use apitest::cli::command::*;
7 use apitest::api::schema::*;
8 use apitest::api::router::*;
9 use apitest::backup::chunk_store::*;
10 use serde_json::{Value};
11
12 use apitest::config::datastore;
13
14 fn required_string_param<'a>(param: &'a Value, name: &str) -> &'a str {
15 param[name].as_str().expect(&format!("missing parameter '{}'", name))
16 }
17
18
19 fn backup_file(param: Value, _info: &ApiMethod) -> Result<Value, Error> {
20
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
36 tools::file_chunker(file, 64*1024, |pos, chunk| {
37 println!("CHUNK {} {}", pos, chunk.len());
38 Ok(true)
39 })?;
40
41 Ok(Value::Null)
42 }
43
44
45 fn 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"])
55 .completion_cb("store", apitest::config::datastore::complete_datastore_name);
56
57
58 if let Err(err) = run_cli_command(&cmd_def.into()) {
59 eprintln!("Error: {}", err);
60 print_cli_usage();
61 std::process::exit(-1);
62 }
63
64 }