[pbs-devel] [PATCH proxmox-backup 01/12] pbs-datastore: add protection info to BackupInfo
Dominik Csapak
d.csapak at proxmox.com
Mon Sep 6 12:57:44 CEST 2021
and add necessary helper functions (protected_file/is_protected)
Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
pbs-datastore/src/backup_info.rs | 20 ++++++++++++++++++--
tests/prune.rs | 4 ++--
2 files changed, 20 insertions(+), 4 deletions(-)
diff --git a/pbs-datastore/src/backup_info.rs b/pbs-datastore/src/backup_info.rs
index f77098ee..032fad8b 100644
--- a/pbs-datastore/src/backup_info.rs
+++ b/pbs-datastore/src/backup_info.rs
@@ -92,7 +92,9 @@ impl BackupGroup {
BackupDir::with_rfc3339(&self.backup_type, &self.backup_id, backup_time)?;
let files = list_backup_files(l2_fd, backup_time)?;
- list.push(BackupInfo { backup_dir, files });
+ let protected = backup_dir.is_protected(base_path.to_owned());
+
+ list.push(BackupInfo { backup_dir, files, protected });
Ok(())
},
@@ -253,6 +255,17 @@ impl BackupDir {
relative_path
}
+ pub fn protected_file(&self, mut path: PathBuf) -> PathBuf {
+ path.push(self.relative_path());
+ path.push(".protected");
+ path
+ }
+
+ pub fn is_protected(&self, base_path: PathBuf) -> bool {
+ let path = self.protected_file(base_path);
+ path.exists()
+ }
+
pub fn backup_time_to_string(backup_time: i64) -> Result<String, Error> {
// fixme: can this fail? (avoid unwrap)
proxmox::tools::time::epoch_to_rfc3339_utc(backup_time)
@@ -293,6 +306,8 @@ pub struct BackupInfo {
pub backup_dir: BackupDir,
/// List of data files
pub files: Vec<String>,
+ /// Protection Status
+ pub protected: bool,
}
impl BackupInfo {
@@ -301,8 +316,9 @@ impl BackupInfo {
path.push(backup_dir.relative_path());
let files = list_backup_files(libc::AT_FDCWD, &path)?;
+ let protected = backup_dir.is_protected(base_path.to_owned());
- Ok(BackupInfo { backup_dir, files })
+ Ok(BackupInfo { backup_dir, files, protected })
}
/// Finds the latest backup inside a backup group
diff --git a/tests/prune.rs b/tests/prune.rs
index 3297b031..5c61cbf9 100644
--- a/tests/prune.rs
+++ b/tests/prune.rs
@@ -17,7 +17,7 @@ fn get_prune_list(
prune_info
.iter()
- .filter_map(|(info, keep)| {
+ .filter_map(|(info, keep, _)| {
if *keep != return_kept {
None
} else {
@@ -40,7 +40,7 @@ fn create_info(
files.push(String::from(MANIFEST_BLOB_NAME));
}
- BackupInfo { backup_dir, files }
+ BackupInfo { backup_dir, files, protected: false }
}
#[test]
--
2.30.2
More information about the pbs-devel
mailing list