datastore: move last_backup from BackupInfo to BackupGroup

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2022-04-20 09:55:48 +02:00
parent fe94c9962e
commit c4b2d26cdb
2 changed files with 16 additions and 15 deletions

View File

@ -103,6 +103,19 @@ impl BackupGroup {
Ok(list) Ok(list)
} }
/// Finds the latest backup inside a backup group
pub fn last_backup(
&self,
base_path: &Path,
only_finished: bool,
) -> Result<Option<BackupInfo>, Error> {
let backups = self.list_backups(base_path)?;
Ok(backups
.into_iter()
.filter(|item| !only_finished || item.is_finished())
.max_by_key(|item| item.backup_dir.backup_time()))
}
pub fn last_successful_backup(&self, base_path: &Path) -> Result<Option<i64>, Error> { pub fn last_successful_backup(&self, base_path: &Path) -> Result<Option<i64>, Error> {
let mut last = None; let mut last = None;
@ -363,19 +376,6 @@ impl BackupInfo {
}) })
} }
/// Finds the latest backup inside a backup group
pub fn last_backup(
base_path: &Path,
group: &BackupGroup,
only_finished: bool,
) -> Result<Option<BackupInfo>, Error> {
let backups = group.list_backups(base_path)?;
Ok(backups
.into_iter()
.filter(|item| !only_finished || item.is_finished())
.max_by_key(|item| item.backup_dir.backup_time()))
}
pub fn sort_list(list: &mut Vec<BackupInfo>, ascendending: bool) { pub fn sort_list(list: &mut Vec<BackupInfo>, ascendending: bool) {
if ascendending { if ascendending {
// oldest first // oldest first

View File

@ -21,7 +21,7 @@ use pbs_api_types::{
DATASTORE_SCHEMA, PRIV_DATASTORE_BACKUP, DATASTORE_SCHEMA, PRIV_DATASTORE_BACKUP,
}; };
use pbs_config::CachedUserInfo; use pbs_config::CachedUserInfo;
use pbs_datastore::backup_info::{BackupDir, BackupGroup, BackupInfo}; use pbs_datastore::backup_info::{BackupDir, BackupGroup};
use pbs_datastore::index::IndexFile; use pbs_datastore::index::IndexFile;
use pbs_datastore::manifest::{archive_type, ArchiveType}; use pbs_datastore::manifest::{archive_type, ArchiveType};
use pbs_datastore::{DataStore, PROXMOX_BACKUP_PROTOCOL_ID_V1}; use pbs_datastore::{DataStore, PROXMOX_BACKUP_PROTOCOL_ID_V1};
@ -134,7 +134,8 @@ fn upgrade_to_backup_protocol(
} }
let last_backup = { let last_backup = {
let info = BackupInfo::last_backup(&datastore.base_path(), &backup_group, true) let info = backup_group
.last_backup(&datastore.base_path(), true)
.unwrap_or(None); .unwrap_or(None);
if let Some(info) = info { if let Some(info) = info {
let (manifest, _) = datastore.load_manifest(&info.backup_dir)?; let (manifest, _) = datastore.load_manifest(&info.backup_dir)?;