2019-05-11 08:19:34 +00:00
|
|
|
use std::os::unix::io::RawFd;
|
2021-03-14 18:18:35 +00:00
|
|
|
use std::path::{Path, PathBuf};
|
2021-10-28 13:00:50 +00:00
|
|
|
use std::str::FromStr;
|
2020-11-03 05:36:50 +00:00
|
|
|
|
2021-07-06 11:26:35 +00:00
|
|
|
use anyhow::{bail, format_err, Error};
|
|
|
|
|
2021-07-07 09:34:45 +00:00
|
|
|
use pbs_api_types::{
|
2022-04-14 13:05:58 +00:00
|
|
|
BackupType, GroupFilter, BACKUP_DATE_REGEX, BACKUP_FILE_REGEX, GROUP_PATH_REGEX,
|
|
|
|
SNAPSHOT_PATH_REGEX,
|
2021-05-07 10:45:44 +00:00
|
|
|
};
|
2019-03-05 06:18:12 +00:00
|
|
|
|
2020-01-06 10:35:22 +00:00
|
|
|
use super::manifest::MANIFEST_BLOB_NAME;
|
|
|
|
|
2019-03-05 06:28:13 +00:00
|
|
|
/// BackupGroup is a directory containing a list of BackupDir
|
2020-01-17 09:39:32 +00:00
|
|
|
#[derive(Debug, Eq, PartialEq, Hash, Clone)]
|
2019-03-05 06:18:12 +00:00
|
|
|
pub struct BackupGroup {
|
|
|
|
/// Type of backup
|
2022-04-14 13:05:58 +00:00
|
|
|
backup_type: BackupType,
|
2019-03-05 06:18:12 +00:00
|
|
|
/// Unique (for this type) ID
|
|
|
|
backup_id: String,
|
|
|
|
}
|
|
|
|
|
2020-08-25 06:38:47 +00:00
|
|
|
impl std::cmp::Ord for BackupGroup {
|
|
|
|
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
|
|
|
|
let type_order = self.backup_type.cmp(&other.backup_type);
|
|
|
|
if type_order != std::cmp::Ordering::Equal {
|
|
|
|
return type_order;
|
|
|
|
}
|
|
|
|
// try to compare IDs numerically
|
|
|
|
let id_self = self.backup_id.parse::<u64>();
|
|
|
|
let id_other = other.backup_id.parse::<u64>();
|
|
|
|
match (id_self, id_other) {
|
|
|
|
(Ok(id_self), Ok(id_other)) => id_self.cmp(&id_other),
|
|
|
|
(Ok(_), Err(_)) => std::cmp::Ordering::Less,
|
|
|
|
(Err(_), Ok(_)) => std::cmp::Ordering::Greater,
|
2021-03-14 18:18:35 +00:00
|
|
|
_ => self.backup_id.cmp(&other.backup_id),
|
2020-08-25 06:38:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl std::cmp::PartialOrd for BackupGroup {
|
|
|
|
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
|
|
|
|
Some(self.cmp(other))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-05 06:18:12 +00:00
|
|
|
impl BackupGroup {
|
2022-04-14 13:05:58 +00:00
|
|
|
pub fn new<T: Into<String>>(backup_type: BackupType, backup_id: T) -> Self {
|
2021-03-14 18:18:35 +00:00
|
|
|
Self {
|
2022-04-14 13:05:58 +00:00
|
|
|
backup_type,
|
2021-03-14 18:18:35 +00:00
|
|
|
backup_id: backup_id.into(),
|
|
|
|
}
|
2019-03-05 06:18:12 +00:00
|
|
|
}
|
|
|
|
|
2022-04-14 13:05:58 +00:00
|
|
|
pub fn backup_type(&self) -> BackupType {
|
|
|
|
self.backup_type
|
2019-03-05 06:18:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn backup_id(&self) -> &str {
|
|
|
|
&self.backup_id
|
|
|
|
}
|
|
|
|
|
2021-03-14 18:18:35 +00:00
|
|
|
pub fn group_path(&self) -> PathBuf {
|
2019-03-05 06:18:12 +00:00
|
|
|
let mut relative_path = PathBuf::new();
|
|
|
|
|
2022-04-14 13:05:58 +00:00
|
|
|
relative_path.push(self.backup_type.as_str());
|
2019-03-05 06:18:12 +00:00
|
|
|
|
|
|
|
relative_path.push(&self.backup_id);
|
|
|
|
|
|
|
|
relative_path
|
|
|
|
}
|
2019-05-11 08:19:34 +00:00
|
|
|
|
|
|
|
pub fn list_backups(&self, base_path: &Path) -> Result<Vec<BackupInfo>, Error> {
|
|
|
|
let mut list = vec![];
|
|
|
|
|
|
|
|
let mut path = base_path.to_owned();
|
|
|
|
path.push(self.group_path());
|
|
|
|
|
2021-11-23 16:57:00 +00:00
|
|
|
proxmox_sys::fs::scandir(
|
2021-03-14 18:18:35 +00:00
|
|
|
libc::AT_FDCWD,
|
|
|
|
&path,
|
|
|
|
&BACKUP_DATE_REGEX,
|
|
|
|
|l2_fd, backup_time, file_type| {
|
|
|
|
if file_type != nix::dir::Type::Directory {
|
|
|
|
return Ok(());
|
|
|
|
}
|
2019-05-11 08:19:34 +00:00
|
|
|
|
2021-03-14 18:18:35 +00:00
|
|
|
let backup_dir =
|
2022-04-14 13:05:58 +00:00
|
|
|
BackupDir::with_rfc3339(self.backup_type, &self.backup_id, backup_time)?;
|
2021-03-14 18:18:35 +00:00
|
|
|
let files = list_backup_files(l2_fd, backup_time)?;
|
2019-05-11 08:19:34 +00:00
|
|
|
|
2021-10-27 11:22:26 +00:00
|
|
|
let protected = backup_dir.is_protected(base_path.to_owned());
|
|
|
|
|
2022-04-14 11:27:53 +00:00
|
|
|
list.push(BackupInfo {
|
|
|
|
backup_dir,
|
|
|
|
files,
|
|
|
|
protected,
|
|
|
|
});
|
2019-05-11 08:19:34 +00:00
|
|
|
|
2021-03-14 18:18:35 +00:00
|
|
|
Ok(())
|
|
|
|
},
|
|
|
|
)?;
|
2019-05-11 08:19:34 +00:00
|
|
|
Ok(list)
|
|
|
|
}
|
2019-12-04 14:49:11 +00:00
|
|
|
|
2022-04-20 07:55:48 +00:00
|
|
|
/// 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()))
|
|
|
|
}
|
|
|
|
|
2021-03-14 18:18:35 +00:00
|
|
|
pub fn last_successful_backup(&self, base_path: &Path) -> Result<Option<i64>, Error> {
|
2020-01-06 10:35:22 +00:00
|
|
|
let mut last = None;
|
|
|
|
|
|
|
|
let mut path = base_path.to_owned();
|
|
|
|
path.push(self.group_path());
|
|
|
|
|
2021-11-23 16:57:00 +00:00
|
|
|
proxmox_sys::fs::scandir(
|
2021-03-14 18:18:35 +00:00
|
|
|
libc::AT_FDCWD,
|
|
|
|
&path,
|
|
|
|
&BACKUP_DATE_REGEX,
|
|
|
|
|l2_fd, backup_time, file_type| {
|
|
|
|
if file_type != nix::dir::Type::Directory {
|
|
|
|
return Ok(());
|
2020-01-06 10:35:22 +00:00
|
|
|
}
|
|
|
|
|
2021-03-14 18:18:35 +00:00
|
|
|
let mut manifest_path = PathBuf::from(backup_time);
|
|
|
|
manifest_path.push(MANIFEST_BLOB_NAME);
|
|
|
|
|
|
|
|
use nix::fcntl::{openat, OFlag};
|
|
|
|
match openat(
|
|
|
|
l2_fd,
|
|
|
|
&manifest_path,
|
|
|
|
OFlag::O_RDONLY,
|
|
|
|
nix::sys::stat::Mode::empty(),
|
|
|
|
) {
|
|
|
|
Ok(rawfd) => {
|
|
|
|
/* manifest exists --> assume backup was successful */
|
|
|
|
/* close else this leaks! */
|
|
|
|
nix::unistd::close(rawfd)?;
|
|
|
|
}
|
|
|
|
Err(nix::Error::Sys(nix::errno::Errno::ENOENT)) => {
|
|
|
|
return Ok(());
|
|
|
|
}
|
|
|
|
Err(err) => {
|
|
|
|
bail!("last_successful_backup: unexpected error - {}", err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-08 09:19:37 +00:00
|
|
|
let timestamp = proxmox_time::parse_rfc3339(backup_time)?;
|
2021-03-14 18:18:35 +00:00
|
|
|
if let Some(last_timestamp) = last {
|
|
|
|
if timestamp > last_timestamp {
|
|
|
|
last = Some(timestamp);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
last = Some(timestamp);
|
|
|
|
}
|
2020-01-06 10:35:22 +00:00
|
|
|
|
2021-03-14 18:18:35 +00:00
|
|
|
Ok(())
|
|
|
|
},
|
|
|
|
)?;
|
2020-01-06 10:35:22 +00:00
|
|
|
|
|
|
|
Ok(last)
|
|
|
|
}
|
2021-10-28 13:00:50 +00:00
|
|
|
|
|
|
|
pub fn matches(&self, filter: &GroupFilter) -> bool {
|
|
|
|
match filter {
|
2021-12-30 11:57:37 +00:00
|
|
|
GroupFilter::Group(backup_group) => match BackupGroup::from_str(backup_group) {
|
2021-10-28 13:00:50 +00:00
|
|
|
Ok(group) => &group == self,
|
|
|
|
Err(_) => false, // shouldn't happen if value is schema-checked
|
|
|
|
},
|
2022-04-14 13:05:58 +00:00
|
|
|
GroupFilter::BackupType(backup_type) => self.backup_type().as_str() == backup_type,
|
2021-10-28 13:00:50 +00:00
|
|
|
GroupFilter::Regex(regex) => regex.is_match(&self.to_string()),
|
|
|
|
}
|
|
|
|
}
|
2019-03-05 06:18:12 +00:00
|
|
|
}
|
|
|
|
|
2022-04-14 13:05:58 +00:00
|
|
|
impl From<&BackupGroup> for pbs_api_types::BackupGroup {
|
|
|
|
fn from(group: &BackupGroup) -> pbs_api_types::BackupGroup {
|
|
|
|
(group.backup_type, group.backup_id.clone()).into()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<BackupGroup> for pbs_api_types::BackupGroup {
|
|
|
|
fn from(group: BackupGroup) -> pbs_api_types::BackupGroup {
|
|
|
|
(group.backup_type, group.backup_id).into()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-24 10:25:45 +00:00
|
|
|
impl std::fmt::Display for BackupGroup {
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
|
let backup_type = self.backup_type();
|
|
|
|
let id = self.backup_id();
|
|
|
|
write!(f, "{}/{}", backup_type, id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-23 06:16:56 +00:00
|
|
|
impl std::str::FromStr for BackupGroup {
|
|
|
|
type Err = Error;
|
|
|
|
|
|
|
|
/// Parse a backup group path
|
|
|
|
///
|
|
|
|
/// This parses strings like `vm/100".
|
|
|
|
fn from_str(path: &str) -> Result<Self, Self::Err> {
|
2021-03-14 18:18:35 +00:00
|
|
|
let cap = GROUP_PATH_REGEX
|
|
|
|
.captures(path)
|
2020-06-23 06:16:56 +00:00
|
|
|
.ok_or_else(|| format_err!("unable to parse backup group path '{}'", path))?;
|
|
|
|
|
|
|
|
Ok(Self {
|
2022-04-14 13:05:58 +00:00
|
|
|
backup_type: cap.get(1).unwrap().as_str().parse()?,
|
2020-06-23 06:16:56 +00:00
|
|
|
backup_id: cap.get(2).unwrap().as_str().to_owned(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-05 06:18:12 +00:00
|
|
|
/// Uniquely identify a Backup (relative to data store)
|
2019-03-05 06:28:13 +00:00
|
|
|
///
|
|
|
|
/// We also call this a backup snaphost.
|
2020-08-11 08:50:40 +00:00
|
|
|
#[derive(Debug, Eq, PartialEq, Clone)]
|
2019-03-05 06:18:12 +00:00
|
|
|
pub struct BackupDir {
|
|
|
|
/// Backup group
|
|
|
|
group: BackupGroup,
|
|
|
|
/// Backup timestamp
|
2020-09-12 13:10:47 +00:00
|
|
|
backup_time: i64,
|
|
|
|
// backup_time as rfc3339
|
2021-03-14 18:18:35 +00:00
|
|
|
backup_time_string: String,
|
2019-03-05 06:18:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl BackupDir {
|
2022-04-14 13:05:58 +00:00
|
|
|
pub fn new<T>(backup_type: BackupType, backup_id: T, backup_time: i64) -> Result<Self, Error>
|
2019-03-05 08:16:54 +00:00
|
|
|
where
|
|
|
|
T: Into<String>,
|
|
|
|
{
|
2022-04-14 13:05:58 +00:00
|
|
|
let group = BackupGroup::new(backup_type, backup_id.into());
|
2020-09-15 07:40:03 +00:00
|
|
|
BackupDir::with_group(group, backup_time)
|
2019-03-05 06:18:12 +00:00
|
|
|
}
|
2020-09-11 12:34:38 +00:00
|
|
|
|
2022-04-14 13:05:58 +00:00
|
|
|
pub fn with_rfc3339<T, U>(
|
|
|
|
backup_type: BackupType,
|
|
|
|
backup_id: T,
|
|
|
|
backup_time_string: U,
|
2021-03-14 18:18:35 +00:00
|
|
|
) -> Result<Self, Error>
|
2020-09-15 07:34:46 +00:00
|
|
|
where
|
|
|
|
T: Into<String>,
|
|
|
|
U: Into<String>,
|
|
|
|
{
|
2021-03-14 18:18:35 +00:00
|
|
|
let backup_time_string = backup_time_string.into();
|
2021-10-08 09:19:37 +00:00
|
|
|
let backup_time = proxmox_time::parse_rfc3339(&backup_time_string)?;
|
2022-04-14 13:05:58 +00:00
|
|
|
let group = BackupGroup::new(backup_type, backup_id.into());
|
2021-03-14 18:18:35 +00:00
|
|
|
Ok(Self {
|
|
|
|
group,
|
|
|
|
backup_time,
|
|
|
|
backup_time_string,
|
|
|
|
})
|
2020-09-15 07:34:46 +00:00
|
|
|
}
|
|
|
|
|
2020-09-15 07:40:03 +00:00
|
|
|
pub fn with_group(group: BackupGroup, backup_time: i64) -> Result<Self, Error> {
|
2020-09-12 13:10:47 +00:00
|
|
|
let backup_time_string = Self::backup_time_to_string(backup_time)?;
|
2021-03-14 18:18:35 +00:00
|
|
|
Ok(Self {
|
|
|
|
group,
|
|
|
|
backup_time,
|
|
|
|
backup_time_string,
|
|
|
|
})
|
2019-05-11 10:07:09 +00:00
|
|
|
}
|
2019-03-05 06:18:12 +00:00
|
|
|
|
|
|
|
pub fn group(&self) -> &BackupGroup {
|
|
|
|
&self.group
|
|
|
|
}
|
|
|
|
|
2020-09-12 13:10:47 +00:00
|
|
|
pub fn backup_time(&self) -> i64 {
|
2019-03-05 06:18:12 +00:00
|
|
|
self.backup_time
|
|
|
|
}
|
|
|
|
|
2020-09-12 13:10:47 +00:00
|
|
|
pub fn backup_time_string(&self) -> &str {
|
|
|
|
&self.backup_time_string
|
|
|
|
}
|
|
|
|
|
2021-03-14 18:18:35 +00:00
|
|
|
pub fn relative_path(&self) -> PathBuf {
|
2019-03-05 06:18:12 +00:00
|
|
|
let mut relative_path = self.group.group_path();
|
|
|
|
|
2020-09-12 13:10:47 +00:00
|
|
|
relative_path.push(self.backup_time_string.clone());
|
2019-03-05 06:18:12 +00:00
|
|
|
|
|
|
|
relative_path
|
|
|
|
}
|
2019-07-22 08:12:51 +00:00
|
|
|
|
2021-10-27 11:22:26 +00:00
|
|
|
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()
|
|
|
|
}
|
|
|
|
|
2020-09-12 13:10:47 +00:00
|
|
|
pub fn backup_time_to_string(backup_time: i64) -> Result<String, Error> {
|
|
|
|
// fixme: can this fail? (avoid unwrap)
|
2022-02-08 13:57:16 +00:00
|
|
|
proxmox_time::epoch_to_rfc3339_utc(backup_time)
|
2019-07-22 08:12:51 +00:00
|
|
|
}
|
2019-03-05 06:18:12 +00:00
|
|
|
}
|
2020-06-23 06:16:56 +00:00
|
|
|
|
2022-04-14 13:05:58 +00:00
|
|
|
impl From<&BackupDir> for pbs_api_types::BackupDir {
|
|
|
|
fn from(dir: &BackupDir) -> pbs_api_types::BackupDir {
|
|
|
|
(
|
|
|
|
pbs_api_types::BackupGroup::from(dir.group.clone()),
|
|
|
|
dir.backup_time,
|
|
|
|
)
|
|
|
|
.into()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<BackupDir> for pbs_api_types::BackupDir {
|
|
|
|
fn from(dir: BackupDir) -> pbs_api_types::BackupDir {
|
|
|
|
(pbs_api_types::BackupGroup::from(dir.group), dir.backup_time).into()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-23 06:09:52 +00:00
|
|
|
impl std::str::FromStr for BackupDir {
|
|
|
|
type Err = Error;
|
|
|
|
|
|
|
|
/// Parse a snapshot path
|
|
|
|
///
|
|
|
|
/// This parses strings like `host/elsa/2020-06-15T05:18:33Z".
|
|
|
|
fn from_str(path: &str) -> Result<Self, Self::Err> {
|
2021-03-14 18:18:35 +00:00
|
|
|
let cap = SNAPSHOT_PATH_REGEX
|
|
|
|
.captures(path)
|
2020-06-23 06:09:52 +00:00
|
|
|
.ok_or_else(|| format_err!("unable to parse backup snapshot path '{}'", path))?;
|
|
|
|
|
2020-09-15 07:34:46 +00:00
|
|
|
BackupDir::with_rfc3339(
|
2022-04-14 13:05:58 +00:00
|
|
|
cap.get(1).unwrap().as_str().parse()?,
|
2020-09-15 07:34:46 +00:00
|
|
|
cap.get(2).unwrap().as_str(),
|
|
|
|
cap.get(3).unwrap().as_str(),
|
|
|
|
)
|
2020-06-23 06:09:52 +00:00
|
|
|
}
|
|
|
|
}
|
2019-03-05 06:18:12 +00:00
|
|
|
|
2020-06-19 06:05:09 +00:00
|
|
|
impl std::fmt::Display for BackupDir {
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
|
let backup_type = self.group.backup_type();
|
|
|
|
let id = self.group.backup_id();
|
2020-09-12 13:10:47 +00:00
|
|
|
write!(f, "{}/{}/{}", backup_type, id, self.backup_time_string)
|
2019-03-05 08:16:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-05 06:28:13 +00:00
|
|
|
/// Detailed Backup Information, lists files inside a BackupDir
|
2019-05-11 09:21:13 +00:00
|
|
|
#[derive(Debug, Clone)]
|
2019-03-05 06:18:12 +00:00
|
|
|
pub struct BackupInfo {
|
|
|
|
/// the backup directory
|
|
|
|
pub backup_dir: BackupDir,
|
|
|
|
/// List of data files
|
|
|
|
pub files: Vec<String>,
|
2021-10-27 11:22:26 +00:00
|
|
|
/// Protection Status
|
|
|
|
pub protected: bool,
|
2019-03-05 06:18:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl BackupInfo {
|
2019-08-07 06:27:52 +00:00
|
|
|
pub fn new(base_path: &Path, backup_dir: BackupDir) -> Result<BackupInfo, Error> {
|
|
|
|
let mut path = base_path.to_owned();
|
|
|
|
path.push(backup_dir.relative_path());
|
|
|
|
|
|
|
|
let files = list_backup_files(libc::AT_FDCWD, &path)?;
|
2021-10-27 11:22:26 +00:00
|
|
|
let protected = backup_dir.is_protected(base_path.to_owned());
|
2019-08-07 06:27:52 +00:00
|
|
|
|
2022-04-14 11:27:53 +00:00
|
|
|
Ok(BackupInfo {
|
|
|
|
backup_dir,
|
|
|
|
files,
|
|
|
|
protected,
|
|
|
|
})
|
2019-08-07 06:27:52 +00:00
|
|
|
}
|
|
|
|
|
2019-03-05 06:18:12 +00:00
|
|
|
pub fn sort_list(list: &mut Vec<BackupInfo>, ascendending: bool) {
|
2021-03-14 18:18:35 +00:00
|
|
|
if ascendending {
|
|
|
|
// oldest first
|
2019-03-05 06:18:12 +00:00
|
|
|
list.sort_unstable_by(|a, b| a.backup_dir.backup_time.cmp(&b.backup_dir.backup_time));
|
2021-03-14 18:18:35 +00:00
|
|
|
} else {
|
|
|
|
// newest first
|
2019-03-05 06:18:12 +00:00
|
|
|
list.sort_unstable_by(|a, b| b.backup_dir.backup_time.cmp(&a.backup_dir.backup_time));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-06 09:49:01 +00:00
|
|
|
pub fn list_files(base_path: &Path, backup_dir: &BackupDir) -> Result<Vec<String>, Error> {
|
|
|
|
let mut path = base_path.to_owned();
|
|
|
|
path.push(backup_dir.relative_path());
|
|
|
|
|
2019-05-11 08:19:34 +00:00
|
|
|
let files = list_backup_files(libc::AT_FDCWD, &path)?;
|
2019-03-06 09:49:01 +00:00
|
|
|
|
|
|
|
Ok(files)
|
|
|
|
}
|
|
|
|
|
2020-07-29 12:33:11 +00:00
|
|
|
pub fn is_finished(&self) -> bool {
|
|
|
|
// backup is considered unfinished if there is no manifest
|
2022-04-14 11:27:53 +00:00
|
|
|
self.files.iter().any(|name| name == MANIFEST_BLOB_NAME)
|
2020-07-29 12:33:11 +00:00
|
|
|
}
|
2019-03-05 06:18:12 +00:00
|
|
|
}
|
2019-05-11 08:19:34 +00:00
|
|
|
|
2021-03-14 18:18:35 +00:00
|
|
|
fn list_backup_files<P: ?Sized + nix::NixPath>(
|
|
|
|
dirfd: RawFd,
|
|
|
|
path: &P,
|
|
|
|
) -> Result<Vec<String>, Error> {
|
2019-05-11 08:19:34 +00:00
|
|
|
let mut files = vec![];
|
|
|
|
|
2021-11-23 16:57:00 +00:00
|
|
|
proxmox_sys::fs::scandir(dirfd, path, &BACKUP_FILE_REGEX, |_, filename, file_type| {
|
2021-03-14 18:18:35 +00:00
|
|
|
if file_type != nix::dir::Type::File {
|
|
|
|
return Ok(());
|
|
|
|
}
|
2019-05-11 08:19:34 +00:00
|
|
|
files.push(filename.to_owned());
|
|
|
|
Ok(())
|
|
|
|
})?;
|
|
|
|
|
|
|
|
Ok(files)
|
|
|
|
}
|