| 1 |
REST Server |
| 2 |
=========== |
| 3 |
|
| 4 |
BorgStore includes a simple REST server that can be used to provide remote access |
| 5 |
to any BorgStore backend. |
| 6 |
|
| 7 |
It can do some stuff server-side, which is usually not possible when using other |
| 8 |
cloud storage servers: |
| 9 |
|
| 10 |
- enforcing permissions |
| 11 |
- server rejects store operation if content hashsum does not match expected |
| 12 |
hashsum (from http header X-Content-hash-sha256) |
| 13 |
- server-side hash computation (e.g. sha256, or blake3 if the optional ``blake3`` |
| 14 |
package is installed on the server) for item content |
| 15 |
- server-side gather (reads multiple byte ranges from multiple items with one request) |
| 16 |
- server-side defragmentation helper (copies blocks to new items) |
| 17 |
|
| 18 |
Running the server on host:port |
| 19 |
------------------------------- |
| 20 |
|
| 21 |
Run a server with a file: backend (for a local directory), using HTTP Basic Authentication:: |
| 22 |
|
| 23 |
borgstore-server-rest --host 127.0.0.1 --port 5618 \ |
| 24 |
--username user --password pass \ |
| 25 |
--backend file:///tmp/teststore |
| 26 |
|
| 27 |
For production deployments, consider using systemd socket activation |
| 28 |
(see contrib/server/nginx-systemd/README.md). |
| 29 |
|
| 30 |
Running the server via stdio |
| 31 |
---------------------------- |
| 32 |
|
| 33 |
Run a server with a file: backend (for a local directory), talking http via |
| 34 |
stdin/stdout, logging via stderr: |
| 35 |
|
| 36 |
borgstore-server-rest --stdio \ |
| 37 |
--backend file:///tmp/teststore |
| 38 |
|
| 39 |
Accessing the server from a client |
| 40 |
---------------------------------- |
| 41 |
|
| 42 |
The borgstore REST client can then access via:: |
| 43 |
|
| 44 |
http://user:[email protected]:5618/ |
| 45 |
|
| 46 |
or (when using http over stdio): |
| 47 |
|
| 48 |
rest://user@host:port//tmp/teststore # via ssh, abs. path |
| 49 |
rest://user@host:port/teststore # via ssh, rel. path |
| 50 |
rest:////tmp/teststore # locally, without ssh, abs. path |
| 51 |
rest:///teststore # locally, without ssh, rel. path |
| 52 |
|
| 53 |
Permissions |
| 54 |
----------- |
| 55 |
|
| 56 |
The REST server, when used with the ``posixfs`` backend, supports the same permissions |
| 57 |
system as that backend (see above). |
| 58 |
|
| 59 |
If ``--permissions`` is omitted, all operations are allowed. |
| 60 |
To restrict permissions, pass a JSON-encoded permissions mapping via ``--permissions``. |
| 61 |
|
| 62 |
Examples: |
| 63 |
|
| 64 |
Read-only access:: |
| 65 |
|
| 66 |
borgstore-server-rest --host 127.0.0.1 --port 5618 \ |
| 67 |
--username user --password pass \ |
| 68 |
--backend file:///tmp/teststore \ |
| 69 |
--permissions '{"": "lr"}' |
| 70 |
|
| 71 |
No-delete, no-overwrite (allow adding new items):: |
| 72 |
|
| 73 |
borgstore-server-rest --host 127.0.0.1 --port 5618 \ |
| 74 |
--username user --password pass \ |
| 75 |
--backend file:///tmp/teststore \ |
| 76 |
--permissions '{"": "lrw"}' |
| 77 |
|
| 78 |
Full access:: |
| 79 |
|
| 80 |
borgstore-server-rest --host 127.0.0.1 --port 5618 \ |
| 81 |
--username user --password pass \ |
| 82 |
--backend file:///tmp/teststore \ |
| 83 |
--permissions '{"": "lrwWD"}' |
| 84 |
|
| 85 |
BorgBackup shortcuts |
| 86 |
~~~~~~~~~~~~~~~~~~~~ |
| 87 |
|
| 88 |
Instead of hand-crafting a JSON mapping, you can use a named shortcut tailored for |
| 89 |
`BorgBackup <https://www.borgbackup.org/>`_ repositories: |
| 90 |
|
| 91 |
``borgbackup-all`` |
| 92 |
No permission restrictions — all operations are allowed (equivalent to omitting ``--permissions``). |
| 93 |
|
| 94 |
``borgbackup-no-delete`` |
| 95 |
Prevent deletion and overwriting of existing objects; new objects may still be added. |
| 96 |
|
| 97 |
``borgbackup-write-only`` |
| 98 |
Clients may store new data but cannot read existing data back (except for caches and metadata |
| 99 |
that borg needs internally). |
| 100 |
|
| 101 |
``borgbackup-read-only`` |
| 102 |
Clients may only list and read objects. |
| 103 |
|
| 104 |
Example — restrict a backup server to no-delete access: |
| 105 |
|
| 106 |
.. code-block:: bash |
| 107 |
|
| 108 |
borgstore-server-rest --host 127.0.0.1 --port 5618 \ |
| 109 |
--username user --password pass \ |
| 110 |
--backend file:///home/user/repos/repo1 \ |
| 111 |
--permissions borgbackup-no-delete |
| 112 |
|
| 113 |
Custom JSON permissions |
| 114 |
~~~~~~~~~~~~~~~~~~~~~~~ |
| 115 |
|
| 116 |
You can also pass an arbitrary JSON-encoded permissions mapping directly. |
| 117 |
|
| 118 |
Hierarchical rules (list-only at root, read/write in ``data/``):: |
| 119 |
|
| 120 |
borgstore-server-rest --host 127.0.0.1 --port 5618 \ |
| 121 |
--username user --password pass \ |
| 122 |
--backend file:///tmp/teststore \ |
| 123 |
--permissions '{"": "l", "data": "lrw"}' |
| 124 |
|
| 125 |
Quota |
| 126 |
----- |
| 127 |
|
| 128 |
The REST server, when used with the ``file:`` backend, optionally supports |
| 129 |
quota tracking and enforcement. |
| 130 |
|
| 131 |
Use the ``--quota`` argument to set a maximum storage size in bytes (default is |
| 132 |
no quota tracking and enforcement). |
| 133 |
|
| 134 |
When the quota is exceeded, ``store`` operations are rejected with HTTP 507 |
| 135 |
(Insufficient Storage). |
| 136 |
|
| 137 |
Example — limit storage to 1 GiB: |
| 138 |
|
| 139 |
.. code-block:: bash |
| 140 |
|
| 141 |
borgstore-server-rest --host 127.0.0.1 --port 5618 \ |
| 142 |
--username user --password pass \ |
| 143 |
--backend file:///tmp/teststore \ |
| 144 |
--quota 1073741824 |
| 145 |
|