diff options
author | Lars Wirzenius <liw@liw.fi> | 2021-10-24 09:59:45 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2021-10-24 11:37:20 +0300 |
commit | 574b8e2c74f3174b15d3d80a21d86cbb10268b15 (patch) | |
tree | 2eb1f525826e0dba2bfe67e964c07792d20dd52c /src/cmd | |
parent | 60cb5be04ecd313f4ea508f66951957d9644fa01 (diff) | |
download | obnam2-574b8e2c74f3174b15d3d80a21d86cbb10268b15.tar.gz |
feat! store schema version of generation database in the db
Add a new mandatory database table "meta" to the SQLite database the
stores information about the files in a backup generation. The idea is
for future versions of the Obnam client to be able to be able to
restore from backups made by older -- or newer -- versions of Obnam,
as far as is reasonable.
Add the `obnam gen-info` command to show information about the
generation metadata.
Sponsored-by: author
Diffstat (limited to 'src/cmd')
-rw-r--r-- | src/cmd/gen_info.rs | 36 | ||||
-rw-r--r-- | src/cmd/mod.rs | 1 |
2 files changed, 37 insertions, 0 deletions
diff --git a/src/cmd/gen_info.rs b/src/cmd/gen_info.rs new file mode 100644 index 0000000..6d12bd8 --- /dev/null +++ b/src/cmd/gen_info.rs @@ -0,0 +1,36 @@ +use crate::client::AsyncBackupClient; +use crate::config::ClientConfig; +use crate::error::ObnamError; +use log::info; +use structopt::StructOpt; +use tempfile::NamedTempFile; +use tokio::runtime::Runtime; + +#[derive(Debug, StructOpt)] +pub struct GenInfo { + #[structopt()] + gen_ref: String, +} + +impl GenInfo { + 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 = AsyncBackupClient::new(config)?; + + let genlist = client.list_generations().await?; + let gen_id = genlist.resolve(&self.gen_ref)?; + info!("generation id is {}", gen_id.as_chunk_id()); + + let gen = client.fetch_generation(&gen_id, temp.path()).await?; + let meta = gen.meta()?; + println!("{}", serde_json::to_string_pretty(&meta)?); + + Ok(()) + } +} diff --git a/src/cmd/mod.rs b/src/cmd/mod.rs index 502ec5d..ee5efd9 100644 --- a/src/cmd/mod.rs +++ b/src/cmd/mod.rs @@ -1,6 +1,7 @@ pub mod backup; pub mod chunk; pub mod chunkify; +pub mod gen_info; pub mod get_chunk; pub mod init; pub mod list; |