use failure::*;
use nix::unistd::{fork, ForkResult, pipe};
use std::os::unix::io::RawFd;
-use chrono::{Local, Utc, TimeZone};
+use chrono::{Local, DateTime, Utc, TimeZone};
use std::path::{Path, PathBuf};
use std::collections::{HashSet, HashMap};
use std::ffi::OsStr;
Ok(list)
}
+async fn api_datastore_latest_snapshot(
+ client: &HttpClient,
+ store: &str,
+ group: BackupGroup,
+) -> Result<(String, String, DateTime<Utc>), Error> {
+
+ let mut list = api_datastore_list_snapshots(client, store, Some(group.clone())).await?;
+
+ if list.is_empty() {
+ bail!("backup group {:?} does not contain any snapshots.", group.group_path());
+ }
+
+ list.sort_unstable_by(|a, b| b.backup_time.cmp(&a.backup_time));
+
+ let backup_time = Utc.timestamp(list[0].backup_time, 0);
+
+ Ok((group.backup_type().to_owned(), group.backup_id().to_owned(), backup_time))
+}
+
+
async fn backup_directory<P: AsRef<Path>>(
client: &BackupWriter,
dir_path: P,
let (backup_type, backup_id, backup_time) = if path.matches('/').count() == 1 {
let group = BackupGroup::parse(path)?;
-
- let mut list = api_datastore_list_snapshots(&client, repo.store(), Some(group.clone())).await?;
-
- if list.is_empty() {
- bail!("backup group '{}' does not contain any snapshots:", path);
- }
- list.sort_unstable_by(|a, b| b.backup_time.cmp(&a.backup_time));
-
- let backup_time = Utc.timestamp(list[0].backup_time, 0);
-
- (group.backup_type().to_owned(), group.backup_id().to_owned(), backup_time)
+ api_datastore_latest_snapshot(&client, repo.store(), group).await?
} else {
let snapshot = BackupDir::parse(path)?;
(snapshot.group().backup_type().to_owned(), snapshot.group().backup_id().to_owned(), snapshot.backup_time())
let path = tools::required_string_param(¶m, "snapshot")?;
let (backup_type, backup_id, backup_time) = if path.matches('/').count() == 1 {
let group = BackupGroup::parse(path)?;
-
- let mut list = api_datastore_list_snapshots(&client, repo.store(), Some(group.clone())).await?;
-
- if list.is_empty() {
- bail!("backup group '{}' does not contain any snapshots:", path);
- }
-
- list.sort_unstable_by(|a, b| b.backup_time.cmp(&a.backup_time));
-
- let backup_time = Utc.timestamp(list[0].backup_time, 0);
-
- (group.backup_type().to_owned(), group.backup_id().to_owned(), backup_time)
+ api_datastore_latest_snapshot(&client, repo.store(), group).await?
} else {
let snapshot = BackupDir::parse(path)?;
(snapshot.group().backup_type().to_owned(), snapshot.group().backup_id().to_owned(), snapshot.backup_time())
let (backup_type, backup_id, backup_time) = if path.matches('/').count() == 1 {
let group = BackupGroup::parse(path)?;
-
- let mut list = api_datastore_list_snapshots(&client, repo.store(), Some(group.clone())).await?;
-
- if list.is_empty() {
- bail!("backup group '{}' does not contain any snapshots:", path);
- }
-
- list.sort_unstable_by(|a, b| b.backup_time.cmp(&a.backup_time));
-
- let backup_time = Utc.timestamp(list[0].backup_time, 0);
-
- (group.backup_type().to_owned(), group.backup_id().to_owned(), backup_time)
+ api_datastore_latest_snapshot(&client, repo.store(), group).await?
} else {
let snapshot = BackupDir::parse(path)?;
(snapshot.group().backup_type().to_owned(), snapshot.group().backup_id().to_owned(), snapshot.backup_time())