toolframe-backup 0.1.0__tar.gz

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.
Files changed (35) hide show
  1. toolframe_backup-0.1.0/.github/workflows/ci.yml +39 -0
  2. toolframe_backup-0.1.0/.github/workflows/publish.yml +65 -0
  3. toolframe_backup-0.1.0/.gitignore +15 -0
  4. toolframe_backup-0.1.0/LICENSE +202 -0
  5. toolframe_backup-0.1.0/NOTICE +4 -0
  6. toolframe_backup-0.1.0/PKG-INFO +148 -0
  7. toolframe_backup-0.1.0/README.md +126 -0
  8. toolframe_backup-0.1.0/docs/adr/0001-stopped-recovery-and-directory-catalog.md +34 -0
  9. toolframe_backup-0.1.0/docs/architecture.md +60 -0
  10. toolframe_backup-0.1.0/docs/releasing.md +68 -0
  11. toolframe_backup-0.1.0/pyproject.toml +47 -0
  12. toolframe_backup-0.1.0/scripts/validate_release.py +181 -0
  13. toolframe_backup-0.1.0/src/toolframe_backup/__init__.py +3 -0
  14. toolframe_backup-0.1.0/src/toolframe_backup/archive.py +907 -0
  15. toolframe_backup-0.1.0/src/toolframe_backup/catalog.py +511 -0
  16. toolframe_backup-0.1.0/src/toolframe_backup/cli.py +82 -0
  17. toolframe_backup-0.1.0/src/toolframe_backup/docs/usage.md +88 -0
  18. toolframe_backup-0.1.0/src/toolframe_backup/environments.py +493 -0
  19. toolframe_backup-0.1.0/src/toolframe_backup/page.py +150 -0
  20. toolframe_backup-0.1.0/src/toolframe_backup/plugin.py +220 -0
  21. toolframe_backup-0.1.0/src/toolframe_backup/service.py +105 -0
  22. toolframe_backup-0.1.0/src/toolframe_backup/zipguard.py +178 -0
  23. toolframe_backup-0.1.0/tests/conftest.py +126 -0
  24. toolframe_backup-0.1.0/tests/test_archive.py +144 -0
  25. toolframe_backup-0.1.0/tests/test_archive_security.py +486 -0
  26. toolframe_backup-0.1.0/tests/test_catalog.py +363 -0
  27. toolframe_backup-0.1.0/tests/test_cli.py +184 -0
  28. toolframe_backup-0.1.0/tests/test_direct_wheel_locks.py +232 -0
  29. toolframe_backup-0.1.0/tests/test_environment_precision.py +269 -0
  30. toolframe_backup-0.1.0/tests/test_environment_review.py +221 -0
  31. toolframe_backup-0.1.0/tests/test_environment_uri_paths.py +183 -0
  32. toolframe_backup-0.1.0/tests/test_environments.py +456 -0
  33. toolframe_backup-0.1.0/tests/test_page.py +215 -0
  34. toolframe_backup-0.1.0/tests/test_plugin.py +200 -0
  35. toolframe_backup-0.1.0/tests/test_zipguard.py +329 -0
