| 1 |
Backends |
| 2 |
======== |
| 3 |
|
| 4 |
The backend API is rather simple; one only needs to provide some very |
| 5 |
basic operations. |
| 6 |
|
| 7 |
``store(name, value)`` accepts a ``bytes`` or a ``memoryview`` value, see |
| 8 |
:ref:`store-values`. Backends that can not give a ``memoryview`` to the library |
| 9 |
they use internally create a ``bytes`` object (one copy) - this is noted below. |
| 10 |
|
| 11 |
Existing backends are listed below; more might come in the future. |
| 12 |
|
| 13 |
See also :doc:`store_caching` for optional Store-level caching with a secondary backend. |
| 14 |
|
| 15 |
posixfs |
| 16 |
------- |
| 17 |
|
| 18 |
Use storage on a local POSIX filesystem: |
| 19 |
|
| 20 |
- URL: ``file:///absolute/path`` |
| 21 |
- It is the caller's responsibility to convert a relative path into an absolute |
| 22 |
filesystem path. |
| 23 |
- Namespaces: directories |
| 24 |
- Values: in key-named files |
| 25 |
- atime: supported (require fs atime support) |
| 26 |
- mtime: supported (stamped by the filesystem's clock - for a network filesystem |
| 27 |
that is usually the file server's clock) |
| 28 |
- Quota: tracks backend storage size and rejects ``store`` if quota is exceeded. |
| 29 |
|
| 30 |
The current usage is persisted to a hidden file in the storage directory. |
| 31 |
|
| 32 |
When quota tracking is enabled on a backend that already contains data, |
| 33 |
the server automatically scans the directories at ``open`` time (that may |
| 34 |
take a while if there are many files). That scan can be avoided by always |
| 35 |
using quotas. |
| 36 |
- Permissions: This backend can enforce a simple, test-friendly permission system |
| 37 |
and raises ``PermissionDenied`` if access is not permitted by the configuration. |
| 38 |
|
| 39 |
You provide a mapping of names (paths) to granted permission letters. Permissions |
| 40 |
apply to the exact name and all of its descendants (inheritance). If a name is not |
| 41 |
present in the mapping, its nearest ancestor is consulted, up to the empty name |
| 42 |
"" (the store root). If no mapping is provided at all, all operations are allowed. |
| 43 |
|
| 44 |
Permission letters: |
| 45 |
|
| 46 |
- ``l``: allow listing object names (directory/namespace listing) |
| 47 |
- ``r``: allow reading objects (contents) |
| 48 |
- ``w``: allow writing new objects (must not already exist) |
| 49 |
- ``W``: allow writing objects including overwriting existing objects |
| 50 |
- ``D``: allow deleting objects |
| 51 |
|
| 52 |
Operation requirements: |
| 53 |
|
| 54 |
- create(): requires ``w`` or ``W`` on the store root (``wW``) |
| 55 |
- destroy(): requires ``D`` on the store root |
| 56 |
- mkdir(name): requires ``w`` |
| 57 |
- rmdir(name): requires ``w`` or ``D`` (``wD``) |
| 58 |
- list(name): requires ``l`` |
| 59 |
- info(name): requires ``l`` (``r`` also accepted) |
| 60 |
- load(name): requires ``r`` |
| 61 |
- store(name, value): requires ``w`` for new objects, ``W`` for overwrites (``wW``) |
| 62 |
- delete(name): requires ``D`` |
| 63 |
- move(src, dst): requires ``D`` for the source and ``w``/``W`` for the destination |
| 64 |
|
| 65 |
Examples: |
| 66 |
|
| 67 |
- Read-only store (recursively): ``permissions = {"": "lr"}`` |
| 68 |
- No-delete, no-overwrite (but allow adding new items): ``permissions = {"": "lrw"}`` |
| 69 |
- Hierarchical rules: only allow listing at root, allow read/write in "dir", |
| 70 |
but only read for "dir/file": |
| 71 |
|
| 72 |
:: |
| 73 |
|
| 74 |
permissions = { |
| 75 |
"": "l", |
| 76 |
"dir": "lrw", |
| 77 |
"dir/file": "r", |
| 78 |
} |
| 79 |
|
| 80 |
To use permissions with ``Store`` and ``posixfs``, pass the mapping to Store and it |
| 81 |
will be handed to the posixfs backend: |
| 82 |
|
| 83 |
:: |
| 84 |
|
| 85 |
from borgstore import Store |
| 86 |
store = Store(url="file:///abs/path", permissions={"": "lrwWD"}) |
| 87 |
store.create() |
| 88 |
store.open() |
| 89 |
# ... |
| 90 |
store.close() |
| 91 |
|
| 92 |
Note: |
| 93 |
|
| 94 |
When using posixfs as a caching backend, it needs to use a filesystem with |
| 95 |
``atime`` support for ``max_age`` and LRU-based ``size`` limits to work as |
| 96 |
expected. |
| 97 |
|
| 98 |
For Linux that means you must not use ``noatime`` mount option. |
| 99 |
|
| 100 |
For Windows / NTFS, atime is disabled by default and you need: |
| 101 |
|
| 102 |
:: |
| 103 |
|
| 104 |
fsutil behavior set DisableLastAccess 0 # re-enable (requires admin, reboot) |
| 105 |
|
| 106 |
sftp |
| 107 |
---- |
| 108 |
|
| 109 |
Use storage on an SFTP server: |
| 110 |
|
| 111 |
- URL: ``sftp://user@server:port/relative/path`` (strongly recommended) |
| 112 |
|
| 113 |
For users' and admins' convenience, the mapping of the URL path to the server filesystem path |
| 114 |
depends on the server configuration (home directory, sshd/sftpd config, ...). |
| 115 |
Usually the path is relative to the user's home directory. |
| 116 |
- URL: ``sftp://user@server:port//absolute/path`` |
| 117 |
|
| 118 |
As this uses an absolute path, some things become more difficult: |
| 119 |
|
| 120 |
- A user's configuration might break if a server admin moves a user's home to a new location. |
| 121 |
- Users must know the full absolute path of the space they are permitted to use. |
| 122 |
- Namespaces: directories |
| 123 |
- Values: in key-named files |
| 124 |
- store: a ``memoryview`` value is copied into a ``bytes`` object first, because |
| 125 |
paramiko does not accept a ``memoryview``. |
| 126 |
- atime / mtime: supported (stamped by the SFTP server's filesystem) |
| 127 |
- hash: runs the hexdigest computation server-side (if server supports check-file). |
| 128 |
"blake3" is not part of the check-file extension, so it is always computed client-side. |
| 129 |
|
| 130 |
rclone |
| 131 |
------ |
| 132 |
|
| 133 |
Use storage on any of the many cloud providers `rclone <https://rclone.org/>`_ supports: |
| 134 |
|
| 135 |
- URL: ``rclone:remote:path`` — we just prefix "rclone:" and pass everything to the right |
| 136 |
of that to rclone; see: https://rclone.org/docs/#syntax-of-remote-paths |
| 137 |
- The implementation primarily depends on the specific remote. |
| 138 |
- The rclone binary path can be set via the environment variable ``RCLONE_BINARY`` (default: "rclone"). |
| 139 |
- Debugging of HTTP requests/responses can be enabled by setting ``BORGSTORE_RCLONE_DEBUG=1``. |
| 140 |
- atime / mtime: not supported (always 0). rclone's ModTime is the client-side mtime |
| 141 |
preserved across upload, not a timestamp stamped by the storage side. |
| 142 |
|
| 143 |
|
| 144 |
s3 |
| 145 |
-- |
| 146 |
|
| 147 |
Use storage on an S3-compliant cloud service: |
| 148 |
|
| 149 |
- URL: ``(s3|b2):[profile|(access_key_id:access_key_secret)@][scheme://hostname[:port]]/bucket/path`` |
| 150 |
|
| 151 |
The underlying backend is based on ``boto3``, so all standard boto3 authentication methods are supported: |
| 152 |
|
| 153 |
- provide a named profile (from your boto3 config), |
| 154 |
- include access key ID and secret in the URL, |
| 155 |
- or use default credentials (e.g., environment variables, IAM roles, etc.). |
| 156 |
|
| 157 |
See the `boto3 credentials documentation <https://boto3.amazonaws.com/v1/documentation/api/latest/guide/credentials.html>`_ for more details. |
| 158 |
|
| 159 |
If you're connecting to **AWS S3**, the ``[schema://hostname[:port]]`` part is optional. |
| 160 |
Bucket and path are always required. |
| 161 |
|
| 162 |
.. note:: |
| 163 |
|
| 164 |
There is a known issue with some S3-compatible services (e.g., **Backblaze B2**). |
| 165 |
If you encounter problems, try using ``b2:`` instead of ``s3:`` in the URL. |
| 166 |
|
| 167 |
- Namespaces: directories |
| 168 |
- Values: in key-named files |
| 169 |
- store: a ``memoryview`` value is copied into a ``bytes`` object first, because |
| 170 |
boto3 does not accept a ``memoryview``. |
| 171 |
- atime: not supported (always 0). |
| 172 |
- mtime: supported (``LastModified``, stamped by the S3 service). |
| 173 |
|
| 174 |
|
| 175 |
REST (http/https) |
| 176 |
----------------- |
| 177 |
|
| 178 |
Use a storage backend running inside a BorgStore REST server process: |
| 179 |
|
| 180 |
- URL: ``http[s]://[user:password@]host:port/path`` (REST via TCP) |
| 181 |
- URL: ``rest://[user@]host[:port]/path`` (REST via stdio via ssh) |
| 182 |
- URL: ``rest:///path`` (REST via local stdio, e.g. for testing) |
| 183 |
|
| 184 |
- Namespaces: depends on backend used by the server |
| 185 |
- Values: depends on backend used by the server |
| 186 |
- Authentication: Optional Basic Auth is supported. |
| 187 |
- hash: runs the hexdigest computation server-side. Using algorithm "blake3" requires |
| 188 |
the optional ``blake3`` package to be installed **on the server**. |
| 189 |
- gather: runs server-side, all ranges are read with one roundtrip. |
| 190 |
- defrag: runs the defragmentation helper server-side. |
| 191 |
- atime / mtime: supported (if backend used by server supports it). mtime is stamped |
| 192 |
by the server side (the store operation executes there). |