5
0
mirror of git://git.proxmox.com/git/proxmox-backup.git synced 2025-01-05 09:17:59 +03:00

datastore: move BackupGroupDeleteStats to api types

In preparation for the delete stats to be exposed as return type to
the backup group delete api endpoint.

Also, rename the private field `unremoved_protected` to a better
fitting `protected_snapshots` to be in line with the method names.

Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
This commit is contained in:
Christian Ebner 2024-11-11 16:43:33 +01:00 committed by Fabian Grünbichler
parent db4f1f64b6
commit d1e5e4533c
3 changed files with 36 additions and 34 deletions

View File

@ -1580,3 +1580,33 @@ pub fn print_store_and_ns(store: &str, ns: &BackupNamespace) -> String {
format!("datastore '{}', namespace '{}'", store, ns)
}
}
#[derive(Default)]
pub struct BackupGroupDeleteStats {
// Count of protected snapshots, therefore not removed
protected_snapshots: usize,
// Count of deleted snapshots
removed_snapshots: usize,
}
impl BackupGroupDeleteStats {
pub fn all_removed(&self) -> bool {
self.protected_snapshots == 0
}
pub fn removed_snapshots(&self) -> usize {
self.removed_snapshots
}
pub fn protected_snapshots(&self) -> usize {
self.protected_snapshots
}
pub fn increment_removed_snapshots(&mut self) {
self.removed_snapshots += 1;
}
pub fn increment_protected_snapshots(&mut self) {
self.protected_snapshots += 1;
}
}

View File

@ -8,7 +8,8 @@ use anyhow::{bail, format_err, Error};
use proxmox_sys::fs::{lock_dir_noblock, replace_file, CreateOptions};
use pbs_api_types::{
Authid, BackupNamespace, BackupType, GroupFilter, BACKUP_DATE_REGEX, BACKUP_FILE_REGEX,
Authid, BackupGroupDeleteStats, BackupNamespace, BackupType, GroupFilter, BACKUP_DATE_REGEX,
BACKUP_FILE_REGEX,
};
use pbs_config::{open_backup_lockfile, BackupLockGuard};
@ -17,36 +18,6 @@ use crate::manifest::{
};
use crate::{DataBlob, DataStore};
#[derive(Default)]
pub struct BackupGroupDeleteStats {
// Count of protected snapshots, therefore not removed
unremoved_protected: usize,
// Count of deleted snapshots
removed_snapshots: usize,
}
impl BackupGroupDeleteStats {
pub fn all_removed(&self) -> bool {
self.unremoved_protected == 0
}
pub fn removed_snapshots(&self) -> usize {
self.removed_snapshots
}
pub fn protected_snapshots(&self) -> usize {
self.unremoved_protected
}
fn increment_removed_snapshots(&mut self) {
self.removed_snapshots += 1;
}
fn increment_protected_snapshots(&mut self) {
self.unremoved_protected += 1;
}
}
/// BackupGroup is a directory containing a list of BackupDir
#[derive(Clone)]
pub struct BackupGroup {

View File

@ -18,11 +18,12 @@ use proxmox_sys::process_locker::ProcessLockSharedGuard;
use proxmox_worker_task::WorkerTaskContext;
use pbs_api_types::{
Authid, BackupNamespace, BackupType, ChunkOrder, DataStoreConfig, DatastoreFSyncLevel,
DatastoreTuning, GarbageCollectionStatus, MaintenanceMode, MaintenanceType, Operation, UPID,
Authid, BackupGroupDeleteStats, BackupNamespace, BackupType, ChunkOrder, DataStoreConfig,
DatastoreFSyncLevel, DatastoreTuning, GarbageCollectionStatus, MaintenanceMode,
MaintenanceType, Operation, UPID,
};
use crate::backup_info::{BackupDir, BackupGroup, BackupGroupDeleteStats};
use crate::backup_info::{BackupDir, BackupGroup};
use crate::chunk_store::ChunkStore;
use crate::dynamic_index::{DynamicIndexReader, DynamicIndexWriter};
use crate::fixed_index::{FixedIndexReader, FixedIndexWriter};