@@ -0,0 +1,39 @@
1
+ name: Validate Python distribution
2
+
3
+ on:
4
+ push:
5
+ pull_request:
6
+ workflow_dispatch:
7
+ workflow_call:
8
+
9
+ permissions:
10
+ contents: read
11
+
12
+ jobs:
13
+ validate:
14
+ runs-on: ${{ matrix.os }}
15
+ timeout-minutes: 25
16
+ strategy:
17
+ fail-fast: false
18
+ matrix:
19
+ os: [ubuntu-24.04, macos-15]
20
+ steps:
21
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
22
+ with:
23
+ persist-credentials: false
24
+ - uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
25
+ with:
26
+ python-version: '3.14.7'
27
+ - uses: astral-sh/setup-uv@c18668ad3cf93ea998bef934396af7bb5c839dc7 # v10.2.0
28
+ with:
29
+ version: '0.12.8'
30
+ enable-cache: false
31
+ - name: Test and install wheel and source distribution
32
+ run: python scripts/validate_release.py --output dist/validated
33
+ - name: Retain only validated distributions
34
+ uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
35
+ with:
36
+ name: python-dist-${{ matrix.os }}
37
+ path: dist/validated/*
38
+ if-no-files-found: error
39
+ retention-days: 14
@@ -0,0 +1,65 @@
1
+ name: Publish Python distribution
2
+
3
+ on:
4
+ workflow_dispatch:
5
+ inputs:
6
+ index:
7
+ description: Package index; run against the matching vVERSION tag
8
+ type: choice
9
+ options: [testpypi, pypi]
10
+ default: testpypi
11
+ required: true
12
+
13
+ permissions:
14
+ contents: read
15
+
16
+ concurrency:
17
+ group: publish-${{ inputs.index }}
18
+ cancel-in-progress: false
19
+
20
+ jobs:
21
+ release-tag:
22
+ runs-on: ubuntu-24.04
23
+ timeout-minutes: 5
24
+ steps:
25
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
26
+ with:
27
+ persist-credentials: false
28
+ - uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
29
+ with:
30
+ python-version: '3.14.7'
31
+ - name: Require the exact package version tag
32
+ env:
33
+ RELEASE_REF: ${{ github.ref }}
34
+ run: |
35
+ python - <<'PYCODE'
36
+ import os, pathlib, tomllib
37
+ project = tomllib.loads(pathlib.Path('pyproject.toml').read_text())['project']
38
+ expected = 'refs/tags/v' + project['version']
39
+ if os.environ['RELEASE_REF'] != expected:
40
+ raise SystemExit('Publication requires ' + expected)
41
+ PYCODE
42
+
43
+ validate:
44
+ needs: release-tag
45
+ uses: ./.github/workflows/ci.yml
46
+ secrets: inherit
47
+
48
+ publish:
49
+ needs: [release-tag, validate]
50
+ runs-on: ubuntu-24.04
51
+ timeout-minutes: 10
52
+ environment:
53
+ name: ${{ inputs.index }}
54
+ permissions:
55
+ contents: read
56
+ id-token: write
57
+ steps:
58
+ - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
59
+ with:
60
+ name: python-dist-ubuntu-24.04
61
+ path: dist/
62
+ - uses: pypa/gh-action-pypi-publish@dc37677b2e1c63e2034f94d8a5b11f265b73ba33 # v1.14.2
63
+ with:
64
+ packages-dir: dist/
65
+ repository-url: ${{ inputs.index == 'testpypi' && 'https://test.pypi.org/legacy/' || 'https://upload.pypi.org/legacy/' }}
@@ -0,0 +1,15 @@
1
+ /.venv/
2
+ /build/
3
+ /dist/
4
+ /.pytest_cache/
5
+ /.ruff_cache/
6
+ /uv.lock
7
+ __pycache__/
8
+ *.py[cod]
9
+ *.egg-info/
10
+ .DS_Store
11
+
12
+ # Local working documents, issue state, and development worktrees.
13
+ /.local/
14
+ /.issues/
15
+ /.worktrees/
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,4 @@
1
+ Toolframe Backup
2
+ Copyright 2026 Toolframe contributors
3
+
4
+ Licensed under the Apache License, Version 2.0.
@@ -0,0 +1,148 @@
1
+ Metadata-Version: 2.5
2
+ Name: toolframe-backup
3
+ Version: 0.1.0
4
+ Summary: Stopped-application recovery archives and a local Backup catalog for Toolframe
5
+ Project-URL: Homepage, https://github.com/toolframe/toolframe-backup
6
+ Project-URL: Repository, https://github.com/toolframe/toolframe-backup
7
+ Project-URL: Documentation, https://github.com/toolframe/toolframe-backup#readme
8
+ Project-URL: Issues, https://github.com/toolframe/toolframe-backup/issues
9
+ Author-email: byfb <62798989+byfb@users.noreply.github.com>
10
+ License-Expression: Apache-2.0
11
+ License-File: LICENSE
12
+ License-File: NOTICE
13
+ Requires-Python: >=3.14
14
+ Requires-Dist: packaging>=25
15
+ Requires-Dist: tomlkit<1,>=0.13
16
+ Requires-Dist: toolframe-sdk==0.3.0
17
+ Provides-Extra: operator
18
+ Requires-Dist: toolframe-core<0.7,>=0.6; extra == 'operator'
19
+ Provides-Extra: ui
20
+ Requires-Dist: streamlit==1.61.0; extra == 'ui'
21
+ Description-Content-Type: text/markdown
22
+
23
+ # Toolframe Backup
24
+
25
+ Toolframe Backup creates recovery archives of cleanly stopped Toolframe applications
26
+ and provides a Dashboard and read-only MCP catalog for a configured local backup
27
+ directory. Its standalone CLI can verify or restore archives even when the source
28
+ application cannot start. The ordinary plugin never snapshots a running application.
29
+
30
+ ## Quick start
31
+
32
+ Use Python 3.14 or newer. Archive creation
33
+ requires a Core release providing `toolframe_core.maintenance.stopped_application`.
34
+ Restoring recorded environments also requires its public `application_lock` helper.
35
+ Install the operator extra from PyPI:
36
+
37
+ ```sh
38
+ uv venv --python 3.14
39
+ uv pip install 'toolframe-backup[operator]==0.1.0'
40
+ # Stop the application's host and workers cleanly before creating the archive.
41
+ .venv/bin/toolframe-backup create --home ./app --directory ./backups
42
+ .venv/bin/toolframe-backup list --directory ./backups
43
+ .venv/bin/toolframe-backup verify ./backups/backup-<id>.zip
44
+ .venv/bin/toolframe-backup restore ./backups/backup-<id>.zip --destination ./recovered-app
45
+ # Optional local-only reconstruction (requires every exact-hash dependency locally):
46
+ .venv/bin/toolframe-backup restore ./backups/backup-<id>.zip --destination ./offline-recovered-app --offline --wheelhouse ./wheelhouse
47
+ ```
48
+
49
+ The CLI prints nonsecret JSON summaries; errors use exit code 2 and interruption
50
+ uses 130. New backup directories and restored directories have mode 0700. Archive
51
+ files and restored payload files have mode 0600; uv sets reconstructed environment
52
+ file modes. Existing backup directories must already have
53
+ mode 0700. Restore requires a new destination with an existing parent directory;
54
+ it never replaces an existing home, including an empty directory.
55
+ Supported restore paths include spaces and Unicode. Paths containing quotes,
56
+ backslashes or control characters are rejected before staging.
57
+ File URI wheel locators encode spaces, Unicode and URI delimiters such as `#`, `?`
58
+ and `%`; direct wheel paths retain their filesystem spelling.
59
+
60
+ To install the catalog in an existing application, declare the plugin and its
61
+ required destination together in `app/toolframe.toml`. Core resolves the package
62
+ from PyPI; replace the destination with your operator-owned absolute backup path:
63
+
64
+ ```toml
65
+ [plugins.backup]
66
+ source = "pypi:toolframe-backup==0.1.0"
67
+ enabled = true
68
+
69
+ [plugins.backup.config]
70
+ destination = "/srv/toolframe-backups"
71
+ retention_keep = 10
72
+ ```
73
+
74
+ ```sh
75
+ toolframe-core --home ./app plan
76
+ toolframe-core --home ./app apply --plan-id <plan-id-from-the-plan-output>
77
+ ```
78
+
79
+ An installed Dashboard or MCP provider consumes the plugin's ordinary resources.
80
+ Grant `backup.read` to catalog readers. Verification and retention actions require
81
+ the built-in `system.plugins.manage` (Manage plugins) operator permission.
82
+ See the [catalog guide](src/toolframe_backup/docs/usage.md) for its service methods,
83
+ verification records and explicit retention workflow.
84
+
85
+ ## Support limits
86
+
87
+ - Version 1 supports local in-home files and local SQLite stores accepted by Core's
88
+ stopped maintenance inventory. Live or uncertain workers, pending recovery,
89
+ external SQL and external attachments are rejected by Core. S3 and other remote
90
+ archive destinations are not implemented.
91
+ - Archives are **unencrypted** and contain private keys, configuration and database
92
+ contents in their payloads. Store them in an operator-controlled local directory.
93
+ The public manifest contains identity, hashes, store ownership, retained-key
94
+ requirements and dependency prerequisites, without credential URLs or key bytes.
95
+ - SHA-256 checks detect corruption. They are not signatures and do not authenticate
96
+ an archive against an attacker who can replace both payload and manifest.
97
+ - Offline means the source host is stopped and the CLI needs no running application.
98
+ Restore reconstructs omitted backend/UI environments with uv from protected original
99
+ exact pylocks before reporting `ready: true`. It uses the final absolute directory
100
+ under Core's public application lock so console-script shebangs remain valid. Missing
101
+ dependency wheels require exact-hash wheels from a supplied wheelhouse or network;
102
+ an air-gapped restart is not guaranteed. uv performs locked dependency acquisition;
103
+ the CLI has no independent downloader. `--offline` forbids network acquisition and
104
+ `--wheelhouse` supplies local candidate wheels. Recovery requires the original Python
105
+ implementation, OS and machine architecture. A recorded two-component Python
106
+ version requires the same major/minor; a recorded three-component version requires
107
+ the exact patch too. The complete operator interpreter is checked against
108
+ Requires-Python, environment markers and wheel tags before publication. Reconstruction
109
+ requires compatible exact-hash wheels and supports at most 100 distinct environments;
110
+ source builds are disabled. Subprocess output is suppressed to protect credentials.
111
+ A failed reconstruction removes only the new destination created by that restore.
112
+ - A recovered clone retains the application ID and composition. Do not concurrently
113
+ run it with another copy using the same external identity. External state is outside
114
+ the supported recovery scope.
115
+ - Atomic restoration is supported on macOS and Linux. Default limits are 10,000
116
+ files, 512 MiB per payload file, 2 GiB total payload, 4 MiB manifest, 3 GiB archive,
117
+ 16 MiB protected environment payload and a maximum decompression ratio of 200.
118
+ ZIP central-directory size/count are checked before indexing. The catalog scans at
119
+ most 1,000 archives.
120
+
121
+ See the [archive architecture](docs/architecture.md) and
122
+ [offline recovery decision](docs/adr/0001-stopped-recovery-and-directory-catalog.md).
123
+
124
+ ## Development
125
+
126
+ Place the immutable matching Toolframe wheel set, including SDK, Core and their
127
+ prerequisites, in `build/wheelhouse/` before syncing. The Core wheel must provide the public
128
+ maintenance helpers used above. This library omits a committed `uv.lock` and
129
+ sibling source pins; development resolves dependencies from supplied or published
130
+ wheels.
131
+
132
+ ```sh
133
+ uv sync --no-sources --find-links ./build/wheelhouse --extra operator --extra ui --group dev
134
+ uv run --no-sync pytest
135
+ uv run --no-sync ruff check .
136
+ uv run --no-sync ruff format --check .
137
+ uv build
138
+ ```
139
+
140
+ Package tests cover archive boundaries with mocked Core inventories and guards, and
141
+ include real offline uv reconstruction of local environments in temporary homes.
142
+ Verify stopped-state eligibility, the actual Core lock and restored application,
143
+ Dashboard and client flows separately through an installed application. Package tests
144
+ do not establish remote-store or air-gap support.
145
+
146
+ Licensed under [Apache-2.0](LICENSE).
147
+
148
+ For release validation and Trusted Publisher setup, see [releasing](docs/releasing.md).
@@ -0,0 +1,126 @@
1
+ # Toolframe Backup
2
+
3
+ Toolframe Backup creates recovery archives of cleanly stopped Toolframe applications
4
+ and provides a Dashboard and read-only MCP catalog for a configured local backup
5
+ directory. Its standalone CLI can verify or restore archives even when the source
6
+ application cannot start. The ordinary plugin never snapshots a running application.
7
+
8
+ ## Quick start
9
+
10
+ Use Python 3.14 or newer. Archive creation
11
+ requires a Core release providing `toolframe_core.maintenance.stopped_application`.
12
+ Restoring recorded environments also requires its public `application_lock` helper.
13
+ Install the operator extra from PyPI:
14
+
15
+ ```sh
16
+ uv venv --python 3.14
17
+ uv pip install 'toolframe-backup[operator]==0.1.0'
18
+ # Stop the application's host and workers cleanly before creating the archive.
19
+ .venv/bin/toolframe-backup create --home ./app --directory ./backups
20
+ .venv/bin/toolframe-backup list --directory ./backups
21
+ .venv/bin/toolframe-backup verify ./backups/backup-<id>.zip
22
+ .venv/bin/toolframe-backup restore ./backups/backup-<id>.zip --destination ./recovered-app
23
+ # Optional local-only reconstruction (requires every exact-hash dependency locally):
24
+ .venv/bin/toolframe-backup restore ./backups/backup-<id>.zip --destination ./offline-recovered-app --offline --wheelhouse ./wheelhouse
25
+ ```
26
+
27
+ The CLI prints nonsecret JSON summaries; errors use exit code 2 and interruption
28
+ uses 130. New backup directories and restored directories have mode 0700. Archive
29
+ files and restored payload files have mode 0600; uv sets reconstructed environment
30
+ file modes. Existing backup directories must already have
31
+ mode 0700. Restore requires a new destination with an existing parent directory;
32
+ it never replaces an existing home, including an empty directory.
33
+ Supported restore paths include spaces and Unicode. Paths containing quotes,
34
+ backslashes or control characters are rejected before staging.
35
+ File URI wheel locators encode spaces, Unicode and URI delimiters such as `#`, `?`
36
+ and `%`; direct wheel paths retain their filesystem spelling.
37
+
38
+ To install the catalog in an existing application, declare the plugin and its
39
+ required destination together in `app/toolframe.toml`. Core resolves the package
40
+ from PyPI; replace the destination with your operator-owned absolute backup path:
41
+
42
+ ```toml
43
+ [plugins.backup]
44
+ source = "pypi:toolframe-backup==0.1.0"
45
+ enabled = true
46
+
47
+ [plugins.backup.config]
48
+ destination = "/srv/toolframe-backups"
49
+ retention_keep = 10
50
+ ```
51
+
52
+ ```sh
53
+ toolframe-core --home ./app plan
54
+ toolframe-core --home ./app apply --plan-id <plan-id-from-the-plan-output>
55
+ ```
56
+
57
+ An installed Dashboard or MCP provider consumes the plugin's ordinary resources.
58
+ Grant `backup.read` to catalog readers. Verification and retention actions require
59
+ the built-in `system.plugins.manage` (Manage plugins) operator permission.
60
+ See the [catalog guide](src/toolframe_backup/docs/usage.md) for its service methods,
61
+ verification records and explicit retention workflow.
62
+
63
+ ## Support limits
64
+
65
+ - Version 1 supports local in-home files and local SQLite stores accepted by Core's
66
+ stopped maintenance inventory. Live or uncertain workers, pending recovery,
67
+ external SQL and external attachments are rejected by Core. S3 and other remote
68
+ archive destinations are not implemented.
69
+ - Archives are **unencrypted** and contain private keys, configuration and database
70
+ contents in their payloads. Store them in an operator-controlled local directory.
71
+ The public manifest contains identity, hashes, store ownership, retained-key
72
+ requirements and dependency prerequisites, without credential URLs or key bytes.
73
+ - SHA-256 checks detect corruption. They are not signatures and do not authenticate
74
+ an archive against an attacker who can replace both payload and manifest.
75
+ - Offline means the source host is stopped and the CLI needs no running application.
76
+ Restore reconstructs omitted backend/UI environments with uv from protected original
77
+ exact pylocks before reporting `ready: true`. It uses the final absolute directory
78
+ under Core's public application lock so console-script shebangs remain valid. Missing
79
+ dependency wheels require exact-hash wheels from a supplied wheelhouse or network;
80
+ an air-gapped restart is not guaranteed. uv performs locked dependency acquisition;
81
+ the CLI has no independent downloader. `--offline` forbids network acquisition and
82
+ `--wheelhouse` supplies local candidate wheels. Recovery requires the original Python
83
+ implementation, OS and machine architecture. A recorded two-component Python
84
+ version requires the same major/minor; a recorded three-component version requires
85
+ the exact patch too. The complete operator interpreter is checked against
86
+ Requires-Python, environment markers and wheel tags before publication. Reconstruction
87
+ requires compatible exact-hash wheels and supports at most 100 distinct environments;
88
+ source builds are disabled. Subprocess output is suppressed to protect credentials.
89
+ A failed reconstruction removes only the new destination created by that restore.
90
+ - A recovered clone retains the application ID and composition. Do not concurrently
91
+ run it with another copy using the same external identity. External state is outside
92
+ the supported recovery scope.
93
+ - Atomic restoration is supported on macOS and Linux. Default limits are 10,000
94
+ files, 512 MiB per payload file, 2 GiB total payload, 4 MiB manifest, 3 GiB archive,
95
+ 16 MiB protected environment payload and a maximum decompression ratio of 200.
96
+ ZIP central-directory size/count are checked before indexing. The catalog scans at
97
+ most 1,000 archives.
98
+
99
+ See the [archive architecture](docs/architecture.md) and
100
+ [offline recovery decision](docs/adr/0001-stopped-recovery-and-directory-catalog.md).
101
+
102
+ ## Development
103
+
104
+ Place the immutable matching Toolframe wheel set, including SDK, Core and their
105
+ prerequisites, in `build/wheelhouse/` before syncing. The Core wheel must provide the public
106
+ maintenance helpers used above. This library omits a committed `uv.lock` and
107
+ sibling source pins; development resolves dependencies from supplied or published
108
+ wheels.
109
+
110
+ ```sh
111
+ uv sync --no-sources --find-links ./build/wheelhouse --extra operator --extra ui --group dev
112
+ uv run --no-sync pytest
113
+ uv run --no-sync ruff check .
114
+ uv run --no-sync ruff format --check .
115
+ uv build
116
+ ```
117
+
118
+ Package tests cover archive boundaries with mocked Core inventories and guards, and
119
+ include real offline uv reconstruction of local environments in temporary homes.
120
+ Verify stopped-state eligibility, the actual Core lock and restored application,
121
+ Dashboard and client flows separately through an installed application. Package tests
122
+ do not establish remote-store or air-gap support.
123
+
124
+ Licensed under [Apache-2.0](LICENSE).
125
+
126
+ For release validation and Trusted Publisher setup, see [releasing](docs/releasing.md).
@@ -0,0 +1,34 @@
1
+ # ADR 0001: Stopped recovery and a directory catalog
2
+
3
+ Status: accepted
4
+
5
+ ## Context
6
+
7
+ A useful recovery archive must bind configuration, captured artifacts, journal locks,
8
+ business data and retained private keys to one application composition. Copying a live
9
+ host's home can mix generations and transactions. A recovery tool must also work when
10
+ the application's plugin runtime cannot start.
11
+
12
+ ## Decision
13
+
14
+ Creation is a standalone operator command using Core's public stopped maintenance
15
+ context. Core owns layout and eligibility, while Backup owns archives, bounded
16
+ verification, restoration into a new home and local retention. Ordinary plugin
17
+ resources expose a directory catalog and guide operators through the stopped workflow.
18
+ The configured directory provides catalog truth; previews and verification observations
19
+ can be rebuilt without coupling recovery to a SQL provider, Jobs or Audit.
20
+
21
+ Version 1 accepts only local files and SQLite stores inside the application home.
22
+ Archives retain the application identity and exact dependency prerequisites; omitted
23
+ runtime environments are reconstructed at the final path under Core's public lock,
24
+ using protected original exact pylocks before recovery is declared ready. Rehydration can require a network
25
+ or a prepared wheelhouse. Archive encryption and signatures are deferred, so operator
26
+ filesystem permissions protect confidentiality and hashes detect corruption only.
27
+
28
+ ## Consequences
29
+
30
+ The runtime cannot offer a live-backup button. Operators must stop the host cleanly
31
+ before capture, and external storage needs a future explicit consistency contract.
32
+ Recovery remains available without a functioning source application. A restored clone
33
+ must not concurrently reuse the same external identity. Directory scanning costs full
34
+ verification work and is bounded; unknown files remain untouched by retention.