[pbs-devel] [PATCH proxmox-backup] fix #4341: manager cli: add commands to run prune/sync/verify jobs
Friedrich Weber
f.weber at proxmox.com
Thu Feb 2 17:00:14 CET 2023
Running configured jobs was already possible using the Web UI, but not
using the CLI. To fix that, this commit adds the following commands to
`proxmox-backup-manager`:
* prune-job run <id>
* sync-job run <id>
* verify-job run <id>
Signed-off-by: Friedrich Weber <f.weber at proxmox.com>
---
I mostly copied the behavior of the `garbage-collection start` command.
Let me know what you think!
src/bin/proxmox-backup-manager.rs | 15 +++++++++++++++
src/bin/proxmox_backup_manager/prune.rs | 24 ++++++++++++++++++++++++
src/bin/proxmox_backup_manager/sync.rs | 24 ++++++++++++++++++++++++
src/bin/proxmox_backup_manager/verify.rs | 24 ++++++++++++++++++++++++
4 files changed, 87 insertions(+)
diff --git a/src/bin/proxmox-backup-manager.rs b/src/bin/proxmox-backup-manager.rs
index f084af31..86adabe3 100644
--- a/src/bin/proxmox-backup-manager.rs
+++ b/src/bin/proxmox-backup-manager.rs
@@ -500,6 +500,21 @@ fn main() -> Result<(), Error> {
proxmox_async::runtime::main(run())
}
+/// Run the job of a given type (one of "prune", "sync", "verify"),
+/// specified by the 'id' parameter.
+async fn run_job(job_type: &str, param: Value) -> Result<Value, Error> {
+ let output_format = get_output_format(¶m);
+ let id = required_string_param(¶m, "id")?;
+
+ let client = connect_to_localhost()?;
+
+ let path = format!("api2/json/admin/{}/{}/run", job_type, id);
+ let result = client.post(&path, None).await?;
+ view_task_result(&client, result, &output_format).await?;
+
+ Ok(Value::Null)
+}
+
fn get_sync_job(id: &str) -> Result<SyncJobConfig, Error> {
let (config, _digest) = sync::config()?;
diff --git a/src/bin/proxmox_backup_manager/prune.rs b/src/bin/proxmox_backup_manager/prune.rs
index deeb8330..923eb6f5 100644
--- a/src/bin/proxmox_backup_manager/prune.rs
+++ b/src/bin/proxmox_backup_manager/prune.rs
@@ -80,6 +80,24 @@ fn show_prune_job(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value
Ok(Value::Null)
}
+#[api(
+ input: {
+ properties: {
+ id: {
+ schema: JOB_ID_SCHEMA,
+ },
+ "output-format": {
+ schema: OUTPUT_FORMAT,
+ optional: true,
+ },
+ }
+ }
+)]
+/// Run the specified prune job
+async fn run_prune_job(param: Value) -> Result<Value, Error> {
+ crate::run_job("prune", param).await
+}
+
pub fn prune_job_commands() -> CommandLineInterface {
let cmd_def = CliCommandMap::new()
.insert("list", CliCommand::new(&API_METHOD_LIST_PRUNE_JOBS))
@@ -107,6 +125,12 @@ pub fn prune_job_commands() -> CommandLineInterface {
.completion_cb("store", pbs_config::datastore::complete_datastore_name)
.completion_cb("ns", complete_prune_local_datastore_namespace),
)
+ .insert(
+ "run",
+ CliCommand::new(&API_METHOD_RUN_PRUNE_JOB)
+ .arg_param(&["id"])
+ .completion_cb("id", pbs_config::prune::complete_prune_job_id),
+ )
.insert(
"remove",
CliCommand::new(&api2::config::prune::API_METHOD_DELETE_PRUNE_JOB)
diff --git a/src/bin/proxmox_backup_manager/sync.rs b/src/bin/proxmox_backup_manager/sync.rs
index 1f5f6523..005cce6f 100644
--- a/src/bin/proxmox_backup_manager/sync.rs
+++ b/src/bin/proxmox_backup_manager/sync.rs
@@ -87,6 +87,24 @@ fn show_sync_job(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value,
Ok(Value::Null)
}
+#[api(
+ input: {
+ properties: {
+ id: {
+ schema: JOB_ID_SCHEMA,
+ },
+ "output-format": {
+ schema: OUTPUT_FORMAT,
+ optional: true,
+ },
+ }
+ }
+)]
+/// Run the specified sync job
+async fn run_sync_job(param: Value) -> Result<Value, Error> {
+ crate::run_job("sync", param).await
+}
+
pub fn sync_job_commands() -> CommandLineInterface {
let cmd_def = CliCommandMap::new()
.insert("list", CliCommand::new(&API_METHOD_LIST_SYNC_JOBS))
@@ -127,6 +145,12 @@ pub fn sync_job_commands() -> CommandLineInterface {
)
.completion_cb("remote-ns", crate::complete_remote_datastore_namespace),
)
+ .insert(
+ "run",
+ CliCommand::new(&API_METHOD_RUN_SYNC_JOB)
+ .arg_param(&["id"])
+ .completion_cb("id", pbs_config::sync::complete_sync_job_id),
+ )
.insert(
"remove",
CliCommand::new(&api2::config::sync::API_METHOD_DELETE_SYNC_JOB)
diff --git a/src/bin/proxmox_backup_manager/verify.rs b/src/bin/proxmox_backup_manager/verify.rs
index 521a31f1..3122b789 100644
--- a/src/bin/proxmox_backup_manager/verify.rs
+++ b/src/bin/proxmox_backup_manager/verify.rs
@@ -70,6 +70,24 @@ fn show_verification_job(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Resul
Ok(Value::Null)
}
+#[api(
+ input: {
+ properties: {
+ id: {
+ schema: JOB_ID_SCHEMA,
+ },
+ "output-format": {
+ schema: OUTPUT_FORMAT,
+ optional: true,
+ },
+ }
+ }
+)]
+/// Run the specified verification job
+async fn run_verification_job(param: Value) -> Result<Value, Error> {
+ crate::run_job("verify", param).await
+}
+
pub fn verify_job_commands() -> CommandLineInterface {
let cmd_def = CliCommandMap::new()
.insert("list", CliCommand::new(&API_METHOD_LIST_VERIFICATION_JOBS))
@@ -96,6 +114,12 @@ pub fn verify_job_commands() -> CommandLineInterface {
.completion_cb("store", pbs_config::datastore::complete_datastore_name)
.completion_cb("remote-store", crate::complete_remote_datastore_name),
)
+ .insert(
+ "run",
+ CliCommand::new(&API_METHOD_RUN_VERIFICATION_JOB)
+ .arg_param(&["id"])
+ .completion_cb("id", pbs_config::verify::complete_verification_job_id),
+ )
.insert(
"remove",
CliCommand::new(&api2::config::verify::API_METHOD_DELETE_VERIFICATION_JOB)
--
2.30.2
More information about the pbs-devel
mailing list