btrbk icon indicating copy to clipboard operation
btrbk copied to clipboard

Machine-readable output of `btrbk list`

Open Atemu opened this issue 1 year ago • 1 comments

I have a use-case where I need to determine the latest btrbk snapshot for some subvol.

I had to resort to parsing the raw format using a regex:

btrbk list --format=raw | rg "^.* snapshot_subvolume='(/.*?/snapshotnamehere\..*?)' .*$" --replace '$1' | tail -n 1

This would have been much simpler (not to mention more robust) if there was an option to output a standardised machine-readable format such as JSON.

Atemu avatar Nov 16 '24 04:11 Atemu

this is what I do. Does not make use of raw but btrbk custom format. Yes json would be nice.

btrbk_latest() {

local file=$(btrbk_conf $1)    
[[ ! $file ]] && echo unable to find conf file for ${1:-btrbk.conf} && return 1
shift

local latest=$(sudo btrbk -c $file list latest --format col:h:snapshot_subvolume | xargs -I % sh -c 'basename %' | sed '$!N; /^\(.*\)\n\1$/!P; D')
echo $latest

}

dkebler avatar Dec 04 '24 20:12 dkebler

I hope to get a JSON output too. It'd be bery appreciated!

aventrax avatar Sep 06 '25 08:09 aventrax