From 2938409cff80d66b4b9f672ab48d2d93822c4aa2 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sun, 20 Mar 2022 07:53:06 +0200 Subject: feat: add subcommands inspect, list-backup-versions Sponsored-by: author --- src/cmd/inspect.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/cmd/inspect.rs (limited to 'src/cmd/inspect.rs') diff --git a/src/cmd/inspect.rs b/src/cmd/inspect.rs new file mode 100644 index 0000000..d5a75c6 --- /dev/null +++ b/src/cmd/inspect.rs @@ -0,0 +1,40 @@ +//! The `inspect` subcommand. + +use crate::client::BackupClient; +use crate::config::ClientConfig; +use crate::error::ObnamError; + +use log::info; +use structopt::StructOpt; +use tempfile::NamedTempFile; +use tokio::runtime::Runtime; + +/// Make a backup. +#[derive(Debug, StructOpt)] +pub struct Inspect { + /// Reference to generation to inspect. + #[structopt()] + gen_id: String, +} + +impl Inspect { + /// Run the command. + 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 temp = NamedTempFile::new()?; + let client = BackupClient::new(config)?; + let genlist = client.list_generations().await?; + let gen_id = genlist.resolve(&self.gen_id)?; + info!("generation id is {}", gen_id.as_chunk_id()); + + let gen = client.fetch_generation(&gen_id, temp.path()).await?; + let meta = gen.meta()?; + println!("schema_version: {}", meta.schema_version()); + + Ok(()) + } +} -- cgit v1.2.1