diff --git a/Cargo.toml b/Cargo.toml index 6357ff5b..6a820e2d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -48,7 +48,7 @@ percent-encoding = "2.1" pin-utils = "0.1.0" pin-project = "0.4" pathpatterns = "0.1.2" -proxmox = { version = "0.7.1", features = [ "sortable-macro", "api-macro", "websocket" ] } +proxmox = { version = "0.7.2", features = [ "sortable-macro", "api-macro", "websocket" ] } #proxmox = { git = "git://git.proxmox.com/git/proxmox", version = "0.1.2", features = [ "sortable-macro", "api-macro" ] } #proxmox = { path = "../proxmox/proxmox", features = [ "sortable-macro", "api-macro", "websocket" ] } proxmox-fuse = "0.1.0" diff --git a/src/bin/proxmox-backup-client.rs b/src/bin/proxmox-backup-client.rs index f8a3fe70..cd424c0a 100644 --- a/src/bin/proxmox-backup-client.rs +++ b/src/bin/proxmox-backup-client.rs @@ -456,75 +456,6 @@ async fn change_backup_owner(group: String, mut param: Value) -> Result<(), Erro Ok(()) } -#[api( - input: { - properties: { - repository: { - schema: REPO_URL_SCHEMA, - optional: true, - }, - group: { - type: String, - description: "Backup group.", - optional: true, - }, - "output-format": { - schema: OUTPUT_FORMAT, - optional: true, - }, - } - } -)] -/// List backup snapshots. -async fn list_snapshots(param: Value) -> Result { - - let repo = extract_repository_from_value(¶m)?; - - let output_format = get_output_format(¶m); - - let client = connect(&repo)?; - - let group: Option = if let Some(path) = param["group"].as_str() { - Some(path.parse()?) - } else { - None - }; - - let mut data = api_datastore_list_snapshots(&client, repo.store(), group).await?; - - record_repository(&repo); - - let render_snapshot_path = |_v: &Value, record: &Value| -> Result { - let item: SnapshotListItem = serde_json::from_value(record.to_owned())?; - let snapshot = BackupDir::new(item.backup_type, item.backup_id, item.backup_time)?; - Ok(snapshot.relative_path().to_str().unwrap().to_owned()) - }; - - let render_files = |_v: &Value, record: &Value| -> Result { - let item: SnapshotListItem = serde_json::from_value(record.to_owned())?; - let mut filenames = Vec::new(); - for file in &item.files { - filenames.push(file.filename.to_string()); - } - Ok(tools::format::render_backup_file_list(&filenames[..])) - }; - - let options = default_table_format_options() - .sortby("backup-type", false) - .sortby("backup-id", false) - .sortby("backup-time", false) - .column(ColumnConfig::new("backup-id").renderer(render_snapshot_path).header("snapshot")) - .column(ColumnConfig::new("size").renderer(tools::format::render_bytes_human_readable)) - .column(ColumnConfig::new("files").renderer(render_files)) - ; - - let info = &proxmox_backup::api2::admin::datastore::API_RETURN_SCHEMA_LIST_SNAPSHOTS; - - format_and_print_result_full(&mut data, info, &output_format, &options); - - Ok(Value::Null) -} - #[api( input: { properties: { @@ -2051,11 +1982,6 @@ fn main() { let list_cmd_def = CliCommand::new(&API_METHOD_LIST_BACKUP_GROUPS) .completion_cb("repository", complete_repository); - let snapshots_cmd_def = CliCommand::new(&API_METHOD_LIST_SNAPSHOTS) - .arg_param(&["group"]) - .completion_cb("group", complete_backup_group) - .completion_cb("repository", complete_repository); - let forget_cmd_def = CliCommand::new(&API_METHOD_FORGET_SNAPSHOTS) .arg_param(&["snapshot"]) .completion_cb("repository", complete_repository) @@ -2109,7 +2035,6 @@ fn main() { .insert("logout", logout_cmd_def) .insert("prune", prune_cmd_def) .insert("restore", restore_cmd_def) - .insert("snapshots", snapshots_cmd_def) .insert("snapshot", snapshot_mgtm_cli()) .insert("files", files_cmd_def) .insert("status", status_cmd_def) @@ -2121,7 +2046,10 @@ fn main() { .insert("task", task_mgmt_cli()) .insert("version", version_cmd_def) .insert("benchmark", benchmark_cmd_def) - .insert("change-owner", change_owner_cmd_def); + .insert("change-owner", change_owner_cmd_def) + + .alias(&["snapshots"], &["snapshot", "list"]) + ; let rpcenv = CliEnvironment::new(); run_cli_command(cmd_def, rpcenv, Some(|future| { diff --git a/src/bin/proxmox_backup_client/snapshot.rs b/src/bin/proxmox_backup_client/snapshot.rs index fd5f543b..55c4de63 100644 --- a/src/bin/proxmox_backup_client/snapshot.rs +++ b/src/bin/proxmox_backup_client/snapshot.rs @@ -2,12 +2,95 @@ use anyhow::Error; use serde_json::{json, Value}; use proxmox::api::{api, cli::*}; -use proxmox_backup::tools; +use proxmox_backup::{ + tools, + api2::types::*, + backup::{ + BackupGroup, + } +}; use crate::{ - complete_backup_snapshot, connect, extract_repository_from_value, BackupDir, REPO_URL_SCHEMA, + REPO_URL_SCHEMA, + BackupDir, + api_datastore_list_snapshots, + complete_backup_snapshot, + complete_backup_group, + complete_repository, + connect, + extract_repository_from_value, + record_repository, }; +#[api( + input: { + properties: { + repository: { + schema: REPO_URL_SCHEMA, + optional: true, + }, + group: { + type: String, + description: "Backup group.", + optional: true, + }, + "output-format": { + schema: OUTPUT_FORMAT, + optional: true, + }, + } + } +)] +/// List backup snapshots. +async fn list_snapshots(param: Value) -> Result { + + let repo = extract_repository_from_value(¶m)?; + + let output_format = get_output_format(¶m); + + let client = connect(&repo)?; + + let group: Option = if let Some(path) = param["group"].as_str() { + Some(path.parse()?) + } else { + None + }; + + let mut data = api_datastore_list_snapshots(&client, repo.store(), group).await?; + + record_repository(&repo); + + let render_snapshot_path = |_v: &Value, record: &Value| -> Result { + let item: SnapshotListItem = serde_json::from_value(record.to_owned())?; + let snapshot = BackupDir::new(item.backup_type, item.backup_id, item.backup_time)?; + Ok(snapshot.relative_path().to_str().unwrap().to_owned()) + }; + + let render_files = |_v: &Value, record: &Value| -> Result { + let item: SnapshotListItem = serde_json::from_value(record.to_owned())?; + let mut filenames = Vec::new(); + for file in &item.files { + filenames.push(file.filename.to_string()); + } + Ok(tools::format::render_backup_file_list(&filenames[..])) + }; + + let options = default_table_format_options() + .sortby("backup-type", false) + .sortby("backup-id", false) + .sortby("backup-time", false) + .column(ColumnConfig::new("backup-id").renderer(render_snapshot_path).header("snapshot")) + .column(ColumnConfig::new("size").renderer(tools::format::render_bytes_human_readable)) + .column(ColumnConfig::new("files").renderer(render_files)) + ; + + let info = &proxmox_backup::api2::admin::datastore::API_RETURN_SCHEMA_LIST_SNAPSHOTS; + + format_and_print_result_full(&mut data, info, &output_format, &options); + + Ok(Value::Null) +} + #[api( input: { properties: { @@ -122,5 +205,12 @@ fn notes_cli() -> CliCommandMap { } pub fn snapshot_mgtm_cli() -> CliCommandMap { - CliCommandMap::new().insert("notes", notes_cli()) + CliCommandMap::new() + .insert("notes", notes_cli()) + .insert( + "list", CliCommand::new(&API_METHOD_LIST_SNAPSHOTS) + .arg_param(&["group"]) + .completion_cb("group", complete_backup_group) + .completion_cb("repository", complete_repository) + ) }