api2/tape/backup: add 'force-media-set' parameter to manual backup

so that a user can force a new media set, e.g. if he uses the
allocation policy 'continue', but wants to manually start a new
media-set.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
Dominik Csapak
2021-05-10 16:45:53 +02:00
committed by Dietmar Maurer
parent 10f788b7eb
commit e953029e8f
4 changed files with 31 additions and 9 deletions

View File

@ -258,7 +258,7 @@ impl MediaPool {
/// Make sure the current media set is usable for writing
///
/// If not, starts a new media set. Also creates a new
/// set if media_set_policy implies it.
/// set if media_set_policy implies it, or if 'force' is true.
///
/// Note: We also call this in list_media to compute correct media
/// status, so this must not change persistent/saved state.
@ -267,6 +267,7 @@ impl MediaPool {
pub fn start_write_session(
&mut self,
current_time: i64,
force: bool,
) -> Result<Option<String>, Error> {
let _pool_lock = if self.no_media_set_locking {
@ -277,11 +278,15 @@ impl MediaPool {
self.inventory.reload()?;
let mut create_new_set = match self.current_set_usable() {
Err(err) => {
Some(err.to_string())
}
Ok(_) => None,
let mut create_new_set = if force {
Some(String::from("forced"))
} else {
match self.current_set_usable() {
Err(err) => {
Some(err.to_string())
}
Ok(_) => None,
}
};
if create_new_set.is_none() {

View File

@ -71,11 +71,12 @@ impl PoolWriter {
drive_name: &str,
worker: &WorkerTask,
notify_email: Option<String>,
force_media_set: bool,
) -> Result<Self, Error> {
let current_time = proxmox::tools::time::epoch_i64();
let new_media_set_reason = pool.start_write_session(current_time)?;
let new_media_set_reason = pool.start_write_session(current_time, force_media_set)?;
if let Some(reason) = new_media_set_reason {
task_log!(
worker,