ptctools 0.1.0__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.
- ptctools/__init__.py +3 -0
- ptctools/_portainer.py +279 -0
- ptctools/_s3.py +150 -0
- ptctools/cli.py +28 -0
- ptctools/config.py +293 -0
- ptctools/db.py +544 -0
- ptctools/stack.py +367 -0
- ptctools/utils.py +416 -0
- ptctools/volume.py +359 -0
- ptctools-0.1.0.dist-info/METADATA +99 -0
- ptctools-0.1.0.dist-info/RECORD +14 -0
- ptctools-0.1.0.dist-info/WHEEL +4 -0
- ptctools-0.1.0.dist-info/entry_points.txt +2 -0
- ptctools-0.1.0.dist-info/licenses/LICENSE +201 -0
ptctools/volume.py
ADDED
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
"""Volume backup and restore commands."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
import sys
|
|
7
|
+
|
|
8
|
+
import click
|
|
9
|
+
|
|
10
|
+
from ptctools._portainer import run_ephemeral_container
|
|
11
|
+
from ptctools._s3 import (
|
|
12
|
+
parse_s3_uri,
|
|
13
|
+
get_s3_endpoint,
|
|
14
|
+
get_s3_credentials,
|
|
15
|
+
build_duplicati_s3_url,
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def backup_volume(
|
|
20
|
+
portainer_url: str,
|
|
21
|
+
api_key: str,
|
|
22
|
+
endpoint_id: int,
|
|
23
|
+
volume_name: str,
|
|
24
|
+
s3_endpoint: str,
|
|
25
|
+
s3_bucket: str,
|
|
26
|
+
s3_access_key: str,
|
|
27
|
+
s3_secret_key: str,
|
|
28
|
+
keep_versions: int,
|
|
29
|
+
passphrase: str,
|
|
30
|
+
) -> bool:
|
|
31
|
+
"""Backup a single volume to S3 using Duplicati CLI."""
|
|
32
|
+
s3_dest = build_duplicati_s3_url(s3_bucket, volume_name, s3_endpoint)
|
|
33
|
+
|
|
34
|
+
click.echo(f"Backing up {volume_name} using Duplicati...")
|
|
35
|
+
|
|
36
|
+
# Common options for both repair and backup
|
|
37
|
+
common_opts = " ".join([
|
|
38
|
+
f"--aws-access-key-id={s3_access_key}",
|
|
39
|
+
f"--aws-secret-access-key={s3_secret_key}",
|
|
40
|
+
f"--passphrase={passphrase}" if passphrase else "--no-encryption",
|
|
41
|
+
"--dbpath=/tmp/duplicati.sqlite",
|
|
42
|
+
])
|
|
43
|
+
|
|
44
|
+
# Repair command to rebuild local database from remote
|
|
45
|
+
repair_cmd = f"duplicati-cli repair '{s3_dest}' {common_opts}"
|
|
46
|
+
|
|
47
|
+
# Backup command
|
|
48
|
+
backup_cmd = " ".join([
|
|
49
|
+
"duplicati-cli",
|
|
50
|
+
"backup",
|
|
51
|
+
f"'{s3_dest}'",
|
|
52
|
+
"/data",
|
|
53
|
+
common_opts,
|
|
54
|
+
f"--keep-versions={keep_versions}",
|
|
55
|
+
"--retention-policy=",
|
|
56
|
+
])
|
|
57
|
+
|
|
58
|
+
# Run repair first (rebuilds local DB from remote), then backup
|
|
59
|
+
# Use ; instead of && because repair may return non-zero for warnings
|
|
60
|
+
full_cmd = f"{repair_cmd}; {backup_cmd}"
|
|
61
|
+
|
|
62
|
+
backup_config = {
|
|
63
|
+
"Image": "duplicati/duplicati:latest",
|
|
64
|
+
"Entrypoint": ["/bin/sh", "-c"],
|
|
65
|
+
"Cmd": [full_cmd],
|
|
66
|
+
"HostConfig": {
|
|
67
|
+
"Binds": [f"{volume_name}:/data:ro"],
|
|
68
|
+
"AutoRemove": False,
|
|
69
|
+
},
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
exit_code, logs = run_ephemeral_container(
|
|
73
|
+
portainer_url, api_key, endpoint_id, backup_config
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
# Check for backup failure
|
|
77
|
+
# Exit code 1 with "0 files need to be examined" = success (no changes)
|
|
78
|
+
no_changes = exit_code == 1 and logs and "0 files need to be examined" in logs
|
|
79
|
+
if exit_code != 0 and not no_changes:
|
|
80
|
+
click.echo(f" ✗ Backup failed with exit code {exit_code}")
|
|
81
|
+
if logs:
|
|
82
|
+
click.echo(f" Logs: {logs}")
|
|
83
|
+
return False
|
|
84
|
+
|
|
85
|
+
click.echo(f" ✓ Backup completed: s3://{s3_bucket}/{volume_name}")
|
|
86
|
+
if logs:
|
|
87
|
+
for line in logs.split("\n"):
|
|
88
|
+
if any(
|
|
89
|
+
k in line.lower()
|
|
90
|
+
for k in ["uploaded", "added", "deleted", "modified", "examined"]
|
|
91
|
+
):
|
|
92
|
+
click.echo(f" {line.strip()}")
|
|
93
|
+
|
|
94
|
+
return True
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def restore_volume(
|
|
98
|
+
portainer_url: str,
|
|
99
|
+
api_key: str,
|
|
100
|
+
endpoint_id: int,
|
|
101
|
+
volume_name: str,
|
|
102
|
+
s3_endpoint: str,
|
|
103
|
+
s3_bucket: str,
|
|
104
|
+
s3_path: str,
|
|
105
|
+
s3_access_key: str,
|
|
106
|
+
s3_secret_key: str,
|
|
107
|
+
passphrase: str,
|
|
108
|
+
version: int | None,
|
|
109
|
+
restore_time: str | None,
|
|
110
|
+
) -> bool:
|
|
111
|
+
"""Restore a single volume from S3 using Duplicati CLI.
|
|
112
|
+
|
|
113
|
+
Args:
|
|
114
|
+
s3_path: S3 path to restore from (used directly, no modification).
|
|
115
|
+
"""
|
|
116
|
+
s3_dest = build_duplicati_s3_url(s3_bucket, s3_path, s3_endpoint)
|
|
117
|
+
|
|
118
|
+
click.echo(f"Restoring {volume_name} using Duplicati...")
|
|
119
|
+
|
|
120
|
+
restore_cmd = [
|
|
121
|
+
"duplicati-cli",
|
|
122
|
+
"restore",
|
|
123
|
+
s3_dest,
|
|
124
|
+
"/data/",
|
|
125
|
+
f"--aws-access-key-id={s3_access_key}",
|
|
126
|
+
f"--aws-secret-access-key={s3_secret_key}",
|
|
127
|
+
f"--passphrase={passphrase}",
|
|
128
|
+
"--overwrite=true",
|
|
129
|
+
"--dbpath=/tmp/duplicati.sqlite",
|
|
130
|
+
"--no-encryption" if not passphrase else "",
|
|
131
|
+
]
|
|
132
|
+
|
|
133
|
+
if version is not None:
|
|
134
|
+
restore_cmd.append(f"--version={version}")
|
|
135
|
+
if restore_time:
|
|
136
|
+
restore_cmd.append(f"--time={restore_time}")
|
|
137
|
+
|
|
138
|
+
restore_cmd = [c for c in restore_cmd if c]
|
|
139
|
+
|
|
140
|
+
restore_config = {
|
|
141
|
+
"Image": "duplicati/duplicati:latest",
|
|
142
|
+
"Cmd": restore_cmd,
|
|
143
|
+
"HostConfig": {
|
|
144
|
+
"Binds": [f"{volume_name}:/data"],
|
|
145
|
+
"AutoRemove": False,
|
|
146
|
+
},
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
exit_code, logs = run_ephemeral_container(
|
|
150
|
+
portainer_url, api_key, endpoint_id, restore_config
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
# Success if exit_code == 0, or exit_code == 2 with no files needing restore (already up-to-date)
|
|
154
|
+
already_up_to_date = exit_code == 2 and logs and "0 files need to be restored" in logs
|
|
155
|
+
if exit_code != 0 and not already_up_to_date:
|
|
156
|
+
click.echo(f" ✗ Restore failed with exit code {exit_code}")
|
|
157
|
+
if logs:
|
|
158
|
+
click.echo(f" Logs: {logs}")
|
|
159
|
+
return False
|
|
160
|
+
|
|
161
|
+
click.echo(f" ✓ Restore completed from s3://{s3_bucket}/{volume_name}")
|
|
162
|
+
if logs:
|
|
163
|
+
for line in logs.split("\n"):
|
|
164
|
+
if any(
|
|
165
|
+
k in line.lower() for k in ["restored", "downloaded", "files", "bytes"]
|
|
166
|
+
):
|
|
167
|
+
click.echo(f" {line.strip()}")
|
|
168
|
+
|
|
169
|
+
return True
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
@click.group()
|
|
173
|
+
def cli():
|
|
174
|
+
"""Volume backup and restore commands."""
|
|
175
|
+
pass
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
@cli.command()
|
|
179
|
+
@click.option("--url", "-u", required=True, help="Portainer base URL")
|
|
180
|
+
@click.option(
|
|
181
|
+
"--volumes", "-v", required=True, help="Comma-separated list of volume names"
|
|
182
|
+
)
|
|
183
|
+
@click.option(
|
|
184
|
+
"--output",
|
|
185
|
+
"-o",
|
|
186
|
+
required=True,
|
|
187
|
+
help="S3 URI (e.g., s3://bucket or s3://endpoint/bucket)",
|
|
188
|
+
)
|
|
189
|
+
@click.option("--s3-endpoint", help="S3/MinIO endpoint URL (or S3_ENDPOINT env var)")
|
|
190
|
+
@click.option("--endpoint-id", "-e", type=int, default=1, help="Portainer endpoint ID")
|
|
191
|
+
@click.option(
|
|
192
|
+
"--keep-versions", type=int, default=7, help="Keep N versions of backups"
|
|
193
|
+
)
|
|
194
|
+
@click.option("--passphrase", type=str, default="", help="Encryption passphrase")
|
|
195
|
+
def backup(
|
|
196
|
+
url: str,
|
|
197
|
+
volumes: str,
|
|
198
|
+
output: str,
|
|
199
|
+
s3_endpoint: str | None,
|
|
200
|
+
endpoint_id: int,
|
|
201
|
+
keep_versions: int,
|
|
202
|
+
passphrase: str,
|
|
203
|
+
):
|
|
204
|
+
"""Backup Docker volumes to S3 using Duplicati."""
|
|
205
|
+
access_token = os.environ.get("PORTAINER_ACCESS_TOKEN")
|
|
206
|
+
if not access_token:
|
|
207
|
+
click.echo("Error: Missing PORTAINER_ACCESS_TOKEN", err=True)
|
|
208
|
+
sys.exit(1)
|
|
209
|
+
|
|
210
|
+
try:
|
|
211
|
+
s3_access_key, s3_secret_key = get_s3_credentials()
|
|
212
|
+
except click.ClickException as e:
|
|
213
|
+
click.echo(f"Error: {e.message}", err=True)
|
|
214
|
+
sys.exit(1)
|
|
215
|
+
|
|
216
|
+
# Parse S3 URI
|
|
217
|
+
try:
|
|
218
|
+
uri_endpoint, s3_bucket, _ = parse_s3_uri(output)
|
|
219
|
+
endpoint = get_s3_endpoint(uri_endpoint, s3_endpoint)
|
|
220
|
+
except click.ClickException as e:
|
|
221
|
+
click.echo(f"Error: {e.message}", err=True)
|
|
222
|
+
sys.exit(1)
|
|
223
|
+
|
|
224
|
+
passphrase = passphrase or os.environ.get("DUPLICATI_PASSPHRASE", "")
|
|
225
|
+
portainer_url = url.rstrip("/")
|
|
226
|
+
volume_list = [v.strip() for v in volumes.split(",")]
|
|
227
|
+
|
|
228
|
+
click.echo(f"Portainer URL: {portainer_url}")
|
|
229
|
+
click.echo(f"S3 Endpoint: {endpoint}")
|
|
230
|
+
click.echo(f"S3 Bucket: {s3_bucket}")
|
|
231
|
+
click.echo(f"Volumes: {len(volume_list)}")
|
|
232
|
+
click.echo(f"Keep Versions: {keep_versions}")
|
|
233
|
+
click.echo(f"Encryption: {'Enabled' if passphrase else 'Disabled'}")
|
|
234
|
+
click.echo()
|
|
235
|
+
click.echo("=== Backing up volumes with Duplicati ===")
|
|
236
|
+
|
|
237
|
+
success_count = 0
|
|
238
|
+
for vol in volume_list:
|
|
239
|
+
if backup_volume(
|
|
240
|
+
portainer_url,
|
|
241
|
+
access_token,
|
|
242
|
+
endpoint_id,
|
|
243
|
+
vol,
|
|
244
|
+
endpoint,
|
|
245
|
+
s3_bucket,
|
|
246
|
+
s3_access_key,
|
|
247
|
+
s3_secret_key,
|
|
248
|
+
keep_versions,
|
|
249
|
+
passphrase,
|
|
250
|
+
):
|
|
251
|
+
success_count += 1
|
|
252
|
+
click.echo()
|
|
253
|
+
|
|
254
|
+
click.echo("=== Volume backup complete ===")
|
|
255
|
+
click.echo(f"Successfully backed up {success_count}/{len(volume_list)} volumes")
|
|
256
|
+
sys.exit(0 if success_count == len(volume_list) else 1)
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
@cli.command()
|
|
260
|
+
@click.option("--url", "-u", required=True, help="Portainer base URL")
|
|
261
|
+
@click.option(
|
|
262
|
+
"--volume",
|
|
263
|
+
"-v",
|
|
264
|
+
default=None,
|
|
265
|
+
help="Volume name (derived from input URI path if not provided)",
|
|
266
|
+
)
|
|
267
|
+
@click.option(
|
|
268
|
+
"--input",
|
|
269
|
+
"-i",
|
|
270
|
+
"input_uri",
|
|
271
|
+
required=True,
|
|
272
|
+
help="S3 URI (e.g., s3://bucket/volume-name or s3://endpoint/bucket/volume-name)",
|
|
273
|
+
)
|
|
274
|
+
@click.option("--s3-endpoint", help="S3/MinIO endpoint URL (or S3_ENDPOINT env var)")
|
|
275
|
+
@click.option("--endpoint-id", "-e", type=int, default=1, help="Portainer endpoint ID")
|
|
276
|
+
@click.option(
|
|
277
|
+
"--version", type=int, default=None, help="Backup version to restore (0=latest)"
|
|
278
|
+
)
|
|
279
|
+
@click.option(
|
|
280
|
+
"--time", "restore_time", type=str, default=None, help="Restore to specific time"
|
|
281
|
+
)
|
|
282
|
+
@click.option("--passphrase", type=str, default="", help="Encryption passphrase")
|
|
283
|
+
def restore(
|
|
284
|
+
url: str,
|
|
285
|
+
volume: str | None,
|
|
286
|
+
input_uri: str,
|
|
287
|
+
s3_endpoint: str | None,
|
|
288
|
+
endpoint_id: int,
|
|
289
|
+
version: int | None,
|
|
290
|
+
restore_time: str | None,
|
|
291
|
+
passphrase: str,
|
|
292
|
+
):
|
|
293
|
+
"""Restore Docker volumes from S3 using Duplicati."""
|
|
294
|
+
access_token = os.environ.get("PORTAINER_ACCESS_TOKEN")
|
|
295
|
+
if not access_token:
|
|
296
|
+
click.echo("Error: Missing PORTAINER_ACCESS_TOKEN", err=True)
|
|
297
|
+
sys.exit(1)
|
|
298
|
+
|
|
299
|
+
try:
|
|
300
|
+
s3_access_key, s3_secret_key = get_s3_credentials()
|
|
301
|
+
except click.ClickException as e:
|
|
302
|
+
click.echo(f"Error: {e.message}", err=True)
|
|
303
|
+
sys.exit(1)
|
|
304
|
+
|
|
305
|
+
# Parse S3 URI
|
|
306
|
+
try:
|
|
307
|
+
uri_endpoint, s3_bucket, uri_path = parse_s3_uri(input_uri)
|
|
308
|
+
endpoint = get_s3_endpoint(uri_endpoint, s3_endpoint)
|
|
309
|
+
except click.ClickException as e:
|
|
310
|
+
click.echo(f"Error: {e.message}", err=True)
|
|
311
|
+
sys.exit(1)
|
|
312
|
+
|
|
313
|
+
# Get s3_path from URI (use as-is)
|
|
314
|
+
s3_path = uri_path.strip("/") if uri_path else ""
|
|
315
|
+
|
|
316
|
+
# Determine volume name: 1) from --volume arg, 2) from s3_path
|
|
317
|
+
if volume:
|
|
318
|
+
volume_name = volume
|
|
319
|
+
elif s3_path:
|
|
320
|
+
# Use the first path segment as volume name
|
|
321
|
+
volume_name = s3_path.split("/")[0]
|
|
322
|
+
else:
|
|
323
|
+
click.echo("Error: No volume specified. Use --volume or include path in input URI", err=True)
|
|
324
|
+
sys.exit(1)
|
|
325
|
+
|
|
326
|
+
passphrase = passphrase or os.environ.get("DUPLICATI_PASSPHRASE", "")
|
|
327
|
+
portainer_url = url.rstrip("/")
|
|
328
|
+
|
|
329
|
+
click.echo(f"Portainer URL: {portainer_url}")
|
|
330
|
+
click.echo(f"S3 Endpoint: {endpoint}")
|
|
331
|
+
click.echo(f"S3 Bucket: {s3_bucket}")
|
|
332
|
+
click.echo(f"S3 Path: {s3_path}")
|
|
333
|
+
click.echo(f"Volume: {volume_name}")
|
|
334
|
+
click.echo(f"Encryption: {'Enabled' if passphrase else 'Disabled'}")
|
|
335
|
+
if version is not None:
|
|
336
|
+
click.echo(f"Version: {version}")
|
|
337
|
+
if restore_time:
|
|
338
|
+
click.echo(f"Time: {restore_time}")
|
|
339
|
+
click.echo()
|
|
340
|
+
click.echo("=== Restoring volumes with Duplicati ===")
|
|
341
|
+
|
|
342
|
+
success = restore_volume(
|
|
343
|
+
portainer_url,
|
|
344
|
+
access_token,
|
|
345
|
+
endpoint_id,
|
|
346
|
+
volume_name,
|
|
347
|
+
endpoint,
|
|
348
|
+
s3_bucket,
|
|
349
|
+
s3_path,
|
|
350
|
+
s3_access_key,
|
|
351
|
+
s3_secret_key,
|
|
352
|
+
passphrase,
|
|
353
|
+
version,
|
|
354
|
+
restore_time,
|
|
355
|
+
)
|
|
356
|
+
|
|
357
|
+
click.echo()
|
|
358
|
+
click.echo("=== Volume restore complete ===")
|
|
359
|
+
sys.exit(0 if success else 1)
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ptctools
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Portainer Client Tools - CLI for managing Portainer from client
|
|
5
|
+
License-File: LICENSE
|
|
6
|
+
Requires-Python: >=3.10
|
|
7
|
+
Requires-Dist: click>=8.0
|
|
8
|
+
Provides-Extra: dev
|
|
9
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
|
|
12
|
+
# ptctools - Portainer Client Tools
|
|
13
|
+
|
|
14
|
+
CLI for managing Portainer stacks, volume backups, and database operations.
|
|
15
|
+
|
|
16
|
+
> **Note:** Only tested on Portainer 2.33.6
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
# From Git repository
|
|
22
|
+
uv tool install git+https://github.com/tamntlib/ptctools.git
|
|
23
|
+
# or
|
|
24
|
+
uv tool install ptctools --from git+https://github.com/tamntlib/ptctools.git
|
|
25
|
+
|
|
26
|
+
# From local path
|
|
27
|
+
uv tool install . --no-cache --reinstall
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Usage
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
export PORTAINER_URL=https://portainer.example.com
|
|
34
|
+
export PORTAINER_ACCESS_TOKEN=your-api-key
|
|
35
|
+
export S3_ACCESS_KEY=your-s3-key
|
|
36
|
+
export S3_SECRET_KEY=your-s3-secret
|
|
37
|
+
export S3_ENDPOINT=https://s3.<region>.amazonaws.com
|
|
38
|
+
|
|
39
|
+
# Stack deployment
|
|
40
|
+
ptctools stack deploy -u $PORTAINER_URL -n mystack -f compose.yaml
|
|
41
|
+
|
|
42
|
+
# Volume backup/restore (uses Duplicati)
|
|
43
|
+
ptctools volume backup -u $PORTAINER_URL -v vol1,vol2 -o s3://mybucket
|
|
44
|
+
ptctools volume restore -u $PORTAINER_URL -i s3://mybucket/vol1 # volume name derived from URI path
|
|
45
|
+
ptctools volume restore -u $PORTAINER_URL -v vol1 -i s3://mybucket/vol1 # explicit volume name
|
|
46
|
+
|
|
47
|
+
# Database backup/restore (uses minio/mc for S3)
|
|
48
|
+
ptctools db backup -u $PORTAINER_URL -c container_id -v db_data \
|
|
49
|
+
--db-user postgres --db-name mydb -o backup.sql.gz
|
|
50
|
+
ptctools db backup -u $PORTAINER_URL -c container_id -v db_data \
|
|
51
|
+
--db-user postgres --db-name mydb -o s3://mybucket/backups/db.sql.gz
|
|
52
|
+
|
|
53
|
+
ptctools db restore -u $PORTAINER_URL -c container_id -v db_data \
|
|
54
|
+
--db-user postgres --db-name mydb -i backup.sql.gz
|
|
55
|
+
ptctools db restore -u $PORTAINER_URL -c container_id -v db_data \
|
|
56
|
+
--db-user postgres --db-name mydb -i s3://mybucket/backups/db.sql.gz
|
|
57
|
+
|
|
58
|
+
# Config management
|
|
59
|
+
# Create config from inline data
|
|
60
|
+
ptctools config set -u $PORTAINER_URL -n my-config -d "config content"
|
|
61
|
+
ptctools config set -u $PORTAINER_URL -n nginx.conf -f ./nginx.conf
|
|
62
|
+
ptctools config set -u $PORTAINER_URL -n my-config -d "new content" --force
|
|
63
|
+
ptctools config list -u $PORTAINER_URL
|
|
64
|
+
ptctools config get -u $PORTAINER_URL -n my-config
|
|
65
|
+
ptctools config delete -u $PORTAINER_URL -n my-config
|
|
66
|
+
|
|
67
|
+
# Utils - local Duplicati operations
|
|
68
|
+
ptctools utils backup --input ./data --output s3://backups/mydata
|
|
69
|
+
ptctools utils restore --input s3://backups/mydata --output ./restored
|
|
70
|
+
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Environment Variables
|
|
74
|
+
|
|
75
|
+
- `PORTAINER_ACCESS_TOKEN` - Portainer API key (required)
|
|
76
|
+
- `S3_ACCESS_KEY` / `S3_SECRET_KEY` - S3 credentials (for backup commands)
|
|
77
|
+
- `S3_ENDPOINT` - S3/MinIO endpoint URL
|
|
78
|
+
- `DUPLICATI_PASSPHRASE` - Backup encryption passphrase (optional, for volume backups)
|
|
79
|
+
|
|
80
|
+
## Commands
|
|
81
|
+
|
|
82
|
+
### `ptctools stack deploy`
|
|
83
|
+
Deploy or update a Docker stack in Portainer.
|
|
84
|
+
|
|
85
|
+
### `ptctools volume backup/restore`
|
|
86
|
+
|
|
87
|
+
- **backup**: Backup multiple Docker volumes (comma-separated) to S3 using Duplicati container.
|
|
88
|
+
- **restore**: Restore a single Docker volume from S3. Volume name can be specified via `--volume` or derived from the input URI path.
|
|
89
|
+
|
|
90
|
+
### `ptctools db backup/restore`
|
|
91
|
+
Backup/restore PostgreSQL database. Supports both local files and S3 URIs.
|
|
92
|
+
- Uses `pg_dump`/`psql` for database operations
|
|
93
|
+
- Uses `minio/mc` container for S3 transfers
|
|
94
|
+
|
|
95
|
+
### `ptctools utils backup/restore`
|
|
96
|
+
Local backup/restore operations using Duplicati CLI (docker or local).
|
|
97
|
+
|
|
98
|
+
### `ptctools config set/get/list/delete`
|
|
99
|
+
Manage Docker Swarm configs via Portainer API.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
ptctools/__init__.py,sha256=n6cNddgYO7DUEyRXP2RqlCihEO8q3H4UNEDJTZeLcJQ,101
|
|
2
|
+
ptctools/_portainer.py,sha256=6bhDvEvAnjnqkwmx6SS7J2bGoWXnx9PtowYVgJgMRCk,8874
|
|
3
|
+
ptctools/_s3.py,sha256=fOz53Y3X6O9XiFbWhb_qY-xHXjf9OBuoWJl--0nXklc,4974
|
|
4
|
+
ptctools/cli.py,sha256=PHyJPIW9SxZ1ZXhwy3kkYbeVVR-qQ6Hopk7ZyeLQxTc,628
|
|
5
|
+
ptctools/config.py,sha256=ePCNT9oRPnTgU3CNYBfIhebpZeNq3SwVRcw6RttVCRo,9142
|
|
6
|
+
ptctools/db.py,sha256=gfoIssSJI7blq9flzadGiQ-p8qI2TlzdJANlZvVqT4o,17548
|
|
7
|
+
ptctools/stack.py,sha256=N3FmH9Ub1vBb4w5jzMeRpGgoWOE8hJVoqF-A2VZvSxc,12012
|
|
8
|
+
ptctools/utils.py,sha256=xlTueqZCVUDPpo8I-tDhy7zmtPhG_EnN4fb7mwhnFIs,12970
|
|
9
|
+
ptctools/volume.py,sha256=gvqFb2gHdJc6DA_1_0RuzgvKbsXlZPoy6Lsu94779E0,10794
|
|
10
|
+
ptctools-0.1.0.dist-info/METADATA,sha256=ikauX05NbofOLwPyFCEG7Z_-jFhDdA2hIcprefr7z7c,3549
|
|
11
|
+
ptctools-0.1.0.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
12
|
+
ptctools-0.1.0.dist-info/entry_points.txt,sha256=JkiFaKgNdfAR9eL3E8g72rJg6bxTlNzRUdjRp_N6YpY,47
|
|
13
|
+
ptctools-0.1.0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
14
|
+
ptctools-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,201 @@
|
|
|
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
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|