tape: implement API to run tape backup jobs
This commit is contained in:
parent
fe291ab794
commit
41a8db3576
@ -31,6 +31,7 @@ use crate::{
|
||||
MEDIA_POOL_NAME_SCHEMA,
|
||||
DRIVE_NAME_SCHEMA,
|
||||
UPID_SCHEMA,
|
||||
JOB_ID_SCHEMA,
|
||||
MediaPoolConfig,
|
||||
},
|
||||
server::WorkerTask,
|
||||
@ -49,6 +50,13 @@ use crate::{
|
||||
},
|
||||
};
|
||||
|
||||
const TAPE_BACKUP_JOB_ROUTER: Router = Router::new()
|
||||
.post(&API_METHOD_RUN_TAPE_BACKUP_JOB);
|
||||
|
||||
pub const ROUTER: Router = Router::new()
|
||||
.post(&API_METHOD_BACKUP)
|
||||
.match_all("id", &TAPE_BACKUP_JOB_ROUTER);
|
||||
|
||||
pub fn do_tape_backup_job(
|
||||
mut job: Job,
|
||||
tape_job: TapeBackupJobConfig,
|
||||
@ -118,6 +126,32 @@ pub fn do_tape_backup_job(
|
||||
Ok(upid_str)
|
||||
}
|
||||
|
||||
#[api(
|
||||
input: {
|
||||
properties: {
|
||||
id: {
|
||||
schema: JOB_ID_SCHEMA,
|
||||
},
|
||||
},
|
||||
},
|
||||
)]
|
||||
/// Runs a tape backup job manually.
|
||||
pub fn run_tape_backup_job(
|
||||
id: String,
|
||||
rpcenv: &mut dyn RpcEnvironment,
|
||||
) -> Result<String, Error> {
|
||||
let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?;
|
||||
|
||||
let (config, _digest) = config::tape_job::config()?;
|
||||
let backup_job: TapeBackupJobConfig = config.lookup("backup", &id)?;
|
||||
|
||||
let job = Job::new("tape-backup-job", &id)?;
|
||||
|
||||
let upid_str = do_tape_backup_job(job, backup_job, &auth_id, None)?;
|
||||
|
||||
Ok(upid_str)
|
||||
}
|
||||
|
||||
#[api(
|
||||
input: {
|
||||
properties: {
|
||||
@ -190,10 +224,6 @@ pub fn backup(
|
||||
Ok(upid_str.into())
|
||||
}
|
||||
|
||||
pub const ROUTER: Router = Router::new()
|
||||
.post(&API_METHOD_BACKUP);
|
||||
|
||||
|
||||
fn backup_worker(
|
||||
worker: &WorkerTask,
|
||||
datastore: Arc<DataStore>,
|
||||
|
@ -5,6 +5,10 @@ use proxmox::api::{api, cli::*, RpcEnvironment, ApiHandler};
|
||||
|
||||
use proxmox_backup::{
|
||||
config,
|
||||
client::{
|
||||
connect_to_localhost,
|
||||
view_task_result,
|
||||
},
|
||||
api2::{
|
||||
self,
|
||||
types::*,
|
||||
@ -75,6 +79,31 @@ fn show_tape_backup_job(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result
|
||||
Ok(Value::Null)
|
||||
}
|
||||
|
||||
#[api(
|
||||
input: {
|
||||
properties: {
|
||||
id: {
|
||||
schema: JOB_ID_SCHEMA,
|
||||
},
|
||||
},
|
||||
},
|
||||
)]
|
||||
/// Run THape Backup Job
|
||||
async fn run_tape_backup_job(mut param: Value) -> Result<(), Error> {
|
||||
|
||||
let output_format = get_output_format(¶m);
|
||||
|
||||
let id = param["id"].take().as_str().unwrap().to_string();
|
||||
|
||||
let mut client = connect_to_localhost()?;
|
||||
|
||||
let result = client.post(&format!("api2/json/tape/backup/{}", id), Some(param)).await?;
|
||||
|
||||
view_task_result(&mut client, result, &output_format).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn backup_job_commands() -> CommandLineInterface {
|
||||
|
||||
let cmd_def = CliCommandMap::new()
|
||||
@ -84,6 +113,11 @@ pub fn backup_job_commands() -> CommandLineInterface {
|
||||
.arg_param(&["id"])
|
||||
.completion_cb("id", config::tape_job::complete_tape_job_id)
|
||||
)
|
||||
.insert("run",
|
||||
CliCommand::new(&API_METHOD_RUN_TAPE_BACKUP_JOB)
|
||||
.arg_param(&["id"])
|
||||
.completion_cb("id", config::tape_job::complete_tape_job_id)
|
||||
)
|
||||
.insert("create",
|
||||
CliCommand::new(&api2::config::tape_backup_job::API_METHOD_CREATE_TAPE_BACKUP_JOB)
|
||||
.arg_param(&["id"])
|
||||
|
Loading…
Reference in New Issue
Block a user