proxmox-backup/src/tape/mod.rs

108 lines
2.9 KiB
Rust
Raw Normal View History

2020-12-15 12:13:44 +00:00
//! Magnetic tape backup
2020-12-09 09:16:01 +00:00
use anyhow::{format_err, Error};
use proxmox::tools::fs::{
create_path,
CreateOptions,
};
2021-02-02 13:38:15 +00:00
#[cfg(test)]
mod test;
2020-12-05 09:45:08 +00:00
pub mod file_formats;
2020-12-05 09:51:34 +00:00
mod tape_write;
pub use tape_write::*;
2020-12-05 09:54:38 +00:00
mod tape_read;
pub use tape_read::*;
2020-12-05 11:20:46 +00:00
mod helpers;
pub use helpers::*;
2021-01-09 07:54:58 +00:00
mod media_set;
pub use media_set::*;
2020-12-05 11:53:08 +00:00
mod inventory;
pub use inventory::*;
2021-01-21 16:25:32 +00:00
mod linux_list_drives;
pub use linux_list_drives::*;
pub mod changer;
pub mod drive;
2020-12-09 09:16:01 +00:00
2020-12-10 10:41:35 +00:00
mod media_pool;
pub use media_pool::*;
2020-12-15 12:13:44 +00:00
mod media_catalog;
pub use media_catalog::*;
2020-12-18 14:27:44 +00:00
mod pool_writer;
pub use pool_writer::*;
2020-12-09 09:16:01 +00:00
/// Directory path where we store all tape status information
pub const TAPE_STATUS_DIR: &str = "/var/lib/proxmox-backup/tape";
2020-12-05 11:20:46 +00:00
/// Directory path where we store temporary drive state
pub const DRIVE_STATE_DIR: &str = concat!(PROXMOX_BACKUP_RUN_DIR_M!(), "/drive-state");
/// Directory path where we store cached changer state
pub const CHANGER_STATE_DIR: &str = concat!(PROXMOX_BACKUP_RUN_DIR_M!(), "/changer-state");
2020-12-05 11:20:46 +00:00
/// We limit chunk archive size, so that we can faster restore a
/// specific chunk (The catalog only store file numbers, so we
/// need to read the whole archive to restore a single chunk)
pub const MAX_CHUNK_ARCHIVE_SIZE: usize = 4*1024*1024*1024; // 4GB for now
/// To improve performance, we need to avoid tape drive buffer flush.
pub const COMMIT_BLOCK_SIZE: usize = 128*1024*1024*1024; // 128 GiB
2020-12-09 09:16:01 +00:00
/// Create tape status dir with correct permission
pub fn create_tape_status_dir() -> Result<(), Error> {
let backup_user = crate::backup::backup_user()?;
let mode = nix::sys::stat::Mode::from_bits_truncate(0o0750);
let options = CreateOptions::new()
2020-12-09 09:16:01 +00:00
.perm(mode)
.owner(backup_user.uid)
.group(backup_user.gid);
create_path(TAPE_STATUS_DIR, None, Some(options))
2020-12-09 09:16:01 +00:00
.map_err(|err: Error| format_err!("unable to create tape status dir - {}", err))?;
Ok(())
}
/// Create drive state dir with correct permission
pub fn create_drive_state_dir() -> Result<(), Error> {
let backup_user = crate::backup::backup_user()?;
let mode = nix::sys::stat::Mode::from_bits_truncate(0o0750);
let options = CreateOptions::new()
.perm(mode)
.owner(backup_user.uid)
.group(backup_user.gid);
create_path(DRIVE_STATE_DIR, None, Some(options))
.map_err(|err: Error| format_err!("unable to create drive state dir - {}", err))?;
Ok(())
}
/// Create changer state cache dir with correct permission
pub fn create_changer_state_dir() -> Result<(), Error> {
let backup_user = crate::backup::backup_user()?;
let mode = nix::sys::stat::Mode::from_bits_truncate(0o0750);
let options = CreateOptions::new()
.perm(mode)
.owner(backup_user.uid)
.group(backup_user.gid);
create_path(CHANGER_STATE_DIR, None, Some(options))
.map_err(|err: Error| format_err!("unable to create changer state dir - {}", err))?;
Ok(())
}