]> git.proxmox.com Git - proxmox-backup.git/blob - src/tape/mod.rs
ed03d8a72131cad2c929899f655e81af2e688049
[proxmox-backup.git] / src / tape / mod.rs
1 //! Magnetic tape backup
2
3 use anyhow::{format_err, Error};
4
5 use proxmox::tools::fs::{
6 create_path,
7 CreateOptions,
8 };
9
10 #[cfg(test)]
11 mod test;
12
13 pub mod file_formats;
14
15 mod tape_write;
16 pub use tape_write::*;
17
18 mod tape_read;
19 pub use tape_read::*;
20
21 mod helpers;
22 pub use helpers::*;
23
24 mod media_set;
25 pub use media_set::*;
26
27 mod inventory;
28 pub use inventory::*;
29
30 mod linux_list_drives;
31 pub use linux_list_drives::*;
32
33 pub mod changer;
34
35 pub mod drive;
36
37 mod media_pool;
38 pub use media_pool::*;
39
40 mod media_catalog;
41 pub use media_catalog::*;
42
43 mod pool_writer;
44 pub use pool_writer::*;
45
46 /// Directory path where we store all tape status information
47 pub const TAPE_STATUS_DIR: &str = "/var/lib/proxmox-backup/tape";
48
49 /// Directory path where we store temporary drive state
50 pub const DRIVE_STATE_DIR: &str = concat!(PROXMOX_BACKUP_RUN_DIR_M!(), "/drive-state");
51
52 /// Directory path where we store cached changer state
53 pub const CHANGER_STATE_DIR: &str = concat!(PROXMOX_BACKUP_RUN_DIR_M!(), "/changer-state");
54
55 /// We limit chunk archive size, so that we can faster restore a
56 /// specific chunk (The catalog only store file numbers, so we
57 /// need to read the whole archive to restore a single chunk)
58 pub const MAX_CHUNK_ARCHIVE_SIZE: usize = 4*1024*1024*1024; // 4GB for now
59
60 /// To improve performance, we need to avoid tape drive buffer flush.
61 pub const COMMIT_BLOCK_SIZE: usize = 128*1024*1024*1024; // 128 GiB
62
63
64 /// Create tape status dir with correct permission
65 pub fn create_tape_status_dir() -> Result<(), Error> {
66 let backup_user = crate::backup::backup_user()?;
67 let mode = nix::sys::stat::Mode::from_bits_truncate(0o0750);
68 let options = CreateOptions::new()
69 .perm(mode)
70 .owner(backup_user.uid)
71 .group(backup_user.gid);
72
73 create_path(TAPE_STATUS_DIR, None, Some(options))
74 .map_err(|err: Error| format_err!("unable to create tape status dir - {}", err))?;
75
76 Ok(())
77 }
78
79 /// Create drive state dir with correct permission
80 pub fn create_drive_state_dir() -> Result<(), Error> {
81 let backup_user = crate::backup::backup_user()?;
82 let mode = nix::sys::stat::Mode::from_bits_truncate(0o0750);
83 let options = CreateOptions::new()
84 .perm(mode)
85 .owner(backup_user.uid)
86 .group(backup_user.gid);
87
88 create_path(DRIVE_STATE_DIR, None, Some(options))
89 .map_err(|err: Error| format_err!("unable to create drive state dir - {}", err))?;
90
91 Ok(())
92 }
93
94 /// Create changer state cache dir with correct permission
95 pub fn create_changer_state_dir() -> Result<(), Error> {
96 let backup_user = crate::backup::backup_user()?;
97 let mode = nix::sys::stat::Mode::from_bits_truncate(0o0750);
98 let options = CreateOptions::new()
99 .perm(mode)
100 .owner(backup_user.uid)
101 .group(backup_user.gid);
102
103 create_path(CHANGER_STATE_DIR, None, Some(options))
104 .map_err(|err: Error| format_err!("unable to create changer state dir - {}", err))?;
105
106 Ok(())
107 }