2022-04-15 10:24:56 +00:00
|
|
|
use std::path::PathBuf;
|
|
|
|
|
|
|
|
use anyhow::{bail, Error};
|
|
|
|
|
2022-04-20 13:30:04 +00:00
|
|
|
use pbs_datastore::DataStore;
|
2022-04-15 10:24:56 +00:00
|
|
|
|
|
|
|
fn run() -> Result<(), Error> {
|
2022-05-15 14:01:09 +00:00
|
|
|
let base: PathBuf = match std::env::args().nth(1) {
|
2022-04-15 10:24:56 +00:00
|
|
|
Some(path) => path.into(),
|
2022-05-05 15:17:02 +00:00
|
|
|
None => bail!("no path passed!\n\nusage: ls-snapshots <path> [<max-depth>]"),
|
|
|
|
};
|
2022-05-15 14:01:09 +00:00
|
|
|
let max_depth: Option<usize> = match std::env::args().nth(2) {
|
2022-05-05 15:17:02 +00:00
|
|
|
Some(depth) => match depth.parse::<usize>() {
|
|
|
|
Ok(depth) if depth < 8 => Some(depth),
|
|
|
|
Ok(_) => bail!("max-depth must be < 8"),
|
|
|
|
Err(err) => bail!("couldn't parse max-depth from {depth} - {err}"),
|
|
|
|
},
|
|
|
|
None => None,
|
2022-04-15 10:24:56 +00:00
|
|
|
};
|
|
|
|
|
2022-04-20 13:30:04 +00:00
|
|
|
let store = unsafe { DataStore::open_path("", &base, None)? };
|
|
|
|
|
2022-05-05 15:17:02 +00:00
|
|
|
for ns in store.recursive_iter_backup_ns_ok(Default::default(), max_depth)? {
|
2022-04-24 18:23:30 +00:00
|
|
|
println!("found namespace store:/{}", ns);
|
2022-04-15 10:24:56 +00:00
|
|
|
|
2022-04-24 18:23:30 +00:00
|
|
|
for group in store.iter_backup_groups(ns)? {
|
|
|
|
let group = group?;
|
2022-05-16 09:00:30 +00:00
|
|
|
println!(" found group {}", group.group());
|
2022-04-24 18:23:30 +00:00
|
|
|
|
|
|
|
for snapshot in group.iter_snapshots()? {
|
2022-05-16 08:33:59 +00:00
|
|
|
let snapshot = snapshot?;
|
|
|
|
println!("\t{}", snapshot.dir());
|
2022-04-24 18:23:30 +00:00
|
|
|
}
|
2022-04-15 10:24:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
std::process::exit(match run() {
|
|
|
|
Ok(_) => 0,
|
|
|
|
Err(err) => {
|
|
|
|
eprintln!("error: {}", err);
|
|
|
|
1
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|