]> git.proxmox.com Git - proxmox-backup.git/blobdiff - src/bin/proxmox-backup-client.rs
client: use hyper-tls for now
[proxmox-backup.git] / src / bin / proxmox-backup-client.rs
index c17a36dd1c306d5c6800fd1cc7247831ead6790c..cbd6953fe276fb11a4974783eac16d87508c9c04 100644 (file)
@@ -1,7 +1,7 @@
 extern crate proxmox_backup;
 
 use failure::*;
-use std::os::unix::io::AsRawFd;
+//use std::os::unix::io::AsRawFd;
 
 use proxmox_backup::tools;
 use proxmox_backup::cli::command::*;
@@ -13,7 +13,7 @@ use proxmox_backup::client::catar_backup_stream::*;
 //use proxmox_backup::backup::image_index::*;
 //use proxmox_backup::config::datastore;
 //use proxmox_backup::catar::encoder::*;
-use proxmox_backup::backup::datastore::*;
+//use proxmox_backup::backup::datastore::*;
 
 use serde_json::{Value};
 use hyper::Body;
@@ -32,7 +32,7 @@ fn backup_directory(body: Body, store: &str, archive_name: &str) -> Result<(), E
         .append_pair("time", &epoch.to_string())
         .finish();
 
-    let path = format!("api3/json/admin/datastore/{}/upload_catar?{}", store, query);
+    let path = format!("api2/json/admin/datastore/{}/catar?{}", store, query);
 
     client.upload("application/x-proxmox-backup-catar", body, &path)?;
 
@@ -45,11 +45,11 @@ fn backup_image(datastore: &DataStore, file: &std::fs::File, size: usize, target
     let mut target = PathBuf::from(target);
 
     if let Some(ext) = target.extension() {
-        if ext != "iidx" {
-            bail!("got wrong file extension - expected '.iidx'");
+        if ext != "fidx" {
+            bail!("got wrong file extension - expected '.fidx'");
         }
     } else {
-        target.set_extension("iidx");
+        target.set_extension("fidx");
     }
 
     let mut index = datastore.create_image_writer(&target, size, chunk_size)?;
@@ -65,19 +65,40 @@ fn backup_image(datastore: &DataStore, file: &std::fs::File, size: usize, target
 }
 */
 
-fn create_backup(param: Value, _info: &ApiMethod) -> Result<Value, Error> {
+fn list_backups(
+    param: Value,
+    _info: &ApiMethod,
+    _rpcenv: &mut RpcEnvironment,
+) -> Result<Value, Error> {
+
+    let store = tools::required_string_param(&param, "store")?;
+
+    let client = HttpClient::new("localhost");
+
+    let path = format!("api2/json/admin/datastore/{}/backups", store);
+
+    let result = client.get(&path)?;
+
+    Ok(result)
+}
+
+fn create_backup(
+    param: Value,
+    _info: &ApiMethod,
+    _rpcenv: &mut RpcEnvironment,
+) -> Result<Value, Error> {
 
     let filename = tools::required_string_param(&param, "filename")?;
     let store = tools::required_string_param(&param, "store")?;
     let target = tools::required_string_param(&param, "target")?;
 
-    let mut chunk_size = 4*1024*1024;
+    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;
+            _chunk_size = (size as usize) * 1024;
         } else {
             bail!("Got unsupported chunk size '{}'", size);
         }
@@ -101,7 +122,7 @@ fn create_backup(param: Value, _info: &ApiMethod) -> Result<Value, Error> {
         println!("Backup image '{}' to '{}'", filename, store);
 
         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;
 
         panic!("implement me");
 
@@ -121,7 +142,7 @@ fn create_backup(param: Value, _info: &ApiMethod) -> Result<Value, Error> {
 
 fn main() {
 
-    let cmd_def = CliCommand::new(
+    let create_cmd_def = CliCommand::new(
         ApiMethod::new(
             create_backup,
             ObjectSchema::new("Create backup.")
@@ -140,6 +161,19 @@ fn main() {
         .completion_cb("filename", tools::complete_file_name)
         .completion_cb("store", proxmox_backup::config::datastore::complete_datastore_name);
 
+    let list_cmd_def = CliCommand::new(
+        ApiMethod::new(
+            list_backups,
+            ObjectSchema::new("List backups.")
+                .required("store", StringSchema::new("Datastore name."))
+        ))
+        .arg_param(vec!["store"])
+        .completion_cb("store", proxmox_backup::config::datastore::complete_datastore_name);
+
+
+    let cmd_def = CliCommandMap::new()
+        .insert("create".to_owned(), create_cmd_def.into())
+        .insert("list".to_owned(), list_cmd_def.into());
 
     if let Err(err) = run_cli_command(&cmd_def.into()) {
         eprintln!("Error: {}", err);