Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Machine-readable output of btrbk list #606

Open
Atemu opened this issue Nov 16, 2024 · 1 comment
Open

Machine-readable output of btrbk list #606

Atemu opened this issue Nov 16, 2024 · 1 comment

Comments

@Atemu
Copy link

Atemu commented Nov 16, 2024

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.

@dkebler
Copy link

dkebler commented Dec 4, 2024

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

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants