Skip to content

Restic snapshot detail json to csv

wordpress meta

title: 'Restic snapshot detail json to csv'
date: '2019-10-25T12:57:05-05:00'
status: publish
permalink: /restic-snapshot-detail-json-to-csv
author: admin
excerpt: ''
type: post
id: 1409
category:
    - Uncategorized
tag: []
post_format: []

Restic shows details of a snapshot. Sometimes you want that to be CSV but the json output for paths, excludes and tags are lists which will choke the @csv jq filter. Furthermore not all snapshots have the excludes key. Here are some snippets on solving above. Use join to collapse the lists and use if to test if key exists.

``` # restic -r $REPO snapshots --last --json | jq -r '.[] | [.hostname,.short_id,.time,(.paths|join(",")),if (.excludes) then (.excludes|join(",")) else empty end]' [ "bkupserver.domain.com", "c56d3e2e", "2019-10-25T00:10:01.767408581-05:00", "/etc,/home,/root,/u01/backuplogs,/var/log,/var/spool/cron", "**/diag/**,/var/spool/lastlog" ]
</div>And using CSV filter

<div class="wp-block-syntaxhighlighter-code ">```

# restic -r $REPO snapshots --last --json | jq -r '.[] | [.hostname,.short_id,.time,(.paths|join(",")),if (.excludes) then (.excludes|join(",")) else empty end] | @csv'
"bkupserver.domain.com","c56d3e2e","2019-10-25T00:10:01.767408581-05:00","/etc,/home,/root,/u01/backuplogs,/var/log,/var/spool/cron","**/diag/**,/var/spool/lastlog"