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