{"id":1409,"date":"2019-10-25T12:57:05","date_gmt":"2019-10-25T17:57:05","guid":{"rendered":"http:\/\/blog.ls-al.com\/?p=1409"},"modified":"2019-10-25T12:57:06","modified_gmt":"2019-10-25T17:57:06","slug":"restic-snapshot-detail-json-to-csv","status":"publish","type":"post","link":"https:\/\/blog.ls-al.com\/restic-snapshot-detail-json-to-csv\/","title":{"rendered":"Restic snapshot detail json to csv"},"content":{"rendered":"\n

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.<\/p>\n\n\n

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

And using CSV filter<\/p>\n\n\n

\n# restic -r $REPO snapshots --last --json | jq -r '.[] | [.hostname,.short_id,.time,(.paths|join(",")),if (.excludes) then (.excludes|join(",")) else empty end] | @csv'\n"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"\n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"

Restic shows details of a snapshot. Sometimes you want that to be CSV but the json output for paths, excludes<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1409","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts\/1409","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/comments?post=1409"}],"version-history":[{"count":0,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts\/1409\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/media?parent=1409"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/categories?post=1409"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/tags?post=1409"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}