-
-
Notifications
You must be signed in to change notification settings - Fork 812
Open
Labels
Milestone
Description
Discussed in #7021
Originally posted by WilliamDEdwards September 12, 2022
I'd like to programmatically extract the archive names that Borg pruned. E.g. with a --json switch for borg prune --list (like borg list has).
--log-json is not easily parseable:
$ borg prune --log-json --list pen --keep-last 2
{"type": "log_message", "time": 1662974892.256543, "message": "Keeping archive (rule: secondly #1): mac Mon, 2022-09-12 11:25:59 [aff7f431a4a027ec328437e3d38dd72c86cc81a1ab3099b033d10f1e9e79388a]", "levelname": "INFO", "name": "borg.output.list"}
>>> import json
>>> line = '{"type": "log_message", "time": 1662974892.256543, "message": "Keeping archive (rule: secondly #1): mac Mon, 2022-09-12 11:25:59 [aff7f431a4a027ec328437e3d38dd72c86cc81a1ab3099b033d10f1e9e79388a]", "levelname": "INFO", "name": "borg.output.list"}'
>>> line = json.loads(line)
>>> line['message'].split()
['Keeping', 'archive', '(rule:', 'secondly', '#1):', 'mac', 'Mon,', '2022-09-12', '11:25:59', '[aff7f431a4a027ec328437e3d38dd72c86cc81a1ab3099b033d10f1e9e79388a]']
>>> _[5]
'mac'
```</div>
dvdheiden and WilliamDEdwards