datastore: add snapshot iterator and provide example

will be more used in the future, when the upend-datastore master plan
comes in effect.

also a preparatory work for namespaces

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht
2022-04-15 12:24:56 +02:00
parent 249dde8b63
commit 33eb23d57e
3 changed files with 81 additions and 2 deletions

View File

@ -0,0 +1,34 @@
use std::path::PathBuf;
use anyhow::{bail, Error};
use pbs_datastore::{ListGroups, ListSnapshots};
fn run() -> Result<(), Error> {
let base: PathBuf = match std::env::args().skip(1).next() {
Some(path) => path.into(),
None => bail!("no path passed"),
};
for group in ListGroups::new(base.to_owned())? {
let group = group?;
println!("found group {}", group);
let group_path = base.as_path().join(group.to_string());
for snapshot in ListSnapshots::new(group, group_path)? {
println!("\t{}", snapshot?);
}
}
Ok(())
}
fn main() {
std::process::exit(match run() {
Ok(_) => 0,
Err(err) => {
eprintln!("error: {}", err);
1
}
});
}