]> git.proxmox.com Git - proxmox-backup.git/blob - src/bin/proxmox_backup_manager/sync.rs
7a1e87182d6ec81652b24a25529cb7a9b227407f
[proxmox-backup.git] / src / bin / proxmox_backup_manager / sync.rs
1 use anyhow::Error;
2 use serde_json::Value;
3
4 use proxmox::api::{api, cli::*, RpcEnvironment, ApiHandler};
5
6 use pbs_api_types::JOB_ID_SCHEMA;
7
8 use proxmox_backup::api2;
9
10 #[api(
11 input: {
12 properties: {
13 "output-format": {
14 schema: OUTPUT_FORMAT,
15 optional: true,
16 },
17 }
18 }
19 )]
20 /// Sync job list.
21 fn list_sync_jobs(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> {
22
23 let output_format = get_output_format(&param);
24
25 let info = &api2::config::sync::API_METHOD_LIST_SYNC_JOBS;
26 let mut data = match info.handler {
27 ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?,
28 _ => unreachable!(),
29 };
30
31 let options = default_table_format_options()
32 .column(ColumnConfig::new("id"))
33 .column(ColumnConfig::new("store"))
34 .column(ColumnConfig::new("remote"))
35 .column(ColumnConfig::new("remote-store"))
36 .column(ColumnConfig::new("schedule"))
37 .column(ColumnConfig::new("comment"));
38
39 format_and_print_result_full(&mut data, &info.returns, &output_format, &options);
40
41 Ok(Value::Null)
42 }
43
44 #[api(
45 input: {
46 properties: {
47 id: {
48 schema: JOB_ID_SCHEMA,
49 },
50 "output-format": {
51 schema: OUTPUT_FORMAT,
52 optional: true,
53 },
54 }
55 }
56 )]
57 /// Show sync job configuration
58 fn show_sync_job(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> {
59
60 let output_format = get_output_format(&param);
61
62 let info = &api2::config::sync::API_METHOD_READ_SYNC_JOB;
63 let mut data = match info.handler {
64 ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?,
65 _ => unreachable!(),
66 };
67
68 let options = default_table_format_options();
69 format_and_print_result_full(&mut data, &info.returns, &output_format, &options);
70
71 Ok(Value::Null)
72 }
73
74 pub fn sync_job_commands() -> CommandLineInterface {
75
76 let cmd_def = CliCommandMap::new()
77 .insert("list", CliCommand::new(&API_METHOD_LIST_SYNC_JOBS))
78 .insert("show",
79 CliCommand::new(&API_METHOD_SHOW_SYNC_JOB)
80 .arg_param(&["id"])
81 .completion_cb("id", pbs_config::sync::complete_sync_job_id)
82 )
83 .insert("create",
84 CliCommand::new(&api2::config::sync::API_METHOD_CREATE_SYNC_JOB)
85 .arg_param(&["id"])
86 .completion_cb("id", pbs_config::sync::complete_sync_job_id)
87 .completion_cb("schedule", pbs_config::datastore::complete_calendar_event)
88 .completion_cb("store", pbs_config::datastore::complete_datastore_name)
89 .completion_cb("remote", pbs_config::remote::complete_remote_name)
90 .completion_cb("remote-store", crate::complete_remote_datastore_name)
91 )
92 .insert("update",
93 CliCommand::new(&api2::config::sync::API_METHOD_UPDATE_SYNC_JOB)
94 .arg_param(&["id"])
95 .completion_cb("id", pbs_config::sync::complete_sync_job_id)
96 .completion_cb("schedule", pbs_config::datastore::complete_calendar_event)
97 .completion_cb("store", pbs_config::datastore::complete_datastore_name)
98 .completion_cb("remote-store", crate::complete_remote_datastore_name)
99 )
100 .insert("remove",
101 CliCommand::new(&api2::config::sync::API_METHOD_DELETE_SYNC_JOB)
102 .arg_param(&["id"])
103 .completion_cb("id", pbs_config::sync::complete_sync_job_id)
104 );
105
106 cmd_def.into()
107 }