restic icon indicating copy to clipboard operation
restic copied to clipboard

HTTP api for repository

Open tamalsaha opened this issue 8 years ago • 9 comments

We would like to build a web dashboard using repository data. The kind of things we would like to see:

  • [ ] Handle multiple repositories
  • [ ] List snapshots
  • [ ] Start new backup.
  • [ ] Forget old snapsots.
  • [ ] Find a file

tamalsaha avatar Mar 02 '17 01:03 tamalsaha

Hey, thanks for opening this issue. That's quite a list you got there. What's the use case? And how do you imagine integrating this with restic?

fd0 avatar Mar 02 '17 13:03 fd0

@fd0, we would like to use this api as part of UI for our Kubernetes integration work. Essentially, we want to show to the users how the backup process is going on via a web dashboard.

tamalsaha avatar Mar 02 '17 13:03 tamalsaha

To be honest with you, I'm not sure the project is ready for this. We're still young, and our goal is to build a highly reliable command-line application for creating secure backups. There are still so many moving parts, changing internals etc.

At the moment we have two API "contracts" with our users: The repository format and the CLI binary calling convention. I'm not sure we're ready for a third one (an HTTP API) integrated into restic yet.

There's an ongoing effort to add JSON output to commands, e.g. for the snapshots command this was merged in #803. Is this maybe something that you can use? Have a small program that receives HTTP API requests, then calls restic and sends its output back to the caller? This way you can define the API that you need yourself, and work with us to get the output in JSON you need.

For long-running operations like backup, I can imagine having "partial" (streaming) JSON output, so that you can display progress while the backup is still running.

fd0 avatar Mar 02 '17 14:03 fd0

How stable do you think the JSON response formats are? We want to consume that in our Kubernetes integration from command line. Regarding HTTP api, it can be essentially exposing these JSON objects over HTTP.

Partial JSON outputs sound good in theory. But I have found it less usable when called from a web page via AJAX.

I am not sure how often things change. But we are open to dealing with unstable interface. Especially, we would prefer to use restic as a lib (instead of consuming json) if things are unstable. Because GO compiler can help us find issues in those cases. It is hard to detect when a JSON format silently changes. @sadlil was looking into vendoring restic earlier and you guys had a discussion around the package path.

tamalsaha avatar Mar 02 '17 14:03 tamalsaha

I can understand that, thanks for elaborating. I have plans to add integration tests for the JSON output, so the tests assure that the format only changes in backwards-compatible ways, once introduced.

Please be aware that (as already detailed in #833) restic is not meant to be a library, although the source code repo is structured in such a way. It is not made for being consumed by another application (at least not yet).

So as far as I understood your request you'd like to have some sort of "server mode" where restic listens on an HTTP API for commands. Is that correct?

In this case, is there just one repository for a given instance of restic (so you can supply the authentication password etc via the normal CLI interface)?

fd0 avatar Mar 02 '17 14:03 fd0

What do you think about creating a lib of GO structs that restic uses to create the JSON outputs. We & any external projects can consume that. You can also write tests to ensure compatibility. Ideally we don't want to use restic as a lib. But if things are too unstable, lib + vendoring might end up a more suitable option.

So as far as I understood your request you'd like to have some sort of "server mode" where restic listens on an HTTP API for commands. Is that correct?

Yes.

In this case, is there just one repository for a given instance of restic (so you can supply the authentication password etc via the normal CLI interface)?

We would like one HTTP server to handle many restic repositories. We can send the repo url and password in HTTP header to server. Then server can invoke restic cli.

tamalsaha avatar Mar 02 '17 14:03 tamalsaha

@fd0 , here are some data we will be interested in for a backup operation:

  • General info about the backup run. I think this is already done.
  • Identify if the backup failed.
  • Stats related to how long it took, how much new data was exported. We would like to record that for monitoring purposes.

tamalsaha avatar Mar 02 '17 15:03 tamalsaha

@tamalsaha restic has JSON output for the backup, snapshots, forget and find commands. These should be sufficient to cover all listed use cases.

MichaelEischer avatar Oct 04 '20 16:10 MichaelEischer

Related to #60

MichaelEischer avatar Aug 20 '22 14:08 MichaelEischer