2020-12-09 16:35:31 +00:00
|
|
|
use anyhow::{format_err, Error};
|
2020-12-11 09:42:29 +00:00
|
|
|
use serde_json::{json, Value};
|
2020-12-09 16:35:31 +00:00
|
|
|
|
2020-12-09 11:58:43 +00:00
|
|
|
use proxmox::{
|
|
|
|
api::{
|
2020-12-09 16:35:31 +00:00
|
|
|
api,
|
2020-12-09 11:58:43 +00:00
|
|
|
cli::*,
|
2020-12-09 16:35:31 +00:00
|
|
|
ApiHandler,
|
2020-12-09 11:58:43 +00:00
|
|
|
RpcEnvironment,
|
2020-12-09 16:35:31 +00:00
|
|
|
section_config::SectionConfigData,
|
|
|
|
},
|
2020-12-14 12:16:18 +00:00
|
|
|
tools::{
|
|
|
|
time::strftime_local,
|
|
|
|
io::ReadExt,
|
|
|
|
},
|
2020-12-09 16:35:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
use proxmox_backup::{
|
2020-12-14 12:16:18 +00:00
|
|
|
tools::format::{
|
|
|
|
HumanByte,
|
|
|
|
render_epoch,
|
|
|
|
},
|
2020-12-11 08:10:22 +00:00
|
|
|
server::{
|
|
|
|
UPID,
|
|
|
|
worker_is_active_local,
|
|
|
|
},
|
2020-12-09 16:35:31 +00:00
|
|
|
api2::{
|
|
|
|
self,
|
|
|
|
types::{
|
2020-12-18 14:32:12 +00:00
|
|
|
DATASTORE_SCHEMA,
|
2020-12-13 08:18:16 +00:00
|
|
|
DRIVE_NAME_SCHEMA,
|
2020-12-10 06:52:56 +00:00
|
|
|
MEDIA_LABEL_SCHEMA,
|
2020-12-10 11:30:27 +00:00
|
|
|
MEDIA_POOL_NAME_SCHEMA,
|
2020-12-09 16:35:31 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
config::{
|
|
|
|
self,
|
2020-12-18 14:32:12 +00:00
|
|
|
datastore::complete_datastore_name,
|
2020-12-09 16:35:31 +00:00
|
|
|
drive::complete_drive_name,
|
2020-12-10 11:30:27 +00:00
|
|
|
media_pool::complete_pool_name,
|
2020-12-09 11:58:43 +00:00
|
|
|
},
|
2020-12-10 06:52:56 +00:00
|
|
|
tape::{
|
2020-12-14 11:55:49 +00:00
|
|
|
open_drive,
|
2020-12-10 06:52:56 +00:00
|
|
|
complete_media_changer_id,
|
2020-12-14 11:55:49 +00:00
|
|
|
file_formats::{
|
|
|
|
PROXMOX_BACKUP_CONTENT_HEADER_MAGIC_1_0,
|
|
|
|
PROXMOX_BACKUP_CONTENT_NAME,
|
|
|
|
MediaContentHeader,
|
|
|
|
},
|
2020-12-10 06:52:56 +00:00
|
|
|
},
|
2020-12-09 11:58:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
mod proxmox_tape;
|
|
|
|
use proxmox_tape::*;
|
|
|
|
|
2020-12-11 08:10:22 +00:00
|
|
|
// Note: local workers should print logs to stdout, so there is no need
|
|
|
|
// to fetch/display logs. We just wait for the worker to finish.
|
|
|
|
pub async fn wait_for_local_worker(upid_str: &str) -> Result<(), Error> {
|
|
|
|
|
|
|
|
let upid: UPID = upid_str.parse()?;
|
|
|
|
|
|
|
|
let sleep_duration = core::time::Duration::new(0, 100_000_000);
|
|
|
|
|
|
|
|
loop {
|
|
|
|
if worker_is_active_local(&upid) {
|
|
|
|
tokio::time::delay_for(sleep_duration).await;
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2020-12-09 16:35:31 +00:00
|
|
|
fn lookup_drive_name(
|
|
|
|
param: &Value,
|
|
|
|
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"))?;
|
|
|
|
|
|
|
|
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,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)]
|
|
|
|
/// Erase media
|
2020-12-11 10:15:58 +00:00
|
|
|
async fn erase_media(
|
2020-12-09 16:35:31 +00:00
|
|
|
mut param: Value,
|
|
|
|
rpcenv: &mut dyn RpcEnvironment,
|
|
|
|
) -> Result<(), Error> {
|
|
|
|
|
|
|
|
let (config, _digest) = config::drive::config()?;
|
|
|
|
|
|
|
|
param["drive"] = lookup_drive_name(¶m, &config)?.into();
|
|
|
|
|
|
|
|
let info = &api2::tape::drive::API_METHOD_ERASE_MEDIA;
|
|
|
|
|
2020-12-11 10:15:58 +00:00
|
|
|
let result = match info.handler {
|
2020-12-09 16:35:31 +00:00
|
|
|
ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?,
|
|
|
|
_ => unreachable!(),
|
|
|
|
};
|
|
|
|
|
2020-12-11 10:15:58 +00:00
|
|
|
wait_for_local_worker(result.as_str().unwrap()).await?;
|
|
|
|
|
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,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)]
|
|
|
|
/// Rewind tape
|
2020-12-11 10:15:58 +00:00
|
|
|
async fn rewind(
|
2020-12-09 16:43:38 +00:00
|
|
|
mut param: Value,
|
|
|
|
rpcenv: &mut dyn RpcEnvironment,
|
|
|
|
) -> Result<(), Error> {
|
2020-12-09 16:50:48 +00:00
|
|
|
|
2020-12-09 16:43:38 +00:00
|
|
|
let (config, _digest) = config::drive::config()?;
|
|
|
|
|
|
|
|
param["drive"] = lookup_drive_name(¶m, &config)?.into();
|
|
|
|
|
|
|
|
let info = &api2::tape::drive::API_METHOD_REWIND;
|
|
|
|
|
2020-12-11 10:15:58 +00:00
|
|
|
let result = match info.handler {
|
2020-12-09 16:43:38 +00:00
|
|
|
ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?,
|
|
|
|
_ => unreachable!(),
|
|
|
|
};
|
|
|
|
|
2020-12-11 10:15:58 +00:00
|
|
|
wait_for_local_worker(result.as_str().unwrap()).await?;
|
|
|
|
|
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,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)]
|
|
|
|
/// Eject/Unload drive media
|
2020-12-12 08:58:47 +00:00
|
|
|
async fn eject_media(
|
2020-12-09 16:50:48 +00:00
|
|
|
mut param: Value,
|
|
|
|
rpcenv: &mut dyn RpcEnvironment,
|
|
|
|
) -> Result<(), Error> {
|
|
|
|
|
|
|
|
let (config, _digest) = config::drive::config()?;
|
|
|
|
|
|
|
|
param["drive"] = lookup_drive_name(¶m, &config)?.into();
|
|
|
|
|
|
|
|
let info = &api2::tape::drive::API_METHOD_EJECT_MEDIA;
|
|
|
|
|
|
|
|
match info.handler {
|
2020-12-12 08:58:47 +00:00
|
|
|
ApiHandler::Async(handler) => (handler)(param, info, rpcenv).await?,
|
2020-12-09 16:50:48 +00:00
|
|
|
_ => unreachable!(),
|
|
|
|
};
|
|
|
|
|
|
|
|
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,
|
|
|
|
},
|
|
|
|
"changer-id": {
|
|
|
|
schema: MEDIA_LABEL_SCHEMA,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)]
|
|
|
|
/// Load media
|
2020-12-12 08:58:47 +00:00
|
|
|
async fn load_media(
|
2020-12-10 06:52:56 +00:00
|
|
|
mut param: Value,
|
|
|
|
rpcenv: &mut dyn RpcEnvironment,
|
|
|
|
) -> Result<(), Error> {
|
|
|
|
|
|
|
|
let (config, _digest) = config::drive::config()?;
|
|
|
|
|
|
|
|
param["drive"] = lookup_drive_name(¶m, &config)?.into();
|
|
|
|
|
|
|
|
let info = &api2::tape::drive::API_METHOD_LOAD_MEDIA;
|
|
|
|
|
|
|
|
match info.handler {
|
2020-12-12 08:58:47 +00:00
|
|
|
ApiHandler::Async(handler) => (handler)(param, info, rpcenv).await?,
|
2020-12-10 06:52:56 +00:00
|
|
|
_ => unreachable!(),
|
|
|
|
};
|
|
|
|
|
|
|
|
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,
|
|
|
|
},
|
|
|
|
"changer-id": {
|
|
|
|
schema: MEDIA_LABEL_SCHEMA,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)]
|
|
|
|
/// Label media
|
2020-12-11 08:10:22 +00:00
|
|
|
async fn label_media(
|
2020-12-10 11:30:27 +00:00
|
|
|
mut param: Value,
|
|
|
|
rpcenv: &mut dyn RpcEnvironment,
|
|
|
|
) -> Result<(), Error> {
|
|
|
|
|
|
|
|
let (config, _digest) = config::drive::config()?;
|
|
|
|
|
|
|
|
param["drive"] = lookup_drive_name(¶m, &config)?.into();
|
|
|
|
|
|
|
|
let info = &api2::tape::drive::API_METHOD_LABEL_MEDIA;
|
|
|
|
|
2020-12-11 08:10:22 +00:00
|
|
|
let result = match info.handler {
|
2020-12-10 11:30:27 +00:00
|
|
|
ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?,
|
|
|
|
_ => unreachable!(),
|
|
|
|
};
|
|
|
|
|
2020-12-11 08:10:22 +00:00
|
|
|
wait_for_local_worker(result.as_str().unwrap()).await?;
|
|
|
|
|
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,
|
|
|
|
},
|
|
|
|
"output-format": {
|
|
|
|
schema: OUTPUT_FORMAT,
|
|
|
|
optional: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)]
|
|
|
|
/// Read media label
|
2020-12-12 08:58:47 +00:00
|
|
|
async fn read_label(
|
2020-12-10 12:20:39 +00:00
|
|
|
mut param: Value,
|
|
|
|
rpcenv: &mut dyn RpcEnvironment,
|
|
|
|
) -> Result<(), Error> {
|
2020-12-11 06:39:28 +00:00
|
|
|
|
|
|
|
let (config, _digest) = config::drive::config()?;
|
2020-12-10 12:20:39 +00:00
|
|
|
|
|
|
|
param["drive"] = lookup_drive_name(¶m, &config)?.into();
|
|
|
|
|
|
|
|
let output_format = get_output_format(¶m);
|
|
|
|
let info = &api2::tape::drive::API_METHOD_READ_LABEL;
|
|
|
|
let mut data = match info.handler {
|
2020-12-12 08:58:47 +00:00
|
|
|
ApiHandler::Async(handler) => (handler)(param, info, rpcenv).await?,
|
2020-12-10 12:20:39 +00:00
|
|
|
_ => unreachable!(),
|
|
|
|
};
|
|
|
|
|
|
|
|
let options = default_table_format_options()
|
|
|
|
.column(ColumnConfig::new("changer-id"))
|
|
|
|
.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))
|
|
|
|
;
|
|
|
|
|
|
|
|
format_and_print_result_full(&mut data, info.returns, &output_format, &options);
|
|
|
|
|
|
|
|
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>,
|
|
|
|
param: Value,
|
2020-12-11 06:39:28 +00:00
|
|
|
rpcenv: &mut dyn RpcEnvironment,
|
|
|
|
) -> Result<(), Error> {
|
|
|
|
|
2020-12-11 09:42:29 +00:00
|
|
|
let output_format = get_output_format(¶m);
|
|
|
|
|
2020-12-11 06:39:28 +00:00
|
|
|
let (config, _digest) = config::drive::config()?;
|
2020-12-11 09:42:29 +00:00
|
|
|
let drive = lookup_drive_name(¶m, &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);
|
|
|
|
|
|
|
|
if do_read {
|
|
|
|
let mut param = json!({
|
|
|
|
"drive": &drive,
|
|
|
|
});
|
|
|
|
if let Some(true) = read_all_labels {
|
|
|
|
param["read-all-labels"] = true.into();
|
|
|
|
}
|
|
|
|
let info = &api2::tape::drive::API_METHOD_UPDATE_INVENTORY;
|
|
|
|
let result = match info.handler {
|
|
|
|
ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?,
|
|
|
|
_ => unreachable!(),
|
|
|
|
};
|
|
|
|
wait_for_local_worker(result.as_str().unwrap()).await?;
|
|
|
|
}
|
2020-12-11 06:39:28 +00:00
|
|
|
|
|
|
|
let info = &api2::tape::drive::API_METHOD_INVENTORY;
|
2020-12-11 09:42:29 +00:00
|
|
|
|
|
|
|
let param = json!({ "drive": &drive });
|
2020-12-11 06:39:28 +00:00
|
|
|
let mut data = match info.handler {
|
2020-12-12 08:58:47 +00:00
|
|
|
ApiHandler::Async(handler) => (handler)(param, info, rpcenv).await?,
|
2020-12-11 06:39:28 +00:00
|
|
|
_ => unreachable!(),
|
|
|
|
};
|
2020-12-10 12:20:39 +00:00
|
|
|
|
2020-12-11 06:39:28 +00:00
|
|
|
let options = default_table_format_options()
|
|
|
|
.column(ColumnConfig::new("changer-id"))
|
|
|
|
.column(ColumnConfig::new("uuid"))
|
|
|
|
;
|
|
|
|
|
|
|
|
format_and_print_result_full(&mut data, info.returns, &output_format, &options);
|
|
|
|
|
|
|
|
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,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)]
|
|
|
|
/// Label media with barcodes from changer device
|
2020-12-11 08:10:22 +00:00
|
|
|
async fn barcode_label_media(
|
2020-12-11 06:50:19 +00:00
|
|
|
mut param: Value,
|
|
|
|
rpcenv: &mut dyn RpcEnvironment,
|
|
|
|
) -> Result<(), Error> {
|
|
|
|
|
|
|
|
let (config, _digest) = config::drive::config()?;
|
|
|
|
|
|
|
|
param["drive"] = lookup_drive_name(¶m, &config)?.into();
|
|
|
|
|
|
|
|
let info = &api2::tape::drive::API_METHOD_BARCODE_LABEL_MEDIA;
|
|
|
|
|
2020-12-11 08:10:22 +00:00
|
|
|
let result = match info.handler {
|
2020-12-11 06:50:19 +00:00
|
|
|
ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?,
|
|
|
|
_ => unreachable!(),
|
|
|
|
};
|
|
|
|
|
2020-12-11 08:10:22 +00:00
|
|
|
wait_for_local_worker(result.as_str().unwrap()).await?;
|
|
|
|
|
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)
|
|
|
|
fn move_to_eom(param: Value) -> Result<(), Error> {
|
|
|
|
|
|
|
|
let (config, _digest) = config::drive::config()?;
|
|
|
|
|
|
|
|
let drive = lookup_drive_name(¶m, &config)?;
|
|
|
|
let mut drive = open_drive(&config, &drive)?;
|
|
|
|
|
|
|
|
drive.move_to_eom()?;
|
|
|
|
|
|
|
|
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.
|
2020-12-14 11:55:49 +00:00
|
|
|
fn debug_scan(param: Value) -> Result<(), Error> {
|
|
|
|
|
|
|
|
let (config, _digest) = config::drive::config()?;
|
|
|
|
|
|
|
|
let drive = lookup_drive_name(¶m, &config)?;
|
|
|
|
let mut drive = open_drive(&config, &drive)?;
|
|
|
|
|
|
|
|
println!("rewinding tape");
|
|
|
|
drive.rewind()?;
|
|
|
|
|
|
|
|
loop {
|
|
|
|
let file_number = drive.current_file_number()?;
|
|
|
|
|
|
|
|
match drive.read_next_file()? {
|
|
|
|
None => {
|
|
|
|
println!("EOD");
|
|
|
|
continue;
|
|
|
|
},
|
|
|
|
Some(mut reader) => {
|
|
|
|
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);
|
|
|
|
} else {
|
|
|
|
if let Some(name) = PROXMOX_BACKUP_CONTENT_NAME.get(&header.content_magic) {
|
|
|
|
println!("got content header: {}", name);
|
2020-12-14 15:56:26 +00:00
|
|
|
println!(" uuid: {}", header.content_uuid());
|
2020-12-14 12:16:18 +00:00
|
|
|
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 {
|
|
|
|
println!("got unknown content header: {:?}", header.content_magic);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Err(err) => {
|
|
|
|
println!("unable to read content header - {}", err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let bytes = reader.skip_to_end()?;
|
2020-12-14 12:16:18 +00:00
|
|
|
println!("skipped {}", HumanByte::from(bytes));
|
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,
|
|
|
|
},
|
|
|
|
"output-format": {
|
|
|
|
schema: OUTPUT_FORMAT,
|
|
|
|
optional: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)]
|
|
|
|
/// Read Medium auxiliary memory attributes (Cartridge Memory)
|
|
|
|
fn mam_attributes(
|
|
|
|
mut param: Value,
|
|
|
|
rpcenv: &mut dyn RpcEnvironment,
|
|
|
|
) -> Result<(), Error> {
|
|
|
|
|
|
|
|
let (config, _digest) = config::drive::config()?;
|
|
|
|
|
|
|
|
param["drive"] = lookup_drive_name(¶m, &config)?.into();
|
|
|
|
|
|
|
|
let output_format = get_output_format(¶m);
|
|
|
|
let info = &api2::tape::drive::API_METHOD_MAM_ATTRIBUTES;
|
|
|
|
|
|
|
|
let mut data = match info.handler {
|
|
|
|
ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?,
|
|
|
|
_ => unreachable!(),
|
|
|
|
};
|
|
|
|
|
|
|
|
let options = default_table_format_options()
|
|
|
|
.column(ColumnConfig::new("id"))
|
|
|
|
.column(ColumnConfig::new("name"))
|
|
|
|
.column(ColumnConfig::new("value"))
|
|
|
|
;
|
|
|
|
|
|
|
|
format_and_print_result_full(&mut data, info.returns, &output_format, &options);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2020-12-18 14:32:12 +00:00
|
|
|
#[api(
|
|
|
|
input: {
|
|
|
|
properties: {
|
|
|
|
store: {
|
|
|
|
schema: DATASTORE_SCHEMA,
|
|
|
|
},
|
|
|
|
pool: {
|
|
|
|
schema: MEDIA_POOL_NAME_SCHEMA,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)]
|
|
|
|
/// Backup datastore to tape media pool
|
|
|
|
async fn backup(
|
|
|
|
param: Value,
|
|
|
|
rpcenv: &mut dyn RpcEnvironment,
|
|
|
|
) -> Result<(), Error> {
|
|
|
|
|
|
|
|
let info = &api2::tape::backup::API_METHOD_BACKUP;
|
|
|
|
|
|
|
|
let result = match info.handler {
|
|
|
|
ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?,
|
|
|
|
_ => unreachable!(),
|
|
|
|
};
|
|
|
|
|
|
|
|
wait_for_local_worker(result.as_str().unwrap()).await?;
|
|
|
|
|
|
|
|
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"])
|
|
|
|
.completion_cb("store", complete_datastore_name)
|
|
|
|
.completion_cb("pool", complete_pool_name)
|
|
|
|
)
|
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-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(
|
|
|
|
"erase",
|
|
|
|
CliCommand::new(&API_METHOD_ERASE_MEDIA)
|
|
|
|
.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-21 11:11:52 +00:00
|
|
|
.insert(
|
|
|
|
"mam",
|
|
|
|
CliCommand::new(&API_METHOD_MAM_ATTRIBUTES)
|
|
|
|
.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())
|
2020-12-10 06:52:56 +00:00
|
|
|
.insert(
|
|
|
|
"load-media",
|
|
|
|
CliCommand::new(&API_METHOD_LOAD_MEDIA)
|
|
|
|
.arg_param(&["changer-id"])
|
|
|
|
.completion_cb("drive", complete_drive_name)
|
|
|
|
.completion_cb("changer-id", complete_media_changer_id)
|
|
|
|
)
|
2020-12-09 11:58:43 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
let mut rpcenv = CliEnvironment::new();
|
|
|
|
rpcenv.set_auth_id(Some(String::from("root@pam")));
|
|
|
|
|
|
|
|
proxmox_backup::tools::runtime::main(run_async_cli_command(cmd_def, rpcenv));
|
|
|
|
}
|