summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-08-01 20:21:02 +0300
committerLars Wirzenius <liw@liw.fi>2021-08-01 20:55:03 +0300
commit0835677f33fe8fa89ee96e4c1b45e5711e10b461 (patch)
tree0552880f3cff7141b4410ba1a90b9b7d1a87fe32
parent4c6206a2cb1f8c1efba9fd08a4d6b4fa7d09a6dc (diff)
downloadobnam2-0835677f33fe8fa89ee96e4c1b45e5711e10b461.tar.gz
feat: add command to resolve a generation ref into a chunk id
Sponsored-by: author
-rw-r--r--obnam.md2
-rw-r--r--src/bin/obnam.rs3
-rw-r--r--src/cmd/mod.rs1
-rw-r--r--src/cmd/resolve.rs33
4 files changed, 39 insertions, 0 deletions
diff --git a/obnam.md b/obnam.md
index decb28c..5386dea 100644
--- a/obnam.md
+++ b/obnam.md
@@ -1278,6 +1278,8 @@ when I run obnam backup
then backup generation is GEN
when I run obnam list
then generation list contains <GEN>
+when I run obnam resolve latest
+then generation list contains <GEN>
when I invoke obnam restore <GEN> rest
given a manifest of the directory live restored in rest in rest.yaml
then manifests live.yaml and rest.yaml match
diff --git a/src/bin/obnam.rs b/src/bin/obnam.rs
index 29de2eb..b2d5683 100644
--- a/src/bin/obnam.rs
+++ b/src/bin/obnam.rs
@@ -9,6 +9,7 @@ use obnam::cmd::get_chunk::GetChunk;
use obnam::cmd::init::Init;
use obnam::cmd::list::List;
use obnam::cmd::list_files::ListFiles;
+use obnam::cmd::resolve::Resolve;
use obnam::cmd::restore::Restore;
use obnam::cmd::show_config::ShowConfig;
use obnam::cmd::show_gen::ShowGeneration;
@@ -44,6 +45,7 @@ fn main_program() -> anyhow::Result<()> {
Command::List(x) => x.run(&config),
Command::ShowGeneration(x) => x.run(&config),
Command::ListFiles(x) => x.run(&config),
+ Command::Resolve(x) => x.run(&config),
Command::Restore(x) => x.run(&config),
Command::GetChunk(x) => x.run(&config),
Command::Config(x) => x.run(&config),
@@ -102,6 +104,7 @@ enum Command {
ListFiles(ListFiles),
Restore(Restore),
ShowGeneration(ShowGeneration),
+ Resolve(Resolve),
GetChunk(GetChunk),
Config(ShowConfig),
EncryptChunk(EncryptChunk),
diff --git a/src/cmd/mod.rs b/src/cmd/mod.rs
index 7313a05..502ec5d 100644
--- a/src/cmd/mod.rs
+++ b/src/cmd/mod.rs
@@ -5,6 +5,7 @@ pub mod get_chunk;
pub mod init;
pub mod list;
pub mod list_files;
+pub mod resolve;
pub mod restore;
pub mod show_config;
pub mod show_gen;
diff --git a/src/cmd/resolve.rs b/src/cmd/resolve.rs
new file mode 100644
index 0000000..a175655
--- /dev/null
+++ b/src/cmd/resolve.rs
@@ -0,0 +1,33 @@
+use crate::client::AsyncBackupClient;
+use crate::config::ClientConfig;
+use crate::error::ObnamError;
+use structopt::StructOpt;
+use tokio::runtime::Runtime;
+
+#[derive(Debug, StructOpt)]
+pub struct Resolve {
+ generation: String,
+}
+
+impl Resolve {
+ pub fn run(&self, config: &ClientConfig) -> Result<(), ObnamError> {
+ let rt = Runtime::new()?;
+ rt.block_on(self.run_async(config))
+ }
+
+ async fn run_async(&self, config: &ClientConfig) -> Result<(), ObnamError> {
+ let client = AsyncBackupClient::new(config)?;
+ let generations = client.list_generations().await?;
+
+ match generations.resolve(&self.generation) {
+ Err(err) => {
+ return Err(err.into());
+ }
+ Ok(old_id) => {
+ println!("{}", old_id);
+ }
+ };
+
+ Ok(())
+ }
+}