2021-11-04 09:56:22 +00:00
|
|
|
use std::collections::HashMap;
|
|
|
|
|
|
|
|
use anyhow::{bail, format_err, Error};
|
2020-12-11 09:42:29 +00:00
|
|
|
use serde_json::{json, Value};
|
2020-12-09 16:35:31 +00:00
|
|
|
|
2021-10-08 09:19:37 +00:00
|
|
|
use proxmox_io::ReadExt;
|
|
|
|
use proxmox_router::RpcEnvironment;
|
|
|
|
use proxmox_router::cli::*;
|
|
|
|
use proxmox_schema::api;
|
|
|
|
use proxmox_section_config::SectionConfigData;
|
|
|
|
use proxmox_time::strftime_local;
|
2020-12-09 16:35:31 +00:00
|
|
|
|
2021-09-29 09:05:26 +00:00
|
|
|
use pbs_client::view_task_result;
|
2021-07-06 11:26:35 +00:00
|
|
|
use pbs_tools::format::{
|
|
|
|
HumanByte,
|
|
|
|
render_epoch,
|
|
|
|
render_bytes_human_readable,
|
|
|
|
};
|
|
|
|
|
2021-09-03 07:10:18 +00:00
|
|
|
use pbs_config::drive::complete_drive_name;
|
2021-09-06 06:56:04 +00:00
|
|
|
use pbs_config::media_pool::complete_pool_name;
|
2021-09-10 06:40:58 +00:00
|
|
|
use pbs_config::datastore::complete_datastore_name;
|
2021-09-03 07:10:18 +00:00
|
|
|
|
2021-09-10 10:25:32 +00:00
|
|
|
use pbs_api_types::{
|
|
|
|
Userid, Authid, DATASTORE_SCHEMA, DATASTORE_MAP_LIST_SCHEMA,
|
|
|
|
DRIVE_NAME_SCHEMA, MEDIA_LABEL_SCHEMA, MEDIA_POOL_NAME_SCHEMA,
|
2021-11-04 09:56:22 +00:00
|
|
|
TAPE_RESTORE_SNAPSHOT_SCHEMA, GROUP_FILTER_LIST_SCHEMA, GroupListItem,
|
2021-09-10 10:25:32 +00:00
|
|
|
};
|
2021-09-13 09:54:24 +00:00
|
|
|
use pbs_tape::{
|
|
|
|
PROXMOX_BACKUP_CONTENT_HEADER_MAGIC_1_0, BlockReadError, MediaContentHeader,
|
|
|
|
};
|
2021-09-10 10:25:32 +00:00
|
|
|
|
2020-12-09 16:35:31 +00:00
|
|
|
use proxmox_backup::{
|
2021-09-10 10:25:32 +00:00
|
|
|
api2,
|
2020-12-10 06:52:56 +00:00
|
|
|
tape::{
|
2021-02-05 09:50:21 +00:00
|
|
|
drive::{
|
|
|
|
open_drive,
|
|
|
|
lock_tape_device,
|
2021-02-18 14:40:28 +00:00
|
|
|
set_tape_device_state,
|
2021-02-05 09:50:21 +00:00
|
|
|
},
|
2021-01-13 12:26:59 +00:00
|
|
|
complete_media_label_text,
|
2020-12-31 09:26:48 +00:00
|
|
|
complete_media_set_uuid,
|
2021-05-11 10:50:06 +00:00
|
|
|
complete_media_set_snapshots,
|
2020-12-14 11:55:49 +00:00
|
|
|
file_formats::{
|
2021-02-04 06:58:34 +00:00
|
|
|
proxmox_tape_magic_to_text,
|
2020-12-14 11:55:49 +00:00
|
|
|
},
|
2020-12-10 06:52:56 +00:00
|
|
|
},
|
2021-09-29 09:05:26 +00:00
|
|
|
client_helpers::connect_to_localhost,
|
2020-12-09 11:58:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
mod proxmox_tape;
|
|
|
|
use proxmox_tape::*;
|
|
|
|
|
2021-11-04 09:56:22 +00:00
|
|
|
async fn get_backup_groups(store: &str) -> Result<Vec<GroupListItem>, Error> {
|
|
|
|
let client = connect_to_localhost()?;
|
|
|
|
let api_res = client
|
|
|
|
.get(&format!("api2/json/admin/datastore/{}/groups", store), None)
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
match api_res.get("data") {
|
|
|
|
Some(data) => Ok(serde_json::from_value::<Vec<GroupListItem>>(data.to_owned())?),
|
|
|
|
None => bail!("could not get group list"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// shell completion helper
|
|
|
|
pub fn complete_datastore_group_filter(_arg: &str, param: &HashMap<String, String>) -> Vec<String> {
|
|
|
|
|
|
|
|
let mut list = Vec::new();
|
|
|
|
|
|
|
|
list.push("regex:".to_string());
|
|
|
|
list.push("type:ct".to_string());
|
|
|
|
list.push("type:host".to_string());
|
|
|
|
list.push("type:vm".to_string());
|
|
|
|
|
|
|
|
if let Some(store) = param.get("store") {
|
|
|
|
let groups = pbs_runtime::block_on(async { get_backup_groups(store).await });
|
|
|
|
if let Ok(groups) = groups {
|
|
|
|
list.extend(groups.iter().map(|group| format!("group:{}/{}", group.backup_type, group.backup_id)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
list
|
|
|
|
}
|
|
|
|
|
2021-02-11 13:11:17 +00:00
|
|
|
pub fn extract_drive_name(
|
|
|
|
param: &mut Value,
|
2020-12-09 16:35:31 +00:00
|
|
|
config: &SectionConfigData,
|
|
|
|
) -> Result<String, Error> {
|
|
|
|
|
|
|
|
let drive = param["drive"]
|
|
|
|
.as_str()
|
|
|
|
.map(String::from)
|
|
|
|
.or_else(|| std::env::var("PROXMOX_TAPE_DRIVE").ok())
|
|
|
|
.or_else(|| {
|
|
|
|
|
|
|
|
let mut drive_names = Vec::new();
|
|
|
|
|
|
|
|
for (name, (section_type, _)) in config.sections.iter() {
|
|
|
|
|
|
|
|
if !(section_type == "linux" || section_type == "virtual") { continue; }
|
|
|
|
drive_names.push(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
if drive_names.len() == 1 {
|
|
|
|
Some(drive_names[0].to_owned())
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.ok_or_else(|| format_err!("unable to get (default) drive name"))?;
|
|
|
|
|
2021-02-11 13:11:17 +00:00
|
|
|
if let Some(map) = param.as_object_mut() {
|
|
|
|
map.remove("drive");
|
|
|
|
}
|
|
|
|
|
2020-12-09 16:35:31 +00:00
|
|
|
Ok(drive)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[api(
|
|
|
|
input: {
|
|
|
|
properties: {
|
|
|
|
drive: {
|
2020-12-13 08:18:16 +00:00
|
|
|
schema: DRIVE_NAME_SCHEMA,
|
2020-12-09 16:35:31 +00:00
|
|
|
optional: true,
|
|
|
|
},
|
|
|
|
fast: {
|
|
|
|
description: "Use fast erase.",
|
|
|
|
type: bool,
|
|
|
|
optional: true,
|
|
|
|
default: true,
|
|
|
|
},
|
2021-01-28 15:36:10 +00:00
|
|
|
"output-format": {
|
|
|
|
schema: OUTPUT_FORMAT,
|
|
|
|
optional: true,
|
|
|
|
},
|
|
|
|
},
|
2020-12-09 16:35:31 +00:00
|
|
|
},
|
|
|
|
)]
|
2021-03-31 07:19:19 +00:00
|
|
|
/// Format media
|
|
|
|
async fn format_media(mut param: Value) -> Result<(), Error> {
|
2021-01-28 15:36:10 +00:00
|
|
|
|
2021-04-30 12:51:56 +00:00
|
|
|
let output_format = extract_output_format(&mut param);
|
2020-12-09 16:35:31 +00:00
|
|
|
|
2021-09-03 07:10:18 +00:00
|
|
|
let (config, _digest) = pbs_config::drive::config()?;
|
2020-12-09 16:35:31 +00:00
|
|
|
|
2021-02-11 13:11:17 +00:00
|
|
|
let drive = extract_drive_name(&mut param, &config)?;
|
2020-12-09 16:35:31 +00:00
|
|
|
|
2021-01-28 15:36:10 +00:00
|
|
|
let mut client = connect_to_localhost()?;
|
2020-12-09 16:35:31 +00:00
|
|
|
|
2021-03-31 07:19:19 +00:00
|
|
|
let path = format!("api2/json/tape/drive/{}/format-media", drive);
|
2021-01-28 15:36:10 +00:00
|
|
|
let result = client.post(&path, Some(param)).await?;
|
2020-12-09 16:35:31 +00:00
|
|
|
|
2021-01-29 10:21:57 +00:00
|
|
|
view_task_result(&mut client, result, &output_format).await?;
|
2020-12-11 10:15:58 +00:00
|
|
|
|
2020-12-09 16:35:31 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2020-12-09 16:43:38 +00:00
|
|
|
#[api(
|
|
|
|
input: {
|
|
|
|
properties: {
|
|
|
|
drive: {
|
2020-12-13 08:18:16 +00:00
|
|
|
schema: DRIVE_NAME_SCHEMA,
|
2020-12-09 16:43:38 +00:00
|
|
|
optional: true,
|
|
|
|
},
|
2021-01-28 15:36:10 +00:00
|
|
|
"output-format": {
|
|
|
|
schema: OUTPUT_FORMAT,
|
|
|
|
optional: true,
|
|
|
|
},
|
2020-12-09 16:43:38 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
)]
|
|
|
|
/// Rewind tape
|
2021-02-11 13:11:17 +00:00
|
|
|
async fn rewind(mut param: Value) -> Result<(), Error> {
|
2021-01-28 15:36:10 +00:00
|
|
|
|
2021-04-30 12:51:56 +00:00
|
|
|
let output_format = extract_output_format(&mut param);
|
2020-12-09 16:50:48 +00:00
|
|
|
|
2021-09-03 07:10:18 +00:00
|
|
|
let (config, _digest) = pbs_config::drive::config()?;
|
2020-12-09 16:43:38 +00:00
|
|
|
|
2021-02-11 13:11:17 +00:00
|
|
|
let drive = extract_drive_name(&mut param, &config)?;
|
2020-12-09 16:43:38 +00:00
|
|
|
|
2021-01-28 15:36:10 +00:00
|
|
|
let mut client = connect_to_localhost()?;
|
2020-12-09 16:43:38 +00:00
|
|
|
|
2021-01-28 15:36:10 +00:00
|
|
|
let path = format!("api2/json/tape/drive/{}/rewind", drive);
|
|
|
|
let result = client.post(&path, Some(param)).await?;
|
2020-12-09 16:43:38 +00:00
|
|
|
|
2021-01-29 10:21:57 +00:00
|
|
|
view_task_result(&mut client, result, &output_format).await?;
|
2020-12-11 10:15:58 +00:00
|
|
|
|
2020-12-09 16:43:38 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2020-12-09 16:50:48 +00:00
|
|
|
#[api(
|
|
|
|
input: {
|
|
|
|
properties: {
|
|
|
|
drive: {
|
2020-12-13 08:18:16 +00:00
|
|
|
schema: DRIVE_NAME_SCHEMA,
|
2020-12-09 16:50:48 +00:00
|
|
|
optional: true,
|
|
|
|
},
|
2021-01-28 15:46:28 +00:00
|
|
|
"output-format": {
|
|
|
|
schema: OUTPUT_FORMAT,
|
|
|
|
optional: true,
|
|
|
|
},
|
2020-12-09 16:50:48 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
)]
|
|
|
|
/// Eject/Unload drive media
|
2021-02-11 13:11:17 +00:00
|
|
|
async fn eject_media(mut param: Value) -> Result<(), Error> {
|
2021-01-28 15:46:28 +00:00
|
|
|
|
2021-04-30 12:51:56 +00:00
|
|
|
let output_format = extract_output_format(&mut param);
|
2020-12-09 16:50:48 +00:00
|
|
|
|
2021-09-03 07:10:18 +00:00
|
|
|
let (config, _digest) = pbs_config::drive::config()?;
|
2020-12-09 16:50:48 +00:00
|
|
|
|
2021-02-11 13:11:17 +00:00
|
|
|
let drive = extract_drive_name(&mut param, &config)?;
|
2020-12-09 16:50:48 +00:00
|
|
|
|
2021-01-28 15:46:28 +00:00
|
|
|
let mut client = connect_to_localhost()?;
|
2020-12-09 16:50:48 +00:00
|
|
|
|
2021-01-28 15:46:28 +00:00
|
|
|
let path = format!("api2/json/tape/drive/{}/eject-media", drive);
|
|
|
|
let result = client.post(&path, Some(param)).await?;
|
|
|
|
|
2021-01-29 10:21:57 +00:00
|
|
|
view_task_result(&mut client, result, &output_format).await?;
|
2020-12-09 16:50:48 +00:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2020-12-10 06:52:56 +00:00
|
|
|
#[api(
|
|
|
|
input: {
|
|
|
|
properties: {
|
|
|
|
drive: {
|
2020-12-13 08:18:16 +00:00
|
|
|
schema: DRIVE_NAME_SCHEMA,
|
2020-12-10 06:52:56 +00:00
|
|
|
optional: true,
|
|
|
|
},
|
2021-01-13 12:26:59 +00:00
|
|
|
"label-text": {
|
2020-12-10 06:52:56 +00:00
|
|
|
schema: MEDIA_LABEL_SCHEMA,
|
|
|
|
},
|
2021-02-18 08:04:51 +00:00
|
|
|
"output-format": {
|
|
|
|
schema: OUTPUT_FORMAT,
|
|
|
|
optional: true,
|
|
|
|
},
|
2020-12-10 06:52:56 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
)]
|
2021-01-07 13:26:43 +00:00
|
|
|
/// Load media with specified label
|
2021-02-11 13:11:17 +00:00
|
|
|
async fn load_media(mut param: Value) -> Result<(), Error> {
|
2020-12-10 06:52:56 +00:00
|
|
|
|
2021-04-30 12:51:56 +00:00
|
|
|
let output_format = extract_output_format(&mut param);
|
2021-02-18 08:04:51 +00:00
|
|
|
|
2021-09-03 07:10:18 +00:00
|
|
|
let (config, _digest) = pbs_config::drive::config()?;
|
2020-12-10 06:52:56 +00:00
|
|
|
|
2021-02-11 13:11:17 +00:00
|
|
|
let drive = extract_drive_name(&mut param, &config)?;
|
2020-12-10 06:52:56 +00:00
|
|
|
|
2021-01-29 09:50:11 +00:00
|
|
|
let mut client = connect_to_localhost()?;
|
2020-12-10 06:52:56 +00:00
|
|
|
|
2021-01-29 09:50:11 +00:00
|
|
|
let path = format!("api2/json/tape/drive/{}/load-media", drive);
|
2021-02-18 08:04:51 +00:00
|
|
|
let result = client.post(&path, Some(param)).await?;
|
|
|
|
|
|
|
|
view_task_result(&mut client, result, &output_format).await?;
|
2020-12-10 06:52:56 +00:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2021-01-10 12:44:44 +00:00
|
|
|
#[api(
|
|
|
|
input: {
|
|
|
|
properties: {
|
|
|
|
drive: {
|
|
|
|
schema: DRIVE_NAME_SCHEMA,
|
|
|
|
optional: true,
|
|
|
|
},
|
2021-01-13 12:26:59 +00:00
|
|
|
"label-text": {
|
2021-01-10 12:44:44 +00:00
|
|
|
schema: MEDIA_LABEL_SCHEMA,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)]
|
|
|
|
/// Export media with specified label
|
2021-02-11 13:11:17 +00:00
|
|
|
async fn export_media(mut param: Value) -> Result<(), Error> {
|
2021-01-10 12:44:44 +00:00
|
|
|
|
2021-09-03 07:10:18 +00:00
|
|
|
let (config, _digest) = pbs_config::drive::config()?;
|
2021-01-10 12:44:44 +00:00
|
|
|
|
2021-02-11 13:11:17 +00:00
|
|
|
let drive = extract_drive_name(&mut param, &config)?;
|
2021-01-10 12:44:44 +00:00
|
|
|
|
2021-01-29 09:50:11 +00:00
|
|
|
let mut client = connect_to_localhost()?;
|
2021-01-10 12:44:44 +00:00
|
|
|
|
2021-01-29 09:50:11 +00:00
|
|
|
let path = format!("api2/json/tape/drive/{}/export-media", drive);
|
|
|
|
client.put(&path, Some(param)).await?;
|
2021-01-10 12:44:44 +00:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2021-01-07 13:26:43 +00:00
|
|
|
#[api(
|
|
|
|
input: {
|
|
|
|
properties: {
|
|
|
|
drive: {
|
|
|
|
schema: DRIVE_NAME_SCHEMA,
|
|
|
|
optional: true,
|
|
|
|
},
|
|
|
|
"source-slot": {
|
|
|
|
description: "Source slot number.",
|
|
|
|
type: u64,
|
|
|
|
minimum: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)]
|
|
|
|
/// Load media from the specified slot
|
2021-02-11 13:11:17 +00:00
|
|
|
async fn load_media_from_slot(mut param: Value) -> Result<(), Error> {
|
2021-01-07 13:26:43 +00:00
|
|
|
|
2021-09-03 07:10:18 +00:00
|
|
|
let (config, _digest) = pbs_config::drive::config()?;
|
2021-01-07 13:26:43 +00:00
|
|
|
|
2021-02-11 13:11:17 +00:00
|
|
|
let drive = extract_drive_name(&mut param, &config)?;
|
2021-01-07 13:26:43 +00:00
|
|
|
|
2021-01-29 09:50:11 +00:00
|
|
|
let mut client = connect_to_localhost()?;
|
2021-01-07 13:26:43 +00:00
|
|
|
|
2021-01-29 09:50:11 +00:00
|
|
|
let path = format!("api2/json/tape/drive/{}/load-slot", drive);
|
|
|
|
client.put(&path, Some(param)).await?;
|
2021-01-07 13:26:43 +00:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[api(
|
|
|
|
input: {
|
|
|
|
properties: {
|
|
|
|
drive: {
|
|
|
|
schema: DRIVE_NAME_SCHEMA,
|
|
|
|
optional: true,
|
|
|
|
},
|
|
|
|
"target-slot": {
|
|
|
|
description: "Target slot number. If omitted, defaults to the slot that the drive was loaded from.",
|
|
|
|
type: u64,
|
|
|
|
minimum: 1,
|
|
|
|
optional: true,
|
|
|
|
},
|
2021-02-18 08:04:51 +00:00
|
|
|
"output-format": {
|
|
|
|
schema: OUTPUT_FORMAT,
|
|
|
|
optional: true,
|
|
|
|
},
|
2021-01-07 13:26:43 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
)]
|
|
|
|
/// Unload media via changer
|
2021-02-11 13:11:17 +00:00
|
|
|
async fn unload_media(mut param: Value) -> Result<(), Error> {
|
2021-01-07 13:26:43 +00:00
|
|
|
|
2021-04-30 12:51:56 +00:00
|
|
|
let output_format = extract_output_format(&mut param);
|
2021-02-18 08:04:51 +00:00
|
|
|
|
2021-09-03 07:10:18 +00:00
|
|
|
let (config, _digest) = pbs_config::drive::config()?;
|
2021-01-07 13:26:43 +00:00
|
|
|
|
2021-02-11 13:11:17 +00:00
|
|
|
let drive = extract_drive_name(&mut param, &config)?;
|
2021-01-07 13:26:43 +00:00
|
|
|
|
2021-01-29 09:50:11 +00:00
|
|
|
let mut client = connect_to_localhost()?;
|
2021-01-07 13:26:43 +00:00
|
|
|
|
2021-01-29 09:50:11 +00:00
|
|
|
let path = format!("api2/json/tape/drive/{}/unload", drive);
|
2021-02-18 08:04:51 +00:00
|
|
|
let result = client.post(&path, Some(param)).await?;
|
|
|
|
|
|
|
|
view_task_result(&mut client, result, &output_format).await?;
|
2021-01-07 13:26:43 +00:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2020-12-10 11:30:27 +00:00
|
|
|
#[api(
|
|
|
|
input: {
|
|
|
|
properties: {
|
|
|
|
pool: {
|
|
|
|
schema: MEDIA_POOL_NAME_SCHEMA,
|
|
|
|
optional: true,
|
|
|
|
},
|
|
|
|
drive: {
|
2020-12-13 08:18:16 +00:00
|
|
|
schema: DRIVE_NAME_SCHEMA,
|
2020-12-10 11:30:27 +00:00
|
|
|
optional: true,
|
|
|
|
},
|
2021-01-13 12:26:59 +00:00
|
|
|
"label-text": {
|
2020-12-10 11:30:27 +00:00
|
|
|
schema: MEDIA_LABEL_SCHEMA,
|
|
|
|
},
|
2021-01-29 09:50:11 +00:00
|
|
|
"output-format": {
|
|
|
|
schema: OUTPUT_FORMAT,
|
|
|
|
optional: true,
|
|
|
|
},
|
|
|
|
},
|
2020-12-10 11:30:27 +00:00
|
|
|
},
|
|
|
|
)]
|
|
|
|
/// Label media
|
2021-02-11 13:11:17 +00:00
|
|
|
async fn label_media(mut param: Value) -> Result<(), Error> {
|
2021-01-29 09:50:11 +00:00
|
|
|
|
2021-04-30 12:51:56 +00:00
|
|
|
let output_format = extract_output_format(&mut param);
|
2020-12-10 11:30:27 +00:00
|
|
|
|
2021-09-03 07:10:18 +00:00
|
|
|
let (config, _digest) = pbs_config::drive::config()?;
|
2020-12-10 11:30:27 +00:00
|
|
|
|
2021-02-11 13:11:17 +00:00
|
|
|
let drive = extract_drive_name(&mut param, &config)?;
|
2020-12-10 11:30:27 +00:00
|
|
|
|
2021-01-29 09:50:11 +00:00
|
|
|
let mut client = connect_to_localhost()?;
|
2020-12-10 11:30:27 +00:00
|
|
|
|
2021-01-29 09:50:11 +00:00
|
|
|
let path = format!("api2/json/tape/drive/{}/label-media", drive);
|
|
|
|
let result = client.post(&path, Some(param)).await?;
|
2020-12-10 11:30:27 +00:00
|
|
|
|
2021-01-29 10:21:57 +00:00
|
|
|
view_task_result(&mut client, result, &output_format).await?;
|
2020-12-11 08:10:22 +00:00
|
|
|
|
2020-12-10 11:30:27 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2020-12-10 12:20:39 +00:00
|
|
|
#[api(
|
|
|
|
input: {
|
|
|
|
properties: {
|
|
|
|
drive: {
|
2020-12-13 08:18:16 +00:00
|
|
|
schema: DRIVE_NAME_SCHEMA,
|
2020-12-10 12:20:39 +00:00
|
|
|
optional: true,
|
|
|
|
},
|
2021-01-14 10:51:23 +00:00
|
|
|
inventorize: {
|
|
|
|
description: "Inventorize media",
|
|
|
|
type: bool,
|
|
|
|
optional: true,
|
|
|
|
},
|
|
|
|
"output-format": {
|
2020-12-10 12:20:39 +00:00
|
|
|
schema: OUTPUT_FORMAT,
|
|
|
|
optional: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)]
|
|
|
|
/// Read media label
|
2021-02-11 13:11:17 +00:00
|
|
|
async fn read_label(mut param: Value) -> Result<(), Error> {
|
2021-01-29 09:50:11 +00:00
|
|
|
|
2021-04-30 12:51:56 +00:00
|
|
|
let output_format = extract_output_format(&mut param);
|
2020-12-11 06:39:28 +00:00
|
|
|
|
2021-09-03 07:10:18 +00:00
|
|
|
let (config, _digest) = pbs_config::drive::config()?;
|
2020-12-10 12:20:39 +00:00
|
|
|
|
2021-02-11 13:11:17 +00:00
|
|
|
let drive = extract_drive_name(&mut param, &config)?;
|
2021-01-29 09:50:11 +00:00
|
|
|
|
|
|
|
let client = connect_to_localhost()?;
|
|
|
|
|
|
|
|
let path = format!("api2/json/tape/drive/{}/read-label", drive);
|
|
|
|
let mut result = client.get(&path, Some(param)).await?;
|
|
|
|
let mut data = result["data"].take();
|
2020-12-10 12:20:39 +00:00
|
|
|
|
|
|
|
let info = &api2::tape::drive::API_METHOD_READ_LABEL;
|
|
|
|
|
|
|
|
let options = default_table_format_options()
|
2021-01-13 12:26:59 +00:00
|
|
|
.column(ColumnConfig::new("label-text"))
|
2020-12-10 12:20:39 +00:00
|
|
|
.column(ColumnConfig::new("uuid"))
|
|
|
|
.column(ColumnConfig::new("ctime").renderer(render_epoch))
|
|
|
|
.column(ColumnConfig::new("pool"))
|
|
|
|
.column(ColumnConfig::new("media-set-uuid"))
|
|
|
|
.column(ColumnConfig::new("media-set-ctime").renderer(render_epoch))
|
2021-01-18 12:36:11 +00:00
|
|
|
.column(ColumnConfig::new("encryption-key-fingerprint"))
|
2020-12-10 12:20:39 +00:00
|
|
|
;
|
|
|
|
|
2020-12-18 11:26:07 +00:00
|
|
|
format_and_print_result_full(&mut data, &info.returns, &output_format, &options);
|
2020-12-10 12:20:39 +00:00
|
|
|
|
|
|
|
Ok(())
|
2020-12-11 06:39:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[api(
|
|
|
|
input: {
|
|
|
|
properties: {
|
|
|
|
"output-format": {
|
|
|
|
schema: OUTPUT_FORMAT,
|
|
|
|
optional: true,
|
|
|
|
},
|
|
|
|
drive: {
|
2020-12-13 08:18:16 +00:00
|
|
|
schema: DRIVE_NAME_SCHEMA,
|
2020-12-11 06:39:28 +00:00
|
|
|
optional: true,
|
|
|
|
},
|
|
|
|
"read-labels": {
|
|
|
|
description: "Load unknown tapes and try read labels",
|
|
|
|
type: bool,
|
|
|
|
optional: true,
|
|
|
|
},
|
|
|
|
"read-all-labels": {
|
|
|
|
description: "Load all tapes and try read labels (even if already inventoried)",
|
|
|
|
type: bool,
|
|
|
|
optional: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)]
|
2020-12-11 09:42:29 +00:00
|
|
|
/// List (and update) media labels (Changer Inventory)
|
|
|
|
async fn inventory(
|
|
|
|
read_labels: Option<bool>,
|
|
|
|
read_all_labels: Option<bool>,
|
2021-02-11 13:11:17 +00:00
|
|
|
mut param: Value,
|
2020-12-11 06:39:28 +00:00
|
|
|
) -> Result<(), Error> {
|
|
|
|
|
2021-04-30 12:51:56 +00:00
|
|
|
let output_format = extract_output_format(&mut param);
|
2020-12-11 09:42:29 +00:00
|
|
|
|
2021-09-03 07:10:18 +00:00
|
|
|
let (config, _digest) = pbs_config::drive::config()?;
|
2021-02-11 13:11:17 +00:00
|
|
|
let drive = extract_drive_name(&mut param, &config)?;
|
2020-12-11 06:39:28 +00:00
|
|
|
|
2020-12-11 09:42:29 +00:00
|
|
|
let do_read = read_labels.unwrap_or(false) || read_all_labels.unwrap_or(false);
|
|
|
|
|
2021-01-29 10:21:57 +00:00
|
|
|
let mut client = connect_to_localhost()?;
|
|
|
|
|
|
|
|
let path = format!("api2/json/tape/drive/{}/inventory", drive);
|
|
|
|
|
2020-12-11 09:42:29 +00:00
|
|
|
if do_read {
|
2021-01-29 10:21:57 +00:00
|
|
|
|
|
|
|
let mut param = json!({});
|
2020-12-11 09:42:29 +00:00
|
|
|
if let Some(true) = read_all_labels {
|
|
|
|
param["read-all-labels"] = true.into();
|
|
|
|
}
|
2021-01-29 10:21:57 +00:00
|
|
|
|
|
|
|
let result = client.put(&path, Some(param)).await?; // update inventory
|
|
|
|
view_task_result(&mut client, result, &output_format).await?;
|
2020-12-11 09:42:29 +00:00
|
|
|
}
|
2020-12-11 06:39:28 +00:00
|
|
|
|
2021-01-29 10:21:57 +00:00
|
|
|
let mut result = client.get(&path, None).await?;
|
|
|
|
let mut data = result["data"].take();
|
2020-12-11 09:42:29 +00:00
|
|
|
|
2021-01-29 10:21:57 +00:00
|
|
|
let info = &api2::tape::drive::API_METHOD_INVENTORY;
|
2020-12-10 12:20:39 +00:00
|
|
|
|
2020-12-11 06:39:28 +00:00
|
|
|
let options = default_table_format_options()
|
2021-01-13 12:26:59 +00:00
|
|
|
.column(ColumnConfig::new("label-text"))
|
2020-12-11 06:39:28 +00:00
|
|
|
.column(ColumnConfig::new("uuid"))
|
|
|
|
;
|
|
|
|
|
2020-12-18 11:26:07 +00:00
|
|
|
format_and_print_result_full(&mut data, &info.returns, &output_format, &options);
|
2020-12-11 06:39:28 +00:00
|
|
|
|
|
|
|
Ok(())
|
2020-12-10 12:20:39 +00:00
|
|
|
}
|
2020-12-11 06:39:28 +00:00
|
|
|
|
2020-12-11 06:50:19 +00:00
|
|
|
#[api(
|
|
|
|
input: {
|
|
|
|
properties: {
|
|
|
|
pool: {
|
|
|
|
schema: MEDIA_POOL_NAME_SCHEMA,
|
|
|
|
optional: true,
|
|
|
|
},
|
|
|
|
drive: {
|
2020-12-13 08:18:16 +00:00
|
|
|
schema: DRIVE_NAME_SCHEMA,
|
2020-12-11 06:50:19 +00:00
|
|
|
optional: true,
|
|
|
|
},
|
2021-01-29 10:49:11 +00:00
|
|
|
"output-format": {
|
|
|
|
schema: OUTPUT_FORMAT,
|
|
|
|
optional: true,
|
|
|
|
},
|
2020-12-11 06:50:19 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
)]
|
|
|
|
/// Label media with barcodes from changer device
|
2021-02-11 13:11:17 +00:00
|
|
|
async fn barcode_label_media(mut param: Value) -> Result<(), Error> {
|
2021-01-29 10:49:11 +00:00
|
|
|
|
2021-04-30 12:51:56 +00:00
|
|
|
let output_format = extract_output_format(&mut param);
|
2020-12-11 06:50:19 +00:00
|
|
|
|
2021-09-03 07:10:18 +00:00
|
|
|
let (config, _digest) = pbs_config::drive::config()?;
|
2020-12-11 06:50:19 +00:00
|
|
|
|
2021-02-11 13:11:17 +00:00
|
|
|
let drive = extract_drive_name(&mut param, &config)?;
|
2020-12-11 06:50:19 +00:00
|
|
|
|
2021-01-29 10:49:11 +00:00
|
|
|
let mut client = connect_to_localhost()?;
|
2020-12-11 06:50:19 +00:00
|
|
|
|
2021-01-29 10:49:11 +00:00
|
|
|
let path = format!("api2/json/tape/drive/{}/barcode-label-media", drive);
|
|
|
|
let result = client.post(&path, Some(param)).await?;
|
2020-12-11 06:50:19 +00:00
|
|
|
|
2021-01-29 10:49:11 +00:00
|
|
|
view_task_result(&mut client, result, &output_format).await?;
|
2020-12-11 08:10:22 +00:00
|
|
|
|
2020-12-11 06:50:19 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2020-12-14 08:56:59 +00:00
|
|
|
#[api(
|
|
|
|
input: {
|
|
|
|
properties: {
|
|
|
|
drive: {
|
|
|
|
schema: DRIVE_NAME_SCHEMA,
|
|
|
|
optional: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)]
|
|
|
|
/// Move to end of media (MTEOM, used to debug)
|
2021-02-11 13:11:17 +00:00
|
|
|
fn move_to_eom(mut param: Value) -> Result<(), Error> {
|
2020-12-14 08:56:59 +00:00
|
|
|
|
2021-09-03 07:10:18 +00:00
|
|
|
let (config, _digest) = pbs_config::drive::config()?;
|
2020-12-14 08:56:59 +00:00
|
|
|
|
2021-02-11 13:11:17 +00:00
|
|
|
let drive = extract_drive_name(&mut param, &config)?;
|
2021-02-05 09:50:21 +00:00
|
|
|
|
|
|
|
let _lock = lock_tape_device(&config, &drive)?;
|
2021-02-18 14:40:28 +00:00
|
|
|
set_tape_device_state(&drive, "moving to eom")?;
|
2021-02-05 09:50:21 +00:00
|
|
|
|
2020-12-14 08:56:59 +00:00
|
|
|
let mut drive = open_drive(&config, &drive)?;
|
|
|
|
|
2021-04-06 10:17:59 +00:00
|
|
|
drive.move_to_eom(false)?;
|
2020-12-14 08:56:59 +00:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2020-12-14 11:55:49 +00:00
|
|
|
#[api(
|
|
|
|
input: {
|
|
|
|
properties: {
|
|
|
|
drive: {
|
|
|
|
schema: DRIVE_NAME_SCHEMA,
|
|
|
|
optional: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)]
|
|
|
|
/// Rewind, then read media contents and print debug info
|
2020-12-14 12:16:18 +00:00
|
|
|
///
|
|
|
|
/// Note: This reads unless the driver returns an IO Error, so this
|
|
|
|
/// method is expected to fails when we reach EOT.
|
2021-02-11 13:11:17 +00:00
|
|
|
fn debug_scan(mut param: Value) -> Result<(), Error> {
|
2020-12-14 11:55:49 +00:00
|
|
|
|
2021-09-03 07:10:18 +00:00
|
|
|
let (config, _digest) = pbs_config::drive::config()?;
|
2020-12-14 11:55:49 +00:00
|
|
|
|
2021-02-11 13:11:17 +00:00
|
|
|
let drive = extract_drive_name(&mut param, &config)?;
|
2021-02-05 09:50:21 +00:00
|
|
|
|
|
|
|
let _lock = lock_tape_device(&config, &drive)?;
|
2021-02-18 14:40:28 +00:00
|
|
|
set_tape_device_state(&drive, "debug scan")?;
|
2021-02-05 09:50:21 +00:00
|
|
|
|
2020-12-14 11:55:49 +00:00
|
|
|
let mut drive = open_drive(&config, &drive)?;
|
|
|
|
|
|
|
|
println!("rewinding tape");
|
|
|
|
drive.rewind()?;
|
|
|
|
|
|
|
|
loop {
|
|
|
|
let file_number = drive.current_file_number()?;
|
|
|
|
|
2021-04-12 09:25:40 +00:00
|
|
|
match drive.read_next_file() {
|
|
|
|
Err(BlockReadError::EndOfFile) => {
|
|
|
|
println!("filemark number {}", file_number);
|
2020-12-14 11:55:49 +00:00
|
|
|
continue;
|
2021-04-12 09:25:40 +00:00
|
|
|
}
|
|
|
|
Err(BlockReadError::EndOfStream) => {
|
|
|
|
println!("got EOT");
|
|
|
|
return Ok(());
|
|
|
|
}
|
|
|
|
Err(BlockReadError::Error(err)) => {
|
|
|
|
return Err(err.into());
|
|
|
|
}
|
|
|
|
Ok(mut reader) => {
|
2020-12-14 11:55:49 +00:00
|
|
|
println!("got file number {}", file_number);
|
|
|
|
|
|
|
|
let header: Result<MediaContentHeader, _> = unsafe { reader.read_le_value() };
|
|
|
|
match header {
|
|
|
|
Ok(header) => {
|
|
|
|
if header.magic != PROXMOX_BACKUP_CONTENT_HEADER_MAGIC_1_0 {
|
|
|
|
println!("got MediaContentHeader with wrong magic: {:?}", header.magic);
|
2021-02-04 06:58:34 +00:00
|
|
|
} else if let Some(name) = proxmox_tape_magic_to_text(&header.content_magic) {
|
2021-01-19 10:06:26 +00:00
|
|
|
println!("got content header: {}", name);
|
|
|
|
println!(" uuid: {}", header.content_uuid());
|
|
|
|
println!(" ctime: {}", strftime_local("%c", header.ctime)?);
|
|
|
|
println!(" hsize: {}", HumanByte::from(header.size as usize));
|
|
|
|
println!(" part: {}", header.part_number);
|
2020-12-14 11:55:49 +00:00
|
|
|
} else {
|
2021-01-19 10:06:26 +00:00
|
|
|
println!("got unknown content header: {:?}", header.content_magic);
|
2020-12-14 11:55:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Err(err) => {
|
|
|
|
println!("unable to read content header - {}", err);
|
|
|
|
}
|
|
|
|
}
|
2021-04-13 11:11:44 +00:00
|
|
|
let bytes = reader.skip_data()?;
|
2020-12-14 12:16:18 +00:00
|
|
|
println!("skipped {}", HumanByte::from(bytes));
|
2021-04-13 11:11:44 +00:00
|
|
|
if let Ok(true) = reader.has_end_marker() {
|
|
|
|
if reader.is_incomplete()? {
|
|
|
|
println!("WARNING: file is incomplete");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
println!("WARNING: file without end marker");
|
|
|
|
}
|
2020-12-14 11:55:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-21 11:11:52 +00:00
|
|
|
#[api(
|
|
|
|
input: {
|
|
|
|
properties: {
|
|
|
|
drive: {
|
|
|
|
schema: DRIVE_NAME_SCHEMA,
|
|
|
|
optional: true,
|
|
|
|
},
|
2021-01-29 10:49:11 +00:00
|
|
|
"output-format": {
|
2020-12-21 11:11:52 +00:00
|
|
|
schema: OUTPUT_FORMAT,
|
|
|
|
optional: true,
|
2021-01-29 10:49:11 +00:00
|
|
|
},
|
2020-12-21 11:11:52 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
)]
|
2020-12-22 08:27:34 +00:00
|
|
|
/// Read Cartridge Memory (Medium auxiliary memory attributes)
|
2021-02-11 13:11:17 +00:00
|
|
|
async fn cartridge_memory(mut param: Value) -> Result<(), Error> {
|
2021-01-29 10:49:11 +00:00
|
|
|
|
2021-04-30 12:51:56 +00:00
|
|
|
let output_format = extract_output_format(&mut param);
|
2020-12-21 11:11:52 +00:00
|
|
|
|
2021-09-03 07:10:18 +00:00
|
|
|
let (config, _digest) = pbs_config::drive::config()?;
|
2020-12-21 11:11:52 +00:00
|
|
|
|
2021-02-11 13:11:17 +00:00
|
|
|
let drive = extract_drive_name(&mut param, &config)?;
|
2020-12-21 11:11:52 +00:00
|
|
|
|
2021-01-29 10:49:11 +00:00
|
|
|
let client = connect_to_localhost()?;
|
2020-12-21 11:11:52 +00:00
|
|
|
|
2021-01-29 10:49:11 +00:00
|
|
|
let path = format!("api2/json/tape/drive/{}/cartridge-memory", drive);
|
|
|
|
let mut result = client.get(&path, Some(param)).await?;
|
|
|
|
let mut data = result["data"].take();
|
|
|
|
|
|
|
|
let info = &api2::tape::drive::API_METHOD_CARTRIDGE_MEMORY;
|
2020-12-21 11:11:52 +00:00
|
|
|
|
|
|
|
let options = default_table_format_options()
|
|
|
|
.column(ColumnConfig::new("id"))
|
|
|
|
.column(ColumnConfig::new("name"))
|
|
|
|
.column(ColumnConfig::new("value"))
|
|
|
|
;
|
|
|
|
|
2020-12-22 07:52:24 +00:00
|
|
|
format_and_print_result_full(&mut data, &info.returns, &output_format, &options);
|
2020-12-21 11:11:52 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2021-01-22 07:45:35 +00:00
|
|
|
#[api(
|
|
|
|
input: {
|
|
|
|
properties: {
|
|
|
|
drive: {
|
|
|
|
schema: DRIVE_NAME_SCHEMA,
|
|
|
|
optional: true,
|
|
|
|
},
|
2021-01-29 10:49:11 +00:00
|
|
|
"output-format": {
|
2021-01-22 07:45:35 +00:00
|
|
|
schema: OUTPUT_FORMAT,
|
|
|
|
optional: true,
|
2021-01-29 10:49:11 +00:00
|
|
|
},
|
2021-01-22 07:45:35 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
)]
|
|
|
|
/// Read Volume Statistics (SCSI log page 17h)
|
2021-02-11 13:11:17 +00:00
|
|
|
async fn volume_statistics(mut param: Value) -> Result<(), Error> {
|
2021-01-29 10:49:11 +00:00
|
|
|
|
2021-04-30 12:51:56 +00:00
|
|
|
let output_format = extract_output_format(&mut param);
|
2021-01-22 07:45:35 +00:00
|
|
|
|
2021-09-03 07:10:18 +00:00
|
|
|
let (config, _digest) = pbs_config::drive::config()?;
|
2021-01-22 07:45:35 +00:00
|
|
|
|
2021-02-11 13:11:17 +00:00
|
|
|
let drive = extract_drive_name(&mut param, &config)?;
|
2021-01-22 07:45:35 +00:00
|
|
|
|
2021-01-29 10:49:11 +00:00
|
|
|
let client = connect_to_localhost()?;
|
2021-01-22 07:45:35 +00:00
|
|
|
|
2021-01-29 10:49:11 +00:00
|
|
|
let path = format!("api2/json/tape/drive/{}/volume-statistics", drive);
|
|
|
|
let mut result = client.get(&path, Some(param)).await?;
|
|
|
|
let mut data = result["data"].take();
|
|
|
|
|
|
|
|
let info = &api2::tape::drive::API_METHOD_VOLUME_STATISTICS;
|
2021-01-22 07:45:35 +00:00
|
|
|
|
|
|
|
let options = default_table_format_options();
|
|
|
|
|
|
|
|
format_and_print_result_full(&mut data, &info.returns, &output_format, &options);
|
2021-01-29 10:49:11 +00:00
|
|
|
|
2021-01-22 07:45:35 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2020-12-22 09:42:22 +00:00
|
|
|
#[api(
|
|
|
|
input: {
|
|
|
|
properties: {
|
|
|
|
drive: {
|
|
|
|
schema: DRIVE_NAME_SCHEMA,
|
|
|
|
optional: true,
|
|
|
|
},
|
|
|
|
"output-format": {
|
|
|
|
schema: OUTPUT_FORMAT,
|
|
|
|
optional: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)]
|
2020-12-23 10:24:34 +00:00
|
|
|
/// Get drive/media status
|
2021-02-11 13:11:17 +00:00
|
|
|
async fn status(mut param: Value) -> Result<(), Error> {
|
2021-01-29 10:49:11 +00:00
|
|
|
|
2021-04-30 12:51:56 +00:00
|
|
|
let output_format = extract_output_format(&mut param);
|
2020-12-22 09:42:22 +00:00
|
|
|
|
2021-09-03 07:10:18 +00:00
|
|
|
let (config, _digest) = pbs_config::drive::config()?;
|
2020-12-22 09:42:22 +00:00
|
|
|
|
2021-02-11 13:11:17 +00:00
|
|
|
let drive = extract_drive_name(&mut param, &config)?;
|
2020-12-22 09:42:22 +00:00
|
|
|
|
2021-01-29 10:49:11 +00:00
|
|
|
let client = connect_to_localhost()?;
|
2020-12-22 09:42:22 +00:00
|
|
|
|
2021-01-29 10:49:11 +00:00
|
|
|
let path = format!("api2/json/tape/drive/{}/status", drive);
|
|
|
|
let mut result = client.get(&path, Some(param)).await?;
|
|
|
|
let mut data = result["data"].take();
|
|
|
|
|
|
|
|
let info = &api2::tape::drive::API_METHOD_STATUS;
|
2020-12-22 09:42:22 +00:00
|
|
|
|
2021-01-22 07:06:25 +00:00
|
|
|
let render_percentage = |value: &Value, _record: &Value| {
|
|
|
|
match value.as_f64() {
|
|
|
|
Some(wearout) => Ok(format!("{:.2}%", wearout*100.0)),
|
|
|
|
None => Ok(String::from("ERROR")), // should never happen
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-12-22 09:42:22 +00:00
|
|
|
let options = default_table_format_options()
|
|
|
|
.column(ColumnConfig::new("blocksize"))
|
|
|
|
.column(ColumnConfig::new("density"))
|
2021-04-07 09:11:35 +00:00
|
|
|
.column(ColumnConfig::new("compression"))
|
|
|
|
.column(ColumnConfig::new("buffer-mode"))
|
|
|
|
.column(ColumnConfig::new("write-protect"))
|
2021-01-04 12:15:30 +00:00
|
|
|
.column(ColumnConfig::new("alert-flags"))
|
2020-12-22 09:42:22 +00:00
|
|
|
.column(ColumnConfig::new("file-number"))
|
|
|
|
.column(ColumnConfig::new("block-number"))
|
2020-12-23 10:24:34 +00:00
|
|
|
.column(ColumnConfig::new("manufactured").renderer(render_epoch))
|
|
|
|
.column(ColumnConfig::new("bytes-written").renderer(render_bytes_human_readable))
|
|
|
|
.column(ColumnConfig::new("bytes-read").renderer(render_bytes_human_readable))
|
2021-01-05 12:43:17 +00:00
|
|
|
.column(ColumnConfig::new("medium-passes"))
|
2021-01-22 07:06:25 +00:00
|
|
|
.column(ColumnConfig::new("medium-wearout").renderer(render_percentage))
|
2021-01-05 12:43:17 +00:00
|
|
|
.column(ColumnConfig::new("volume-mounts"))
|
2020-12-22 09:42:22 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
format_and_print_result_full(&mut data, &info.returns, &output_format, &options);
|
2021-01-29 10:49:11 +00:00
|
|
|
|
2020-12-22 09:42:22 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2021-01-08 10:32:56 +00:00
|
|
|
#[api(
|
|
|
|
input: {
|
|
|
|
properties: {
|
|
|
|
drive: {
|
|
|
|
schema: DRIVE_NAME_SCHEMA,
|
|
|
|
optional: true,
|
|
|
|
},
|
2021-01-29 10:49:11 +00:00
|
|
|
"output-format": {
|
|
|
|
schema: OUTPUT_FORMAT,
|
|
|
|
optional: true,
|
|
|
|
},
|
2021-01-08 10:32:56 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
)]
|
|
|
|
/// Clean drive
|
2021-02-11 13:11:17 +00:00
|
|
|
async fn clean_drive(mut param: Value) -> Result<(), Error> {
|
2021-01-29 10:49:11 +00:00
|
|
|
|
2021-04-30 12:51:56 +00:00
|
|
|
let output_format = extract_output_format(&mut param);
|
2021-01-08 10:32:56 +00:00
|
|
|
|
2021-09-03 07:10:18 +00:00
|
|
|
let (config, _digest) = pbs_config::drive::config()?;
|
2021-01-08 10:32:56 +00:00
|
|
|
|
2021-02-11 13:11:17 +00:00
|
|
|
let drive = extract_drive_name(&mut param, &config)?;
|
2021-01-08 10:32:56 +00:00
|
|
|
|
2021-01-29 10:49:11 +00:00
|
|
|
let mut client = connect_to_localhost()?;
|
2021-01-08 10:32:56 +00:00
|
|
|
|
2021-03-24 13:10:15 +00:00
|
|
|
let path = format!("api2/json/tape/drive/{}/clean", drive);
|
|
|
|
let result = client.put(&path, Some(param)).await?;
|
2021-01-08 10:32:56 +00:00
|
|
|
|
2021-01-29 10:49:11 +00:00
|
|
|
view_task_result(&mut client, result, &output_format).await?;
|
2021-01-08 10:32:56 +00:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2020-12-18 14:32:12 +00:00
|
|
|
#[api(
|
2021-02-24 17:12:11 +00:00
|
|
|
input: {
|
2020-12-18 14:32:12 +00:00
|
|
|
properties: {
|
2021-02-26 07:51:24 +00:00
|
|
|
|
|
|
|
// Note: We cannot use TapeBackupJobSetup, because drive needs to be optional here
|
|
|
|
//setup: {
|
|
|
|
// type: TapeBackupJobSetup,
|
|
|
|
// flatten: true,
|
|
|
|
//},
|
|
|
|
|
|
|
|
store: {
|
|
|
|
schema: DATASTORE_SCHEMA,
|
|
|
|
},
|
|
|
|
pool: {
|
|
|
|
schema: MEDIA_POOL_NAME_SCHEMA,
|
|
|
|
},
|
|
|
|
drive: {
|
|
|
|
schema: DRIVE_NAME_SCHEMA,
|
|
|
|
optional: true,
|
|
|
|
},
|
|
|
|
"eject-media": {
|
|
|
|
description: "Eject media upon job completion.",
|
|
|
|
type: bool,
|
|
|
|
optional: true,
|
|
|
|
},
|
|
|
|
"export-media-set": {
|
|
|
|
description: "Export media set upon job completion.",
|
|
|
|
type: bool,
|
|
|
|
optional: true,
|
|
|
|
},
|
|
|
|
"latest-only": {
|
|
|
|
description: "Backup latest snapshots only.",
|
|
|
|
type: bool,
|
|
|
|
optional: true,
|
2021-01-10 10:59:55 +00:00
|
|
|
},
|
2021-11-04 09:56:18 +00:00
|
|
|
"notify-user": {
|
|
|
|
optional: true,
|
|
|
|
type: Userid,
|
|
|
|
},
|
2021-11-04 09:56:22 +00:00
|
|
|
groups: {
|
|
|
|
schema: GROUP_FILTER_LIST_SCHEMA,
|
|
|
|
optional: true,
|
|
|
|
},
|
2021-09-10 07:41:57 +00:00
|
|
|
"force-media-set": {
|
|
|
|
description: "Ignore the allocation policy and start a new media-set.",
|
|
|
|
optional: true,
|
|
|
|
type: bool,
|
|
|
|
default: false,
|
|
|
|
},
|
2021-01-28 13:56:42 +00:00
|
|
|
"output-format": {
|
|
|
|
schema: OUTPUT_FORMAT,
|
|
|
|
optional: true,
|
|
|
|
},
|
2020-12-18 14:32:12 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
)]
|
|
|
|
/// Backup datastore to tape media pool
|
2021-02-01 08:14:28 +00:00
|
|
|
async fn backup(mut param: Value) -> Result<(), Error> {
|
2020-12-18 14:32:12 +00:00
|
|
|
|
2021-04-30 12:51:56 +00:00
|
|
|
let output_format = extract_output_format(&mut param);
|
2020-12-18 14:32:12 +00:00
|
|
|
|
2021-09-03 07:10:18 +00:00
|
|
|
let (config, _digest) = pbs_config::drive::config()?;
|
2021-02-01 08:14:28 +00:00
|
|
|
|
2021-02-11 13:11:17 +00:00
|
|
|
param["drive"] = extract_drive_name(&mut param, &config)?.into();
|
2021-02-01 08:14:28 +00:00
|
|
|
|
2021-01-28 13:56:42 +00:00
|
|
|
let mut client = connect_to_localhost()?;
|
2020-12-18 14:32:12 +00:00
|
|
|
|
2021-01-28 13:56:42 +00:00
|
|
|
let result = client.post("api2/json/tape/backup", Some(param)).await?;
|
|
|
|
|
2021-01-29 10:21:57 +00:00
|
|
|
view_task_result(&mut client, result, &output_format).await?;
|
2020-12-18 14:32:12 +00:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
2021-01-29 10:49:11 +00:00
|
|
|
|
2020-12-31 09:26:48 +00:00
|
|
|
#[api(
|
|
|
|
input: {
|
|
|
|
properties: {
|
|
|
|
store: {
|
2021-03-24 13:10:14 +00:00
|
|
|
schema: DATASTORE_MAP_LIST_SCHEMA,
|
2020-12-31 09:26:48 +00:00
|
|
|
},
|
2021-02-01 08:14:28 +00:00
|
|
|
drive: {
|
|
|
|
schema: DRIVE_NAME_SCHEMA,
|
|
|
|
optional: true,
|
|
|
|
},
|
2020-12-31 09:26:48 +00:00
|
|
|
"media-set": {
|
|
|
|
description: "Media set UUID.",
|
|
|
|
type: String,
|
|
|
|
},
|
2021-03-12 10:28:40 +00:00
|
|
|
"notify-user": {
|
|
|
|
type: Userid,
|
|
|
|
optional: true,
|
|
|
|
},
|
2021-05-11 10:50:06 +00:00
|
|
|
"snapshots": {
|
|
|
|
description: "List of snapshots.",
|
|
|
|
type: Array,
|
|
|
|
optional: true,
|
|
|
|
items: {
|
|
|
|
schema: TAPE_RESTORE_SNAPSHOT_SCHEMA,
|
|
|
|
},
|
|
|
|
},
|
2021-03-12 10:28:41 +00:00
|
|
|
owner: {
|
|
|
|
type: Authid,
|
|
|
|
optional: true,
|
|
|
|
},
|
2021-01-29 10:49:11 +00:00
|
|
|
"output-format": {
|
|
|
|
schema: OUTPUT_FORMAT,
|
|
|
|
optional: true,
|
|
|
|
},
|
2020-12-31 09:26:48 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
)]
|
|
|
|
/// Restore data from media-set
|
2021-02-01 08:14:28 +00:00
|
|
|
async fn restore(mut param: Value) -> Result<(), Error> {
|
2021-01-29 10:49:11 +00:00
|
|
|
|
2021-04-30 12:51:56 +00:00
|
|
|
let output_format = extract_output_format(&mut param);
|
2020-12-31 09:26:48 +00:00
|
|
|
|
2021-09-03 07:10:18 +00:00
|
|
|
let (config, _digest) = pbs_config::drive::config()?;
|
2021-02-01 08:14:28 +00:00
|
|
|
|
2021-02-11 13:11:17 +00:00
|
|
|
param["drive"] = extract_drive_name(&mut param, &config)?.into();
|
2021-02-01 08:14:28 +00:00
|
|
|
|
2021-01-29 10:49:11 +00:00
|
|
|
let mut client = connect_to_localhost()?;
|
2020-12-31 09:26:48 +00:00
|
|
|
|
2021-01-29 10:49:11 +00:00
|
|
|
let result = client.post("api2/json/tape/restore", Some(param)).await?;
|
2020-12-31 09:26:48 +00:00
|
|
|
|
2021-01-29 10:49:11 +00:00
|
|
|
view_task_result(&mut client, result, &output_format).await?;
|
2020-12-31 09:26:48 +00:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
2020-12-18 14:32:12 +00:00
|
|
|
|
2020-12-30 08:48:18 +00:00
|
|
|
#[api(
|
|
|
|
input: {
|
|
|
|
properties: {
|
|
|
|
drive: {
|
|
|
|
schema: DRIVE_NAME_SCHEMA,
|
|
|
|
optional: true,
|
|
|
|
},
|
|
|
|
force: {
|
|
|
|
description: "Force overriding existing index.",
|
|
|
|
type: bool,
|
|
|
|
optional: true,
|
|
|
|
},
|
2021-03-25 12:08:34 +00:00
|
|
|
scan: {
|
|
|
|
description: "Re-read the whole tape to reconstruct the catalog instead of restoring saved versions.",
|
|
|
|
type: bool,
|
|
|
|
optional: true,
|
|
|
|
},
|
2020-12-30 08:48:18 +00:00
|
|
|
verbose: {
|
|
|
|
description: "Verbose mode - log all found chunks.",
|
|
|
|
type: bool,
|
|
|
|
optional: true,
|
|
|
|
},
|
|
|
|
"output-format": {
|
|
|
|
schema: OUTPUT_FORMAT,
|
|
|
|
optional: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)]
|
|
|
|
/// Scan media and record content
|
2021-02-11 13:11:17 +00:00
|
|
|
async fn catalog_media(mut param: Value) -> Result<(), Error> {
|
2021-01-29 10:49:11 +00:00
|
|
|
|
2021-04-30 12:51:56 +00:00
|
|
|
let output_format = extract_output_format(&mut param);
|
2020-12-30 08:48:18 +00:00
|
|
|
|
2021-09-03 07:10:18 +00:00
|
|
|
let (config, _digest) = pbs_config::drive::config()?;
|
2020-12-30 08:48:18 +00:00
|
|
|
|
2021-02-11 13:11:17 +00:00
|
|
|
let drive = extract_drive_name(&mut param, &config)?;
|
2020-12-30 08:48:18 +00:00
|
|
|
|
2021-01-29 10:49:11 +00:00
|
|
|
let mut client = connect_to_localhost()?;
|
2020-12-30 08:48:18 +00:00
|
|
|
|
2021-01-29 10:49:11 +00:00
|
|
|
let path = format!("api2/json/tape/drive/{}/catalog", drive);
|
|
|
|
let result = client.post(&path, Some(param)).await?;
|
2020-12-30 08:48:18 +00:00
|
|
|
|
2021-01-29 10:49:11 +00:00
|
|
|
view_task_result(&mut client, result, &output_format).await?;
|
2020-12-30 08:48:18 +00:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2020-12-09 11:58:43 +00:00
|
|
|
fn main() {
|
|
|
|
|
|
|
|
let cmd_def = CliCommandMap::new()
|
2020-12-18 14:32:12 +00:00
|
|
|
.insert(
|
|
|
|
"backup",
|
|
|
|
CliCommand::new(&API_METHOD_BACKUP)
|
|
|
|
.arg_param(&["store", "pool"])
|
2021-02-24 17:12:11 +00:00
|
|
|
.completion_cb("drive", complete_drive_name)
|
2020-12-18 14:32:12 +00:00
|
|
|
.completion_cb("store", complete_datastore_name)
|
|
|
|
.completion_cb("pool", complete_pool_name)
|
2021-11-04 09:56:22 +00:00
|
|
|
.completion_cb("groups", complete_datastore_group_filter)
|
2020-12-18 14:32:12 +00:00
|
|
|
)
|
2020-12-31 09:26:48 +00:00
|
|
|
.insert(
|
|
|
|
"restore",
|
|
|
|
CliCommand::new(&API_METHOD_RESTORE)
|
2021-05-11 10:50:06 +00:00
|
|
|
.arg_param(&["media-set", "store", "snapshots"])
|
2020-12-31 09:26:48 +00:00
|
|
|
.completion_cb("store", complete_datastore_name)
|
|
|
|
.completion_cb("media-set", complete_media_set_uuid)
|
2021-05-11 10:50:06 +00:00
|
|
|
.completion_cb("snapshots", complete_media_set_snapshots)
|
2020-12-31 09:26:48 +00:00
|
|
|
)
|
2020-12-11 06:50:19 +00:00
|
|
|
.insert(
|
|
|
|
"barcode-label",
|
|
|
|
CliCommand::new(&API_METHOD_BARCODE_LABEL_MEDIA)
|
|
|
|
.completion_cb("drive", complete_drive_name)
|
|
|
|
.completion_cb("pool", complete_pool_name)
|
|
|
|
)
|
2020-12-09 16:43:38 +00:00
|
|
|
.insert(
|
|
|
|
"rewind",
|
|
|
|
CliCommand::new(&API_METHOD_REWIND)
|
|
|
|
.completion_cb("drive", complete_drive_name)
|
|
|
|
)
|
2020-12-14 11:55:49 +00:00
|
|
|
.insert(
|
|
|
|
"scan",
|
|
|
|
CliCommand::new(&API_METHOD_DEBUG_SCAN)
|
|
|
|
.completion_cb("drive", complete_drive_name)
|
|
|
|
)
|
2020-12-22 09:42:22 +00:00
|
|
|
.insert(
|
|
|
|
"status",
|
|
|
|
CliCommand::new(&API_METHOD_STATUS)
|
|
|
|
.completion_cb("drive", complete_drive_name)
|
|
|
|
)
|
2020-12-14 08:56:59 +00:00
|
|
|
.insert(
|
|
|
|
"eod",
|
|
|
|
CliCommand::new(&API_METHOD_MOVE_TO_EOM)
|
|
|
|
.completion_cb("drive", complete_drive_name)
|
|
|
|
)
|
2020-12-09 16:35:31 +00:00
|
|
|
.insert(
|
2021-03-31 07:19:19 +00:00
|
|
|
"format",
|
|
|
|
CliCommand::new(&API_METHOD_FORMAT_MEDIA)
|
2020-12-09 16:35:31 +00:00
|
|
|
.completion_cb("drive", complete_drive_name)
|
|
|
|
)
|
2020-12-09 16:50:48 +00:00
|
|
|
.insert(
|
|
|
|
"eject",
|
|
|
|
CliCommand::new(&API_METHOD_EJECT_MEDIA)
|
|
|
|
.completion_cb("drive", complete_drive_name)
|
2020-12-11 06:39:28 +00:00
|
|
|
)
|
|
|
|
.insert(
|
|
|
|
"inventory",
|
|
|
|
CliCommand::new(&API_METHOD_INVENTORY)
|
|
|
|
.completion_cb("drive", complete_drive_name)
|
2020-12-09 16:50:48 +00:00
|
|
|
)
|
2020-12-10 12:20:39 +00:00
|
|
|
.insert(
|
|
|
|
"read-label",
|
|
|
|
CliCommand::new(&API_METHOD_READ_LABEL)
|
|
|
|
.completion_cb("drive", complete_drive_name)
|
|
|
|
)
|
2020-12-30 08:48:18 +00:00
|
|
|
.insert(
|
|
|
|
"catalog",
|
|
|
|
CliCommand::new(&API_METHOD_CATALOG_MEDIA)
|
|
|
|
.completion_cb("drive", complete_drive_name)
|
|
|
|
)
|
2020-12-21 11:11:52 +00:00
|
|
|
.insert(
|
2020-12-22 08:27:34 +00:00
|
|
|
"cartridge-memory",
|
|
|
|
CliCommand::new(&API_METHOD_CARTRIDGE_MEMORY)
|
2020-12-21 11:11:52 +00:00
|
|
|
.completion_cb("drive", complete_drive_name)
|
|
|
|
)
|
2021-01-22 07:45:35 +00:00
|
|
|
.insert(
|
|
|
|
"volume-statistics",
|
|
|
|
CliCommand::new(&API_METHOD_VOLUME_STATISTICS)
|
|
|
|
.completion_cb("drive", complete_drive_name)
|
|
|
|
)
|
2021-01-08 10:32:56 +00:00
|
|
|
.insert(
|
|
|
|
"clean",
|
|
|
|
CliCommand::new(&API_METHOD_CLEAN_DRIVE)
|
|
|
|
.completion_cb("drive", complete_drive_name)
|
|
|
|
)
|
2020-12-10 11:30:27 +00:00
|
|
|
.insert(
|
|
|
|
"label",
|
|
|
|
CliCommand::new(&API_METHOD_LABEL_MEDIA)
|
|
|
|
.completion_cb("drive", complete_drive_name)
|
|
|
|
.completion_cb("pool", complete_pool_name)
|
|
|
|
|
|
|
|
)
|
2020-12-09 11:58:43 +00:00
|
|
|
.insert("changer", changer_commands())
|
|
|
|
.insert("drive", drive_commands())
|
2020-12-10 10:08:29 +00:00
|
|
|
.insert("pool", pool_commands())
|
2020-12-14 06:55:57 +00:00
|
|
|
.insert("media", media_commands())
|
2021-01-18 06:16:06 +00:00
|
|
|
.insert("key", encryption_key_commands())
|
2021-02-14 09:32:33 +00:00
|
|
|
.insert("backup-job", backup_job_commands())
|
2020-12-10 06:52:56 +00:00
|
|
|
.insert(
|
|
|
|
"load-media",
|
|
|
|
CliCommand::new(&API_METHOD_LOAD_MEDIA)
|
2021-01-13 12:26:59 +00:00
|
|
|
.arg_param(&["label-text"])
|
2020-12-10 06:52:56 +00:00
|
|
|
.completion_cb("drive", complete_drive_name)
|
2021-01-13 12:26:59 +00:00
|
|
|
.completion_cb("label-text", complete_media_label_text)
|
2020-12-10 06:52:56 +00:00
|
|
|
)
|
2021-01-07 13:26:43 +00:00
|
|
|
.insert(
|
|
|
|
"load-media-from-slot",
|
|
|
|
CliCommand::new(&API_METHOD_LOAD_MEDIA_FROM_SLOT)
|
2021-01-07 14:39:25 +00:00
|
|
|
.arg_param(&["source-slot"])
|
2021-01-07 13:26:43 +00:00
|
|
|
.completion_cb("drive", complete_drive_name)
|
|
|
|
)
|
|
|
|
.insert(
|
|
|
|
"unload",
|
|
|
|
CliCommand::new(&API_METHOD_UNLOAD_MEDIA)
|
|
|
|
.completion_cb("drive", complete_drive_name)
|
|
|
|
)
|
2021-01-10 12:44:44 +00:00
|
|
|
.insert(
|
|
|
|
"export-media",
|
|
|
|
CliCommand::new(&API_METHOD_EXPORT_MEDIA)
|
2021-01-13 12:26:59 +00:00
|
|
|
.arg_param(&["label-text"])
|
2021-01-10 12:44:44 +00:00
|
|
|
.completion_cb("drive", complete_drive_name)
|
2021-01-13 12:26:59 +00:00
|
|
|
.completion_cb("label-text", complete_media_label_text)
|
2021-01-10 12:44:44 +00:00
|
|
|
)
|
2020-12-09 11:58:43 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
let mut rpcenv = CliEnvironment::new();
|
|
|
|
rpcenv.set_auth_id(Some(String::from("root@pam")));
|
|
|
|
|
2021-07-06 10:08:44 +00:00
|
|
|
pbs_runtime::main(run_async_cli_command(cmd_def, rpcenv));
|
2020-12-09 11:58:43 +00:00
|
|
|
}
|