btrbk
btrbk copied to clipboard
Machine-readable output of `btrbk list`
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.
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
}
I hope to get a JSON output too. It'd be bery appreciated!