{"id":1365,"date":"2019-06-30T11:56:32","date_gmt":"2019-06-30T16:56:32","guid":{"rendered":"http:\/\/blog.ls-al.com\/?p=1365"},"modified":"2019-06-30T11:57:24","modified_gmt":"2019-06-30T16:57:24","slug":"restic-json-output-and-jq","status":"publish","type":"post","link":"https:\/\/blog.ls-al.com\/restic-json-output-and-jq\/","title":{"rendered":"Restic json output and jq"},"content":{"rendered":"\n
Restic has the ability to show output in json. Here is how I used it for some CSV type reporting I needed on backup jobs.<\/p>\n\n\n\n
Example json output.<\/p>\n\n\n
\n# restic -r rclone:s3_phx:\/restic-backup backup \/root --json | jq -r 'select(.message_type=="summary")'\n{\n "message_type": "summary",\n "files_new": 0,\n "files_changed": 0,\n "files_unmodified": 761,\n "dirs_new": 0,\n "dirs_changed": 0,\n "dirs_unmodified": 0,\n "data_blobs": 0,\n "tree_blobs": 0,\n "data_added": 0,\n "total_files_processed": 761,\n "total_bytes_processed": 251861194,\n "total_duration": 1.118076434,\n "snapshot_id": "09d1a6b9"\n}\n<\/pre><\/div>\n\n\nWith @csv filter.<\/p>\n\n\n
\n# restic -r rclone:s3_phx:\/restic-backup backup \/root --json | jq -r 'select(.message_type=="summary") | [.files_new,.files_changed,.files_unmodified,.dirs_new,.dirs_changed,.dirs_unmodified,.data_blobs,.tree_blobs,.data_added,.total_files_processed,.total_bytes_processed,.total_duration,.snapshot_id] | @csv'\n0,0,764,0,0,0,0,0,0,764,251918381,1.037043765,"3a55b3b3"\n<\/pre><\/div>\n\n\nI needed double quotes and could not figure out how to tell @csv filter to quote so below workaround for now. This was then usable in my bash script.<\/p>\n\n\n
\n# restic -r rclone:s3_phx:\/restic-backup backup \/root --json | jq -r 'select(.message_type=="summary") | "\\"\\(.files_new)\\",\\"\\(.files_changed)\\",\\"\\(.files_unmodified)\\",\\"\\(.dirs_new)\\",\\"\\(.dirs_changed)\\",\\"\\(.dirs_unmodified)\\",\\"\\(.data_blobs)\\",\\"\\(.tree_blobs)\\",\\"\\(.data_added)\\",\\"\\(.total_files_processed)\\",\\"\\(.total_bytes_processed)\\",\\"\\(.total_duration)\\",\\"\\(.snapshot_id)\\""'\n"0","3","761","0","0","0","3","1","2901845","764","251920790","2.035211002","fb9d780b"\n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"Restic has the ability to show output in json. Here is how I used it for some CSV type reporting<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[106,99],"tags":[],"class_list":["post-1365","post","type-post","status-publish","format-standard","hentry","category-json","category-restic"],"_links":{"self":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts\/1365","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=1365"}],"version-history":[{"count":0,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts\/1365\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/media?parent=1365"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/categories?post=1365"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/tags?post=1365"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}