dorestic 0.4.4__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.
- dorestic-0.4.4/LICENSE +190 -0
- dorestic-0.4.4/PKG-INFO +367 -0
- dorestic-0.4.4/README.md +341 -0
- dorestic-0.4.4/pyproject.toml +56 -0
- dorestic-0.4.4/setup.cfg +4 -0
- dorestic-0.4.4/src/dorestic/__init__.py +39 -0
- dorestic-0.4.4/src/dorestic/__main__.py +4 -0
- dorestic-0.4.4/src/dorestic/backup.py +356 -0
- dorestic-0.4.4/src/dorestic/cli.py +58 -0
- dorestic-0.4.4/src/dorestic/config.py +110 -0
- dorestic-0.4.4/src/dorestic/config.yml.example +50 -0
- dorestic-0.4.4/src/dorestic/docker.py +211 -0
- dorestic-0.4.4/src/dorestic/models.py +64 -0
- dorestic-0.4.4/src/dorestic/paths.py +61 -0
- dorestic-0.4.4/src/dorestic/restic.py +111 -0
- dorestic-0.4.4/src/dorestic.egg-info/PKG-INFO +367 -0
- dorestic-0.4.4/src/dorestic.egg-info/SOURCES.txt +22 -0
- dorestic-0.4.4/src/dorestic.egg-info/dependency_links.txt +1 -0
- dorestic-0.4.4/src/dorestic.egg-info/entry_points.txt +2 -0
- dorestic-0.4.4/src/dorestic.egg-info/requires.txt +2 -0
- dorestic-0.4.4/src/dorestic.egg-info/top_level.txt +1 -0
- dorestic-0.4.4/tests/test_backup.py +786 -0
- dorestic-0.4.4/tests/test_docker.py +347 -0
- dorestic-0.4.4/tests/test_unit.py +578 -0
dorestic-0.4.4/LICENSE
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
Copyright 2025 Eddie Cornejo
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|
dorestic-0.4.4/PKG-INFO
ADDED
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dorestic
|
|
3
|
+
Version: 0.4.4
|
|
4
|
+
Summary: A label-driven backup system for Docker containers using restic
|
|
5
|
+
Author: Eddie Cornejo
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/cornejo/dorestic
|
|
8
|
+
Project-URL: Repository, https://github.com/cornejo/dorestic
|
|
9
|
+
Project-URL: Issues, https://github.com/cornejo/dorestic/issues
|
|
10
|
+
Project-URL: Changelog, https://github.com/cornejo/dorestic/blob/main/CHANGELOG.md
|
|
11
|
+
Project-URL: Funding, https://ko-fi.com/rdacted
|
|
12
|
+
Keywords: backup,docker,restic,containers
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: System Administrators
|
|
15
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Topic :: System :: Archiving :: Backup
|
|
20
|
+
Requires-Python: >=3.12
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Requires-Dist: docker<8.0,>=7.0
|
|
24
|
+
Requires-Dist: pyyaml<7.0,>=6.0
|
|
25
|
+
Dynamic: license-file
|
|
26
|
+
|
|
27
|
+
# dorestic
|
|
28
|
+
|
|
29
|
+
A label-driven backup system for Docker containers using [restic](https://restic.net/).
|
|
30
|
+
|
|
31
|
+
Containers opt in to backups by adding labels to their compose file. A host-side
|
|
32
|
+
Python script discovers opted-in containers, runs lifecycle hooks (e.g. database
|
|
33
|
+
dumps), resolves volume mounts to host paths, and spawns a disposable
|
|
34
|
+
`restic/restic:latest` container for each backup scope. The restic container has
|
|
35
|
+
no Docker socket and can only read the specific paths mounted into it.
|
|
36
|
+
|
|
37
|
+
## Installation
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
uv tool install dorestic
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Or directly from a git repository:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
uv tool install git+https://github.com/USER/dorestic.git
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Quick Start
|
|
50
|
+
|
|
51
|
+
1. Generate an example config:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
dorestic --init ~/.config/dorestic/
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Edit `~/.config/dorestic/config.yml` and set `repository` and `password_file`.
|
|
58
|
+
|
|
59
|
+
2. Create the password file:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
echo -n 'your-restic-password' > /etc/backup/restic-password
|
|
63
|
+
chmod 600 /etc/backup/restic-password
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
3. Add labels to any container you want backed up:
|
|
67
|
+
|
|
68
|
+
```yaml
|
|
69
|
+
services:
|
|
70
|
+
my-db:
|
|
71
|
+
image: postgres:17
|
|
72
|
+
volumes:
|
|
73
|
+
- ./pgdata:/var/lib/postgresql/data
|
|
74
|
+
labels:
|
|
75
|
+
backup.enable: "true"
|
|
76
|
+
backup.container.paths: "/var/lib/postgresql/data"
|
|
77
|
+
backup.container.on_start: "pg_dumpall -U postgres --clean > /var/lib/postgresql/data/dump.sql"
|
|
78
|
+
backup.container.on_complete: "rm -f /var/lib/postgresql/data/dump.sql"
|
|
79
|
+
backup.host.paths: ".@1"
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
4. Run a backup:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
dorestic
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
5. (Optional) Add to cron:
|
|
89
|
+
|
|
90
|
+
```
|
|
91
|
+
0 3 * * * dorestic
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Configuration
|
|
95
|
+
|
|
96
|
+
Config is loaded from the first location found:
|
|
97
|
+
|
|
98
|
+
1. `./config.yml` (current directory)
|
|
99
|
+
2. `$XDG_CONFIG_HOME/dorestic/config.yml` (default: `~/.config/dorestic/config.yml`)
|
|
100
|
+
|
|
101
|
+
Or pass a path explicitly: `dorestic /path/to/config.yml`
|
|
102
|
+
|
|
103
|
+
Run `dorestic --init [PATH]` to write an example config with documentation.
|
|
104
|
+
|
|
105
|
+
```yaml
|
|
106
|
+
repository: /mnt/backup/backup1
|
|
107
|
+
password_file: /etc/backup/restic-password
|
|
108
|
+
|
|
109
|
+
# restic_image: restic/restic:latest
|
|
110
|
+
# on_start: /path/to/on_start.sh
|
|
111
|
+
# on_complete: /path/to/on_complete.sh
|
|
112
|
+
|
|
113
|
+
# retention:
|
|
114
|
+
# daily: 7
|
|
115
|
+
# weekly: 4
|
|
116
|
+
# monthly: 12
|
|
117
|
+
|
|
118
|
+
# host_groups:
|
|
119
|
+
# - tag: documents
|
|
120
|
+
# paths: [/mnt/fileserver/share]
|
|
121
|
+
# exclude: ["*.tmp"]
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
The password file is mounted read-only into the restic container via
|
|
125
|
+
`RESTIC_PASSWORD_FILE` — the password never appears on the command line or in
|
|
126
|
+
`ps` output.
|
|
127
|
+
|
|
128
|
+
| Field | Required | Description |
|
|
129
|
+
|---|---|---|
|
|
130
|
+
| `repository` | Yes | Restic repository path |
|
|
131
|
+
| `password_file` | Yes | Path to a file containing the restic password |
|
|
132
|
+
| `restic_image` | No | Docker image for restic (default: `restic/restic:latest`) |
|
|
133
|
+
| `on_start` | No | Command to run before the backup starts. If it exits non-zero, the backup is aborted. |
|
|
134
|
+
| `on_complete` | No | Command to run after the entire backup. Env: `$DORESTIC_EXIT_CODE`, `$DORESTIC_LOGFILE` |
|
|
135
|
+
| `retention` | No | Snapshot retention policy (default: 7 daily, 4 weekly, 12 monthly) |
|
|
136
|
+
| `host_groups` | No | Host-only backup groups (see below) |
|
|
137
|
+
|
|
138
|
+
## Architecture
|
|
139
|
+
|
|
140
|
+
```
|
|
141
|
+
Host (dorestic) Restic container (docker run --rm)
|
|
142
|
+
┌───────────────────────────────┐ ┌────────────────────────────────┐
|
|
143
|
+
│ Load config.yml │ │ No Docker socket │
|
|
144
|
+
│ Acquire process lock │ │ No host filesystem access │
|
|
145
|
+
│ Discover labeled containers │ │ Only explicitly mounted paths │
|
|
146
|
+
│ Run on_start hooks │ spawn │ Data paths mounted read-only │
|
|
147
|
+
│ Resolve volume mounts → paths │ ────► │ Password via mounted file │
|
|
148
|
+
│ docker cp for unmounted paths │ │ Runs restic backup │
|
|
149
|
+
│ Expand depth-limited paths │ │ Deleted on completion (--rm) │
|
|
150
|
+
│ Run on_complete hooks │ └────────────────────────────────┘
|
|
151
|
+
│ Forget/prune/check │
|
|
152
|
+
│ Run on_complete callback │
|
|
153
|
+
└───────────────────────────────┘
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
The backup script runs on the host and interacts with Docker via the Python SDK.
|
|
157
|
+
For each backup scope, it spawns a fresh `restic/restic:latest` container with
|
|
158
|
+
`docker run --rm`, mounting only the necessary data paths (read-only) and the
|
|
159
|
+
restic repository. The container is automatically removed on completion.
|
|
160
|
+
|
|
161
|
+
## Labels
|
|
162
|
+
|
|
163
|
+
Each container can define two backup scopes — **container** (paths inside the
|
|
164
|
+
container, resolved via volume mounts) and **host** (paths relative to the
|
|
165
|
+
compose project directory).
|
|
166
|
+
|
|
167
|
+
| Label | Required | Description |
|
|
168
|
+
|---|---|---|
|
|
169
|
+
| `backup.enable` | Yes | `"true"` to opt in |
|
|
170
|
+
| `backup.container.paths` | No | Comma-separated container-internal paths to back up |
|
|
171
|
+
| `backup.container.exclude` | No | Comma-separated restic exclude patterns for container scope |
|
|
172
|
+
| `backup.container.on_start` | No | Command run inside the container before container backup. Env: `$DORESTIC_TAG` |
|
|
173
|
+
| `backup.container.on_complete` | No | Command run inside the container after container backup. Env: `$DORESTIC_TAG`, `$DORESTIC_EXIT_CODE` |
|
|
174
|
+
| `backup.container.shell` | No | Shell used for container hooks (default: `sh`) |
|
|
175
|
+
| `backup.host.paths` | No | Comma-separated paths relative to the compose project directory |
|
|
176
|
+
| `backup.host.exclude` | No | Comma-separated restic exclude patterns for host scope |
|
|
177
|
+
| `backup.host.on_start` | No | Command run on the host before host backup. Env: `$DORESTIC_TAG` |
|
|
178
|
+
| `backup.host.on_complete` | No | Command run on the host after host backup. Env: `$DORESTIC_TAG`, `$DORESTIC_EXIT_CODE` |
|
|
179
|
+
| `backup.suppress-mount-warning` | No | `"true"` to silence warnings when container paths fall back to `docker cp` (see below) |
|
|
180
|
+
|
|
181
|
+
### Container paths
|
|
182
|
+
|
|
183
|
+
Paths in `backup.container.paths` are resolved to host paths by inspecting the
|
|
184
|
+
container's volume mounts. The longest prefix match is used when multiple mounts
|
|
185
|
+
overlap.
|
|
186
|
+
|
|
187
|
+
If a path has no matching volume mount, dorestic cannot resolve it to a host
|
|
188
|
+
path directly. Instead, it falls back to `docker cp` to extract the data to a
|
|
189
|
+
temporary staging directory before backing it up. This is slower and uses extra
|
|
190
|
+
disk space, so dorestic logs a warning when it happens. If this is intentional
|
|
191
|
+
(e.g. the container stores data outside any mounted volume), set
|
|
192
|
+
`backup.suppress-mount-warning` to `"true"` to silence the warning.
|
|
193
|
+
|
|
194
|
+
### Host paths and depth
|
|
195
|
+
|
|
196
|
+
`backup.host.paths` are resolved relative to the container's compose project
|
|
197
|
+
directory (`com.docker.compose.project.working_dir`). Append `@N` to limit
|
|
198
|
+
depth:
|
|
199
|
+
|
|
200
|
+
| Value | Meaning |
|
|
201
|
+
|---|---|
|
|
202
|
+
| `.@1` | Top-level files in the compose dir (compose file, .env, etc.) |
|
|
203
|
+
| `.` | Entire compose directory, recursive |
|
|
204
|
+
| `../shared-config@2` | Sibling directory, 2 levels deep |
|
|
205
|
+
|
|
206
|
+
## Lifecycle
|
|
207
|
+
|
|
208
|
+
For each container, the two scopes (container and host) are independent:
|
|
209
|
+
|
|
210
|
+
```
|
|
211
|
+
container.on_start ─→ container backup ─→ container.on_complete
|
|
212
|
+
host.on_start ──────→ host backup ──────→ host.on_complete
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
- Each scope runs independently — a failing `container.on_start` does not
|
|
216
|
+
affect the host scope, and vice versa.
|
|
217
|
+
- If `on_start` fails, the backup for that scope is skipped, but `on_complete`
|
|
218
|
+
still runs with the failure code.
|
|
219
|
+
- `on_complete` failures log a warning but don't affect the backup's exit code.
|
|
220
|
+
- Hooks run inside the target container via `docker exec`, so they have access
|
|
221
|
+
to that container's tools (e.g. `pg_dumpall` in a postgres image).
|
|
222
|
+
|
|
223
|
+
## Snapshots
|
|
224
|
+
|
|
225
|
+
Each container gets up to two tagged restic snapshots per run:
|
|
226
|
+
|
|
227
|
+
- `<name>:container` — container-internal paths (resolved to host via mounts)
|
|
228
|
+
- `<name>:host` — host/compose directory paths
|
|
229
|
+
|
|
230
|
+
```bash
|
|
231
|
+
# List all snapshots
|
|
232
|
+
restic snapshots
|
|
233
|
+
|
|
234
|
+
# List snapshots for a specific container scope
|
|
235
|
+
restic snapshots --tag my-db:container
|
|
236
|
+
|
|
237
|
+
# List host-scope snapshots
|
|
238
|
+
restic snapshots --tag my-db:host
|
|
239
|
+
|
|
240
|
+
# Restore a specific scope
|
|
241
|
+
restic restore --tag my-db:container latest --target /tmp/restore/
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
Retention policy is configurable in `config.yml`. Default: 7 daily, 4 weekly,
|
|
245
|
+
12 monthly. Applied per tag via `--group-by tags`.
|
|
246
|
+
|
|
247
|
+
## Host Backup Groups
|
|
248
|
+
|
|
249
|
+
Host-only backup groups (not tied to any container) are configured in the
|
|
250
|
+
`host_groups` section of `config.yml`:
|
|
251
|
+
|
|
252
|
+
```yaml
|
|
253
|
+
host_groups:
|
|
254
|
+
- tag: documents
|
|
255
|
+
paths:
|
|
256
|
+
- /mnt/fileserver/share
|
|
257
|
+
- /mnt/fileserver/share-private
|
|
258
|
+
exclude:
|
|
259
|
+
- "*.tmp"
|
|
260
|
+
|
|
261
|
+
- tag: docker-config
|
|
262
|
+
paths:
|
|
263
|
+
- /mnt/fileserver/docker
|
|
264
|
+
exclude:
|
|
265
|
+
- "aosp-mirror/mirror"
|
|
266
|
+
on_start: /config/pre-docker-backup.sh
|
|
267
|
+
on_complete: /config/notify-documents.sh
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
| Field | Required | Description |
|
|
271
|
+
|---|---|---|
|
|
272
|
+
| `tag` | Yes | Restic tag for this group's snapshot |
|
|
273
|
+
| `paths` | Yes | List of absolute host paths to back up |
|
|
274
|
+
| `exclude` | No | List of restic exclude patterns |
|
|
275
|
+
| `on_start` | No | Command to run before backup. Env: `$DORESTIC_TAG`. Failure skips the backup. |
|
|
276
|
+
| `on_complete` | No | Command to run after backup. Env: `$DORESTIC_TAG`, `$DORESTIC_EXIT_CODE` |
|
|
277
|
+
|
|
278
|
+
## Examples
|
|
279
|
+
|
|
280
|
+
### Database with dump
|
|
281
|
+
|
|
282
|
+
```yaml
|
|
283
|
+
services:
|
|
284
|
+
database:
|
|
285
|
+
image: postgres:17
|
|
286
|
+
volumes:
|
|
287
|
+
- ${DB_DATA_LOCATION}:/var/lib/postgresql/data
|
|
288
|
+
labels:
|
|
289
|
+
backup.enable: "true"
|
|
290
|
+
backup.container.paths: "/var/lib/postgresql/data"
|
|
291
|
+
backup.container.exclude: "*.log"
|
|
292
|
+
backup.container.on_start: "pg_dumpall -U postgres --clean > /var/lib/postgresql/data/dump.sql"
|
|
293
|
+
backup.container.on_complete: "rm -f /var/lib/postgresql/data/dump.sql"
|
|
294
|
+
backup.host.paths: ".@1"
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
The dump file is created by `on_start`, included in the restic snapshot, then
|
|
298
|
+
cleaned up by `on_complete` — regardless of whether the backup succeeded.
|
|
299
|
+
|
|
300
|
+
### Application with uploads
|
|
301
|
+
|
|
302
|
+
```yaml
|
|
303
|
+
services:
|
|
304
|
+
app:
|
|
305
|
+
image: myapp:latest
|
|
306
|
+
volumes:
|
|
307
|
+
- ${UPLOAD_LOCATION}:/usr/src/app/upload
|
|
308
|
+
labels:
|
|
309
|
+
backup.enable: "true"
|
|
310
|
+
backup.container.paths: "/usr/src/app/upload"
|
|
311
|
+
backup.container.exclude: "*.tmp,thumbs/"
|
|
312
|
+
backup.host.paths: ".@1"
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
### Exclude pattern tips
|
|
316
|
+
|
|
317
|
+
- Patterns use restic's native `--exclude` syntax, interpreted relative to the
|
|
318
|
+
backup root(s).
|
|
319
|
+
- Container and host scopes are separate restic invocations — `backup.host.exclude`
|
|
320
|
+
never affects the container scope or other containers.
|
|
321
|
+
- Do **not** compress or encrypt files before handing them to restic. Restic
|
|
322
|
+
already does both, and pre-processed data destroys chunk-level deduplication.
|
|
323
|
+
|
|
324
|
+
## Dependencies
|
|
325
|
+
|
|
326
|
+
- Python 3.12+
|
|
327
|
+
- `docker` Python SDK
|
|
328
|
+
- `pyyaml`
|
|
329
|
+
- Docker daemon with `restic/restic:latest` image available
|
|
330
|
+
|
|
331
|
+
## Testing
|
|
332
|
+
|
|
333
|
+
```bash
|
|
334
|
+
uv run pytest tests/ -v
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
Tests require a running Docker daemon and the `restic/restic:latest` image.
|
|
338
|
+
Unit tests (no Docker) can be run in isolation:
|
|
339
|
+
|
|
340
|
+
```bash
|
|
341
|
+
uv run pytest tests/test_unit.py -v
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
## File Structure
|
|
345
|
+
|
|
346
|
+
```
|
|
347
|
+
dorestic/
|
|
348
|
+
├── src/dorestic/
|
|
349
|
+
│ ├── __init__.py # Public API re-exports
|
|
350
|
+
│ ├── __main__.py # Entry point for python -m dorestic
|
|
351
|
+
│ ├── cli.py # Argument parsing and --init
|
|
352
|
+
│ ├── models.py # Dataclasses and constants
|
|
353
|
+
│ ├── config.py # Config file loading and validation
|
|
354
|
+
│ ├── config.yml.example # Bundled example config (used by --init)
|
|
355
|
+
│ ├── restic.py # Restic container invocation
|
|
356
|
+
│ ├── docker.py # Docker container operations
|
|
357
|
+
│ ├── paths.py # Path resolution utilities
|
|
358
|
+
│ └── backup.py # Backup orchestration
|
|
359
|
+
├── tests/
|
|
360
|
+
│ ├── conftest.py # Fixtures and test infrastructure
|
|
361
|
+
│ ├── test_unit.py # Pure function tests (no Docker)
|
|
362
|
+
│ ├── test_docker.py # Docker integration tests
|
|
363
|
+
│ └── test_backup.py # Backup execution and lifecycle tests
|
|
364
|
+
├── pyproject.toml
|
|
365
|
+
├── pyrightconfig.json
|
|
366
|
+
└── .gitignore
|
|
367
|
+
```
|