]> git.proxmox.com Git - proxmox-backup.git/commitdiff
src/bin/proxmox-backup-manager.rs: implement cli sync command
authorDietmar Maurer <dietmar@proxmox.com>
Thu, 9 Jan 2020 13:52:29 +0000 (14:52 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Thu, 9 Jan 2020 13:52:29 +0000 (14:52 +0100)
src/bin/proxmox-backup-manager.rs

index 8a50356913bbbb40bc368f63279d593b9bf509dd..5218674d3d845f5fb5b426c47b629c9c56465c9f 100644 (file)
@@ -353,13 +353,69 @@ fn cert_mgmt_cli() -> CommandLineInterface {
     cmd_def.into()
 }
 
+#[api(
+   input: {
+        properties: {
+            store: {
+                schema: DATASTORE_SCHEMA,
+            },
+            remote: {
+                description: "Remote name.", // fixme: remote ID schema
+                type: String,
+            },
+            "remote-store": {
+                schema: DATASTORE_SCHEMA,
+            },
+            "output-format": {
+                schema: OUTPUT_FORMAT,
+                optional: true,
+            },
+        }
+   }
+)]
+/// Start datastore sync
+async fn start_datastore_sync(
+    store: String,
+    remote: String,
+    remote_store: String,
+    output_format: Option<String>,
+) -> Result<Value, Error> {
+
+    let output_format = output_format.unwrap_or("text".to_string());
+
+    let mut client = connect()?;
+
+    let remote = proxmox_backup::config::remotes::lookup(&remote)?;
+
+    let args = json!({
+        "store": store,
+        "remote-host": remote.host,
+        "remote-user": remote.userid,
+        "remote-store": remote_store,
+        "remote-password": remote.password,
+    });
+
+    let result = client.post("api2/json/sync", Some(args)).await?;
+
+    view_task_result(client, result, &output_format).await?;
+
+    Ok(Value::Null)
+}
+
 fn main() {
 
     let cmd_def = CliCommandMap::new()
         .insert("datastore", datastore_commands())
         .insert("garbage-collection", garbage_collection_commands())
         .insert("cert", cert_mgmt_cli())
-        .insert("task", task_mgmt_cli());
+        .insert("task", task_mgmt_cli())
+        .insert(
+            "sync",
+            CliCommand::new(&API_METHOD_START_DATASTORE_SYNC)
+                .arg_param(&["store", "remote", "remote-store"])
+                .completion_cb("store", config::datastore::complete_datastore_name)
+                .completion_cb("remote", config::remotes::complete_remote_name)
+        );
 
     run_cli_command(cmd_def);
 }