From: Friedrich Weber <f.weber@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup] fix #4341: manager cli: add commands to run prune/sync/verify jobs
Date: Thu, 2 Feb 2023 17:00:14 +0100 [thread overview]
Message-ID: <20230202160014.3646404-1-f.weber@proxmox.com> (raw)
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@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
next reply other threads:[~2023-02-02 16:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-02 16:00 Friedrich Weber [this message]
2023-02-09 11:06 ` [pbs-devel] applied: " Wolfgang Bumiller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230202160014.3646404-1-f.weber@proxmox.com \
--to=f.weber@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox