datadouble-btrfs 0.0.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- datadouble_btrfs/__init__.py +121 -0
- datadouble_btrfs/py.typed +0 -0
- datadouble_btrfs-0.0.3.dist-info/METADATA +35 -0
- datadouble_btrfs-0.0.3.dist-info/RECORD +7 -0
- datadouble_btrfs-0.0.3.dist-info/WHEEL +4 -0
- datadouble_btrfs-0.0.3.dist-info/entry_points.txt +2 -0
- datadouble_btrfs-0.0.3.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# Copyright (c) 2026- Tight Line LLC
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
"""The btrfs replicate adapter for Datadouble.
|
|
5
|
+
|
|
6
|
+
Spec settings::
|
|
7
|
+
|
|
8
|
+
replicate:
|
|
9
|
+
using:
|
|
10
|
+
btrfs:
|
|
11
|
+
path: /srv/clones # on the same btrfs filesystem as staging
|
|
12
|
+
|
|
13
|
+
Each copy is its own subvolume, filled with reflinked copies of the staged
|
|
14
|
+
image's files: the copy shares every data block with staging until it is
|
|
15
|
+
written to, so it is made in moments and costs no space up front, and
|
|
16
|
+
consumers can snapshot or delete it like any subvolume. Uses the ``btrfs``
|
|
17
|
+
command; staging and ``path`` must be on one btrfs filesystem. A group's
|
|
18
|
+
files, when the spec has them, get their own subvolume, ``<copy id>-files``.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
from collections.abc import Mapping
|
|
22
|
+
from pathlib import Path
|
|
23
|
+
|
|
24
|
+
from pydantic import BaseModel, ConfigDict, JsonValue
|
|
25
|
+
|
|
26
|
+
from datadouble.files import Reflink, copy_tree
|
|
27
|
+
from datadouble.images import ImageSummary
|
|
28
|
+
from datadouble.programs import locate, run_program
|
|
29
|
+
from datadouble.replicate import (
|
|
30
|
+
ClaimState,
|
|
31
|
+
Copy,
|
|
32
|
+
CopyKind,
|
|
33
|
+
Made,
|
|
34
|
+
ReplicateError,
|
|
35
|
+
Replicator,
|
|
36
|
+
StagedImage,
|
|
37
|
+
copy_names,
|
|
38
|
+
files_id,
|
|
39
|
+
)
|
|
40
|
+
from datadouble.settings import parse_settings
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class BtrfsSettings(BaseModel):
|
|
44
|
+
"""Settings for the ``btrfs`` replicate adapter."""
|
|
45
|
+
|
|
46
|
+
model_config = ConfigDict(strict=True, frozen=True, extra="forbid")
|
|
47
|
+
|
|
48
|
+
path: Path
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def _run(arguments: list[str], action: str) -> None:
|
|
52
|
+
done = run_program(arguments[0], arguments[1:])
|
|
53
|
+
if done.status != 0:
|
|
54
|
+
message = f"{action} failed: {done.last_error()}"
|
|
55
|
+
raise ReplicateError(message)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def btrfs_binary() -> str:
|
|
59
|
+
"""``DATADOUBLE_BTRFS``, or ``btrfs`` on ``PATH``."""
|
|
60
|
+
found = locate("btrfs", "DATADOUBLE_BTRFS")
|
|
61
|
+
if not found:
|
|
62
|
+
message = "the btrfs command was not found; install btrfs-progs"
|
|
63
|
+
raise ReplicateError(message)
|
|
64
|
+
return found
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
class BtrfsReplicator:
|
|
68
|
+
"""Volume copies as subvolumes sharing blocks with staging."""
|
|
69
|
+
|
|
70
|
+
def __init__(self, settings: BtrfsSettings) -> None:
|
|
71
|
+
"""Make subvolumes under ``settings.path``."""
|
|
72
|
+
self.root = settings.path
|
|
73
|
+
|
|
74
|
+
@property
|
|
75
|
+
def kind(self) -> CopyKind:
|
|
76
|
+
"""Volumes."""
|
|
77
|
+
return CopyKind.VOLUME
|
|
78
|
+
|
|
79
|
+
def create(
|
|
80
|
+
self, copy_id: str, image: Path, summary: ImageSummary, files: StagedImage | None = None
|
|
81
|
+
) -> Made:
|
|
82
|
+
"""Create a subvolume, reflink the image into it, then rename it into place.
|
|
83
|
+
|
|
84
|
+
The group's files, if given, get a subvolume of their own, ``<copy id>-files``.
|
|
85
|
+
"""
|
|
86
|
+
self.root.mkdir(parents=True, exist_ok=True)
|
|
87
|
+
location: dict[str, JsonValue] = {"path": str(self._copy(copy_id, image, summary))}
|
|
88
|
+
if files is None:
|
|
89
|
+
return Made(location=location)
|
|
90
|
+
copied = self._copy(files_id(copy_id), files.path, files.summary)
|
|
91
|
+
return Made(location=location, files={"path": str(copied)})
|
|
92
|
+
|
|
93
|
+
def _copy(self, copy_id: str, image: Path, summary: ImageSummary) -> Path:
|
|
94
|
+
partial = self.root / f".{copy_id}.partial"
|
|
95
|
+
btrfs = btrfs_binary()
|
|
96
|
+
_run([btrfs, "subvolume", "create", str(partial)], "creating the subvolume")
|
|
97
|
+
problem = copy_tree(image, partial, Reflink.ALWAYS, contents=True)
|
|
98
|
+
if problem:
|
|
99
|
+
run_program(btrfs, ["subvolume", "delete", str(partial)])
|
|
100
|
+
message = f"copying {summary.identity.generation} failed: {problem}"
|
|
101
|
+
raise ReplicateError(message)
|
|
102
|
+
final = self.root / copy_id
|
|
103
|
+
partial.rename(final)
|
|
104
|
+
return final
|
|
105
|
+
|
|
106
|
+
def destroy(self, copy: Copy) -> None:
|
|
107
|
+
"""Delete the copy's subvolumes, complete or not."""
|
|
108
|
+
btrfs = btrfs_binary()
|
|
109
|
+
for name in copy_names(copy):
|
|
110
|
+
for path in (self.root / name, self.root / f".{name}.partial"):
|
|
111
|
+
if path.exists():
|
|
112
|
+
_run([btrfs, "subvolume", "delete", str(path)], f"deleting {path.name}")
|
|
113
|
+
|
|
114
|
+
def claim_state(self, _copy: Copy, /) -> ClaimState:
|
|
115
|
+
"""Claims are recorded by ``claim``."""
|
|
116
|
+
return ClaimState.UNKNOWN
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def btrfs_replicator(settings: Mapping[str, JsonValue]) -> Replicator:
|
|
120
|
+
"""The entry point named in ``datadouble.replicators``."""
|
|
121
|
+
return BtrfsReplicator(parse_settings(BtrfsSettings, settings, "btrfs replicate"))
|
|
File without changes
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: datadouble-btrfs
|
|
3
|
+
Version: 0.0.3
|
|
4
|
+
Summary: btrfs replicate adapter for Datadouble
|
|
5
|
+
Project-URL: Homepage, https://datadouble.tightlinesoftware.com/
|
|
6
|
+
Project-URL: Source, https://github.com/datadouble/datadouble
|
|
7
|
+
Author: Tight Line LLC
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Classifier: Development Status :: 2 - Pre-Alpha
|
|
11
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
15
|
+
Classifier: Topic :: System :: Filesystems
|
|
16
|
+
Classifier: Typing :: Typed
|
|
17
|
+
Requires-Python: >=3.13
|
|
18
|
+
Requires-Dist: datadouble
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
|
|
21
|
+
# datadouble-btrfs
|
|
22
|
+
|
|
23
|
+
The btrfs replicate adapter for [Datadouble](https://datadouble.tightlinesoftware.com/):
|
|
24
|
+
each copy is a writable snapshot of the staged image, made in moments however
|
|
25
|
+
large the image is.
|
|
26
|
+
|
|
27
|
+
```yaml
|
|
28
|
+
replicate:
|
|
29
|
+
using:
|
|
30
|
+
btrfs:
|
|
31
|
+
path: /srv/clones # a directory on the same btrfs filesystem as staging
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Staging must be on btrfs too. The first copy of a generation turns its staged
|
|
35
|
+
image into a subvolume; later copies snapshot it. Uses the `btrfs` command.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
datadouble_btrfs/__init__.py,sha256=AwagER30lBDYjWFqVj06KF0i2MDxv_l-YiZ6vz2PRRk,4237
|
|
2
|
+
datadouble_btrfs/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
+
datadouble_btrfs-0.0.3.dist-info/METADATA,sha256=EBqrs3UseaanwTieOIcPlHOhqL3-pnrq1USkKWq1xYo,1214
|
|
4
|
+
datadouble_btrfs-0.0.3.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
5
|
+
datadouble_btrfs-0.0.3.dist-info/entry_points.txt,sha256=cH2YJkGAi7NMU5Y5T6tZbfCMXCJ1GlNCqFp57D1XwYw,67
|
|
6
|
+
datadouble_btrfs-0.0.3.dist-info/licenses/LICENSE,sha256=2LcT-SSMiSa7vrHsdC41sUWNmkcwZqIYdYBaSVmqqT8,1072
|
|
7
|
+
datadouble_btrfs-0.0.3.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026- Tight Line LLC
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|