Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open API for use with third party applications (Home Assistant, Node-RED, etc) #587

Open
skylord123 opened this issue Nov 27, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@skylord123
Copy link

Is your feature request related to a problem? Please describe.
I want to use Node-RED to communicate with backrest via some sort of API.

Currently I have webhooks that fire off to Node-RED and I use that to send messages to my matrix room with updates about the backups. I want to be able to track the progress of the backup by making calls to some sort of endpoint to get information (similar to how the WebUI works currently).

This would also be really handy because we can build an integration for Home Assistant which would allow people to monitor/trigger their backups from their existing home automation platform.

Describe the solution you'd like
Create an open API and document it so people can build cool stuff off it.

@skylord123 skylord123 added the enhancement New feature or request label Nov 27, 2024
@balgerion
Copy link

balgerion commented Jan 2, 2025

Look at this:
https://github.com/colby-int/restic-json

@skylord123
Copy link
Author

skylord123 commented Jan 2, 2025

Look at this: https://github.com/colby-int/restic-json

I know this exists. I want something that can query backrest since it already has all of this data available. Ideally the same info I can see via the web UI on backrest should also be available via API.

I did get the webhooks setup and working nicely but that is still just data being pushed out of backrest whereas I need to be able to query backrest for data directly.

For example: I would like to be able to query for info about a currently running backup to get the complete percentage and other info.

Another example: I want to setup a script to query the API and check previous backups to make sure all backups ran and completed successfully. Sort of like another tool that audits my backups to make sure things are running as it should. I currently have it message me every time a backup finishes but this is error prone since I have to manually verify them. The idea is to make this process automatic and an API would be perfect for this.

@garethgeorge
Copy link
Owner

garethgeorge commented Jan 2, 2025

It's great to see the interest in scripting / additional automation around backrest, this is certainly something I'd like to support. Putting out more formal docs covering Backrest's architecture and API are on my road map -- hopefully some of which can be code-generated. Today however you'll need to read the proto definitions to understand the API.

Today the API is defined formally as a gRPC service https://github.com/garethgeorge/backrest/blob/main/proto/v1/service.proto#L14-L63 which backrest makes accessible over an HTTP gateway which accepts binary requests OR protojson formatted requests. E.g.

curl -X POST 'localhost:9898/v1.Backrest/Backup' --data '{"value": "YOUR_PLAN_ID"}' -H 'Content-Type: application/json'

is a valid request to the Backup endpoint on the service to start a Backup.

Beyond this, for query support I suspect something like

curl -X POST 'localhost:9898/v1.Backrest/GetOperations' --data '{}' -H 'Content-Type: application/json'

should return the full operation history for your install, which may be quite a bit of JSON data. You can provide optional parameters i.e.

curl -X POST 'localhost:9898/v1.Backrest/GetOperations' --data '{"lastN": 1000, "selector": {"repoId": "myrepo"}}' -H 'Content-Type: application/json'

should return the last few thousand operations from the targeted repo myrepo. At the moment I expect that these APIs should be reasonably stable though it's possible that the the structures of the actual operations returned may change over time.

@skylord123
Copy link
Author

skylord123 commented Jan 2, 2025

@garethgeorge thank you! This is exactly what I needed.

Here is a flow for an example of how to do this in Node-RED (import using the hamburger menu in NR):

[{"id":"f8d0ed6480b4a91b","type":"inject","z":"2abaa0e7be1a6d3b","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"lastN\": 1000, \"selector\": {\"repoId\": \"repo-id\"}}","payloadType":"jsonata","x":250,"y":460,"wires":[["4f3d186ba804c950"]]},{"id":"4f3d186ba804c950","type":"http request","z":"2abaa0e7be1a6d3b","name":"","method":"POST","ret":"obj","paytoqs":"ignore","url":"http://localhost:9898/v1.Backrest/GetOperations","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[{"keyType":"other","keyValue":"Content-Type","valueType":"other","valueValue":"application/json"}],"x":430,"y":460,"wires":[["900415374eb3824d"]]},{"id":"900415374eb3824d","type":"debug","z":"2abaa0e7be1a6d3b","name":"debug backrest api response","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":660,"y":460,"wires":[]}]

Now I am looking into creating a module for Node-RED to make integrating with backrest much easier for people in the future. Should make scripting a bit easier.

Keeping an eye out for the docs update :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants