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:
34
pbs-datastore/examples/ls-snapshots.rs
Normal file
34
pbs-datastore/examples/ls-snapshots.rs
Normal 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
|
||||
}
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user