From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 9893291A60 for ; Thu, 2 Feb 2023 17:00:29 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 78A0210056 for ; Thu, 2 Feb 2023 17:00:29 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Thu, 2 Feb 2023 17:00:27 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id A5167446AB for ; Thu, 2 Feb 2023 17:00:27 +0100 (CET) From: Friedrich Weber To: pbs-devel@lists.proxmox.com Date: Thu, 2 Feb 2023 17:00:14 +0100 Message-Id: <20230202160014.3646404-1-f.weber@proxmox.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.897 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [verify.rs, proxmox-backup-manager.rs, prune.rs, sync.rs] Subject: [pbs-devel] [PATCH proxmox-backup] fix #4341: manager cli: add commands to run prune/sync/verify jobs X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 02 Feb 2023 16:00:29 -0000 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 * sync-job run * verify-job run Signed-off-by: Friedrich Weber --- 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 { + 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 { 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 Result { + 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 Result { + 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 { + 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