tape: backup - implement --eject-media option

This commit is contained in:
Dietmar Maurer
2021-01-09 15:17:03 +01:00
parent 5843268c47
commit 42967bf185
3 changed files with 39 additions and 3 deletions

View File

@ -26,6 +26,7 @@ use crate::{
tape_write_snapshot_archive,
request_and_load_media,
tape_alert_flags_critical,
media_changer,
file_formats::MediaSetLabel,
},
};
@ -106,6 +107,24 @@ impl PoolWriter {
self.media_set_catalog.contains_snapshot(snapshot)
}
/// Eject media and drop PoolWriterState (close drive)
pub fn eject_media(&mut self) -> Result<(), Error> {
let mut status = match self.status.take() {
Some(status) => status,
None => return Ok(()), // no media loaded
};
let (drive_config, _digest) = crate::config::drive::config()?;
if let Some((mut changer, _)) = media_changer(&drive_config, &self.drive_name)? {
changer.unload_media(None)?;
} else {
status.drive.eject_media()?;
}
Ok(())
}
/// commit changes to tape and catalog
///
/// This is done automatically during a backupsession, but needs to