summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2020-12-30 15:06:30 +0200
committerLars Wirzenius <liw@liw.fi>2020-12-30 15:25:49 +0200
commit6bc74795a009a35a0c1a27426b619b9f20a2db8e (patch)
tree682655b00b49a3ad477cfee0b4271344e30b3170 /src
parent776b2c134c3096b8a7cf1742cbcda13f0527e415 (diff)
downloadobnam2-6bc74795a009a35a0c1a27426b619b9f20a2db8e.tar.gz
feat: allow restoring latest generation
Diffstat (limited to 'src')
-rw-r--r--src/cmd/restore.rs10
-rw-r--r--src/lib.rs1
2 files changed, 10 insertions, 1 deletions
diff --git a/src/cmd/restore.rs b/src/cmd/restore.rs
index dd7ed41..9e137f2 100644
--- a/src/cmd/restore.rs
+++ b/src/cmd/restore.rs
@@ -1,5 +1,6 @@
use crate::client::BackupClient;
use crate::client::ClientConfig;
+use crate::error::ObnamError;
use crate::fsentry::{FilesystemEntry, FilesystemKind};
use crate::generation::NascentGeneration;
use indicatif::{ProgressBar, ProgressStyle};
@@ -14,7 +15,7 @@ use std::path::{Path, PathBuf};
use structopt::StructOpt;
use tempfile::NamedTempFile;
-pub fn restore(config: &ClientConfig, gen_id: &str, to: &Path) -> anyhow::Result<()> {
+pub fn restore(config: &ClientConfig, gen_ref: &str, to: &Path) -> anyhow::Result<()> {
// Create a named temporary file. We don't meed the open file
// handle, so we discard that.
let dbname = {
@@ -24,6 +25,13 @@ pub fn restore(config: &ClientConfig, gen_id: &str, to: &Path) -> anyhow::Result
};
let client = BackupClient::new(&config.server_url)?;
+
+ let genlist = client.list_generations()?;
+ let gen_id: String = match genlist.resolve(gen_ref) {
+ None => return Err(ObnamError::UnknownGeneration(gen_ref.to_string()).into()),
+ Some(id) => id,
+ };
+
let gen_chunk = client.fetch_generation(&gen_id)?;
debug!("gen: {:?}", gen_chunk);
diff --git a/src/lib.rs b/src/lib.rs
index 1880758..a06d396 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -6,6 +6,7 @@ pub mod chunkid;
pub mod chunkmeta;
pub mod client;
pub mod cmd;
+pub mod error;
pub mod fsentry;
pub mod fsiter;
pub mod generation;