So I’d like to write a frontend and database/backend to manage restic repos and snapshots.
I have some nodejs code running fine. It uses a spawned process to call restic and passes back all the stdout responses.
That’s fine but if I want to do something with those (like the snapshot command) I’m going to have to parse it (not good).
I didn’t find anything like a --json flag that would return json instead of formatted text.
While it’s “ok” to send commands via a spawned process to a cli if restic was written in node I’d just use the repo directly (using hopefully a documented api).
Other than spawed cli calls and parsing the output (hopefuly json) is there a better option at this time for intgetraing Restic? What would be cool is a module that launches restic as a RPC/TCP/Named Socket server that allows calls directly to the restic commands (api) and returns json. Like this https://stackoverflow.com/a/60084086
I’ve actually developed a library that does this (socket RPC) using nodejs and it allows me to have parts of code of essentially the same application running on any machine or in multiple processes on one machine including a browser frontend.
Restic does indeed have a
--json flag. See
--json set output mode to JSON for commands that support it
I’ve got my own junky python which like cdhowie says uses “–json” and pipes the stdout. The output is json with a few header lines to ignore. For a single Windows machine with an external usb drive the parsing was not much of a problem other then understanding how python, restic, Windows use forward slashes and backslashes.
RTFM, ah, duh I should have looked at help for snaphot.
So when I run via my child process wrapper and use JSON.parse(buffer) with the stdout buffer it goes right to clean array of json (js objects) nice!
Now would be nice to be able to send command as json instead of a string. :).
I’ll just have to write a function to do that.
So I guess I can at this point write an RPC wrapper on restic, but still would be way cooler if restic itself supported RPC (which would be faster and more robust).
Came across this new google communication buffer protocol which would make it JSON independent. Language Guide | Protocol Buffers | Google Developers
I’m thinking with that I could have a single install of restic on a “backup manager” and backup from any machine to any machine via ssh or maybe even QUIC which would be even cooler
Protobuf is actually not terribly new. It was first released in 2008.
It’s not necessarily a bad suggestion, but protobuf is generally used in situations where compact message representation is highly desired. Restic does not exist in that kind of a situation; JSON is more than sufficient and is both much more widely-supported and easier to use than protobuf – the client does not need any message schema files to use JSON, but they are required with protobuf. Many programming environments have JSON support built-in, but I’m not aware of one that has built-in protobuf support.
Yeah, JSON has by and large displaced XML. It’s a much simpler grammar than XML, and all of the complexity of XML doesn’t really even accomplish XML’s additional goals beyond what JSON provides.