bdbackup 0.7.0__tar.gz → 0.7.2__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.
- {bdbackup-0.7.0 → bdbackup-0.7.2}/PKG-INFO +32 -14
- {bdbackup-0.7.0 → bdbackup-0.7.2}/README.md +31 -13
- {bdbackup-0.7.0 → bdbackup-0.7.2}/bdbackup/backends.py +1 -0
- {bdbackup-0.7.0 → bdbackup-0.7.2}/bdbackup/cli.py +75 -7
- {bdbackup-0.7.0 → bdbackup-0.7.2}/bdbackup/config.py +79 -1
- {bdbackup-0.7.0 → bdbackup-0.7.2}/bdbackup/engines.py +1 -0
- {bdbackup-0.7.0 → bdbackup-0.7.2}/bdbackup/gfs/actions.py +24 -4
- {bdbackup-0.7.0 → bdbackup-0.7.2}/bdbackup/gfs/runner.py +9 -2
- {bdbackup-0.7.0 → bdbackup-0.7.2}/bdbackup/gfs/stages.py +28 -1
- {bdbackup-0.7.0 → bdbackup-0.7.2}/bdbackup/gfs/structure.py +3 -2
- {bdbackup-0.7.0 → bdbackup-0.7.2}/bdbackup/history.py +1 -1
- bdbackup-0.7.2/bdbackup/postgres/__init__.py +22 -0
- bdbackup-0.7.2/bdbackup/postgres/pgbackrest.py +536 -0
- bdbackup-0.7.2/bdbackup/postgres/repository.py +238 -0
- bdbackup-0.7.2/bdbackup/postgres/restore.py +160 -0
- {bdbackup-0.7.0 → bdbackup-0.7.2}/bdbackup/recovery.py +2 -2
- {bdbackup-0.7.0 → bdbackup-0.7.2}/bdbackup/validation.py +10 -4
- {bdbackup-0.7.0 → bdbackup-0.7.2}/config.toml.example +81 -9
- bdbackup-0.7.2/contrib/systemd/bdbackup-incremental@.service +11 -0
- bdbackup-0.7.2/contrib/systemd/bdbackup-incremental@.timer +10 -0
- bdbackup-0.7.2/contrib/systemd/bdbackup@.service +11 -0
- bdbackup-0.7.2/contrib/systemd/bdbackup@.timer +10 -0
- {bdbackup-0.7.0 → bdbackup-0.7.2}/docs/README_ENGINES.md +4 -3
- {bdbackup-0.7.0 → bdbackup-0.7.2}/docs/README_FILE.md +4 -0
- {bdbackup-0.7.0 → bdbackup-0.7.2}/docs/README_GFS.md +54 -4
- bdbackup-0.7.2/docs/README_PGBACKREST.md +466 -0
- bdbackup-0.7.2/docs/README_SYSTEMD.md +138 -0
- {bdbackup-0.7.0 → bdbackup-0.7.2}/docs/README_XTRABACKUP.md +6 -0
- {bdbackup-0.7.0 → bdbackup-0.7.2}/pyproject.toml +2 -1
- bdbackup-0.7.2/scripts/docker/pgbackrest.Dockerfile +28 -0
- bdbackup-0.7.2/scripts/integration_pgbackrest.py +747 -0
- {bdbackup-0.7.0 → bdbackup-0.7.2}/tests/AGENTS.md +23 -10
- bdbackup-0.7.2/tests/pgbackrest_fake.py +198 -0
- {bdbackup-0.7.0 → bdbackup-0.7.2}/tests/test_cli_reshape.py +26 -0
- {bdbackup-0.7.0 → bdbackup-0.7.2}/tests/test_engines.py +5 -2
- {bdbackup-0.7.0 → bdbackup-0.7.2}/tests/test_gfs_init.py +36 -2
- {bdbackup-0.7.0 → bdbackup-0.7.2}/tests/test_gfs_run.py +100 -0
- {bdbackup-0.7.0 → bdbackup-0.7.2}/tests/test_history.py +26 -0
- bdbackup-0.7.2/tests/test_pgbackrest_cli.py +444 -0
- bdbackup-0.7.2/tests/test_pgbackrest_engine.py +1129 -0
- bdbackup-0.7.2/tests/test_pgbackrest_export.py +519 -0
- bdbackup-0.7.2/tests/test_pgbackrest_repository.py +488 -0
- bdbackup-0.7.2/tests/test_pgbackrest_restore.py +487 -0
- bdbackup-0.7.2/tests/test_systemd_units.py +111 -0
- {bdbackup-0.7.0 → bdbackup-0.7.2}/.gitignore +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.2}/LICENSE +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.2}/bdbackup/__init__.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.2}/bdbackup/filebackup.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.2}/bdbackup/gfs/__init__.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.2}/bdbackup/gfs/policy.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.2}/bdbackup/gfs/store.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.2}/bdbackup/ledger.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.2}/bdbackup/mysql/__init__.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.2}/bdbackup/mysql/helpers.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.2}/bdbackup/mysql/mysqldump.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.2}/bdbackup/mysql/xtrabackup.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.2}/bdbackup/templates/__init__.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.2}/bdbackup/templates/_matching.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.2}/bdbackup/templates/python_dev.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.2}/bdbackup/utils.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.2}/docs/README_MYSQLDUMP.md +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.2}/scripts/check_release.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.2}/scripts/integration_mysql.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.2}/scripts/integration_physical.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.2}/scripts/smoke_install.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.2}/template.txt +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.2}/tests/__init__.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.2}/tests/conftest.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.2}/tests/test_architecture.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.2}/tests/test_correctness.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.2}/tests/test_encryption.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.2}/tests/test_engine_conditions.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.2}/tests/test_gfs_config.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.2}/tests/test_gfs_policy.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.2}/tests/test_gfs_store.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.2}/tests/test_helpers.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.2}/tests/test_import.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.2}/tests/test_ledger.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.2}/tests/test_performance.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.2}/tests/test_release_fixes.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.2}/tests/test_run_selector.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.2}/tests/test_safety_nets.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.2}/tests/test_security.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.2}/tests/test_templates.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: bdbackup
|
|
3
|
-
Version: 0.7.
|
|
3
|
+
Version: 0.7.2
|
|
4
4
|
Summary: MySQL, MariaDB and file backups with mysqldump, Percona XtraBackup, MariaDB Backup and tar: verification, GFS rotation and guided restore
|
|
5
5
|
Project-URL: Homepage, https://github.com/ayder/bdbackup
|
|
6
6
|
Project-URL: Repository, https://github.com/ayder/bdbackup
|
|
@@ -36,12 +36,13 @@ Description-Content-Type: text/markdown
|
|
|
36
36
|
|
|
37
37
|
**Backups by design.**
|
|
38
38
|
|
|
39
|
-
bdbackup is a command-line backup tool and Python library for MySQL, MariaDB
|
|
40
|
-
files on Linux and macOS. It takes MySQL and MariaDB
|
|
41
|
-
Percona XtraBackup and MariaDB Backup (full and
|
|
42
|
-
compressed and optionally encrypted),
|
|
43
|
-
tar.gz or tar.zst, and
|
|
44
|
-
|
|
39
|
+
bdbackup is a command-line backup tool and Python library for MySQL, MariaDB,
|
|
40
|
+
PostgreSQL (pgBackRest) and files on Linux and macOS. It takes MySQL and MariaDB
|
|
41
|
+
backups with mysqldump, Percona XtraBackup and MariaDB Backup (full and
|
|
42
|
+
incremental physical backups, compressed and optionally encrypted), exports
|
|
43
|
+
pgBackRest fulls, archives files and directories as tar, tar.gz or tar.zst, and
|
|
44
|
+
rotates the results across storage stages with GFS (grandfather-father-son)
|
|
45
|
+
retention. Every backup is verified before it is
|
|
45
46
|
published and recorded with a SHA-256 checksum in an SQLite backup history, from
|
|
46
47
|
which a guided restore prepares a recovery copy. Jobs live in one TOML file and
|
|
47
48
|
run from cron.
|
|
@@ -53,6 +54,8 @@ run from cron.
|
|
|
53
54
|
encrypted with Percona, prepared for recovery with `restore --backup`.
|
|
54
55
|
- [MySQL and MariaDB logical backups](https://github.com/ayder/bdbackup/blob/master/docs/README_MYSQLDUMP.md) with mysqldump,
|
|
55
56
|
gzip-compressed, one database or all.
|
|
57
|
+
- [PostgreSQL pgBackRest backups](https://github.com/ayder/bdbackup/blob/master/docs/README_PGBACKREST.md): the newest
|
|
58
|
+
full of a stanza exported as one tar into a GFS stage, restorable on its own.
|
|
56
59
|
- [File and directory backups](https://github.com/ayder/bdbackup/blob/master/docs/README_FILE.md) as tar archives, with
|
|
57
60
|
gitignore-style exclusion templates.
|
|
58
61
|
- [GFS (grandfather-father-son) backup rotation](https://github.com/ayder/bdbackup/blob/master/docs/README_GFS.md): daily,
|
|
@@ -71,8 +74,10 @@ run from cron.
|
|
|
71
74
|
| [File and directory backups with tar](https://github.com/ayder/bdbackup/blob/master/docs/README_FILE.md) | file jobs, template files, exclusion templates, restoring an archive |
|
|
72
75
|
| [MySQL and MariaDB logical backups with mysqldump](https://github.com/ayder/bdbackup/blob/master/docs/README_MYSQLDUMP.md) | mysqldump jobs, credentials, default options |
|
|
73
76
|
| [MySQL and MariaDB physical backups with Percona XtraBackup and MariaDB Backup](https://github.com/ayder/bdbackup/blob/master/docs/README_XTRABACKUP.md) | xtrabackup jobs, full and incremental backups, encryption, preparing a recovery copy, engine pruning |
|
|
77
|
+
| [PostgreSQL pgBackRest backups: nightly fulls exported to a GFS stage](https://github.com/ayder/bdbackup/blob/master/docs/README_PGBACKREST.md) | pgbackrest jobs, taking fulls with archive-copy, the first stage, no new full and `max_full_age_hours`, restore and the printed pgBackRest command, the repository host lost, known limits |
|
|
74
78
|
| [GFS (grandfather-father-son) backup rotation](https://github.com/ayder/bdbackup/blob/master/docs/README_GFS.md) | stages, preparing stage directories, safety rules, run and step logs, ledger copies |
|
|
75
79
|
| [Custom backup engines (plugins)](https://github.com/ayder/bdbackup/blob/master/docs/README_ENGINES.md) | the engine registry and writing your own engine |
|
|
80
|
+
| [Running xtrabackup jobs with systemd timers](https://github.com/ayder/bdbackup/blob/master/docs/README_SYSTEMD.md) | service and timer templates, the mysql account, schedules, CPU, I/O and memory limits |
|
|
76
81
|
| [Annotated configuration](https://github.com/ayder/bdbackup/blob/master/config.toml.example) | every config key with a comment |
|
|
77
82
|
|
|
78
83
|
## Support and safety
|
|
@@ -142,7 +147,7 @@ The CLI uses these exit codes:
|
|
|
142
147
|
| Code | Meaning |
|
|
143
148
|
|------|---------|
|
|
144
149
|
| 0 | Success |
|
|
145
|
-
| 1 | Backup/verify failure (including a job whose backend rejects its settings in a real run), or validation checks failed/incomplete |
|
|
150
|
+
| 1 | Backup/verify failure (including a job whose backend rejects its settings in a real run, except a pgbackrest job: exit 2), or validation checks failed/incomplete |
|
|
146
151
|
| 2 | Usage error, an inactive job, or a configuration error found when the config loads or by `--dry-run` |
|
|
147
152
|
| 3 | Lock held; for GFS, another run of the job is in progress or only deferred work remains |
|
|
148
153
|
|
|
@@ -203,10 +208,12 @@ An xtrabackup job also takes `--incremental`; see
|
|
|
203
208
|
|
|
204
209
|
`--dry-run` reports what a job would do: it runs no backup tool, writes no
|
|
205
210
|
backup and records no history; a GFS dry run creates only its job's lock file
|
|
206
|
-
beside the history database.
|
|
211
|
+
beside the history database. The one exception is a pgbackrest job, which runs
|
|
212
|
+
the read-only `pgbackrest info`. What each job type reports is described with it:
|
|
207
213
|
[file jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_FILE.md#dry-run),
|
|
208
214
|
[mysqldump jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_MYSQLDUMP.md#dry-run),
|
|
209
|
-
[xtrabackup jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_XTRABACKUP.md#dry-run)
|
|
215
|
+
[xtrabackup jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_XTRABACKUP.md#dry-run),
|
|
216
|
+
[pgbackrest jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_PGBACKREST.md#dry-run-and-validation) and
|
|
210
217
|
[GFS jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_GFS.md#dry-run).
|
|
211
218
|
|
|
212
219
|
A dry run exits 1 where the real run would fail before writing anything (an
|
|
@@ -239,6 +246,10 @@ Times use the cron daemon's timezone, and separate lines do not wait for each
|
|
|
239
246
|
other: leave enough time for backups before GFS. Add `--dry-run` to the GFS line
|
|
240
247
|
until its report looks right.
|
|
241
248
|
|
|
249
|
+
xtrabackup jobs can run from systemd timers instead, which also stop the backup
|
|
250
|
+
tool if bdbackup dies and add per-job limits: see
|
|
251
|
+
[Running xtrabackup jobs with systemd timers](https://github.com/ayder/bdbackup/blob/master/docs/README_SYSTEMD.md).
|
|
252
|
+
|
|
242
253
|
### Validate configuration and permissions
|
|
243
254
|
|
|
244
255
|
Check all configured jobs without creating a backup or running retention:
|
|
@@ -280,7 +291,8 @@ Checks cover direct grants; role-derived privileges and partial revokes may need
|
|
|
280
291
|
manual review. Physical datadir checks cover root-directory access, not every data
|
|
281
292
|
file or external tablespace. Custom mysqldump options, routine visibility, GTID
|
|
282
293
|
settings and exact server/binary version compatibility still need review.
|
|
283
|
-
For a GFS job, every stage path after the first
|
|
294
|
+
For a GFS job, every stage path after the first (and the first, when a pgbackrest
|
|
295
|
+
job writes into it) must exist and be writable, and
|
|
284
296
|
its `.bdbackup-destination` marker must be present and writable; a missing
|
|
285
297
|
marker's line names the `--initialize-structure` command that creates it.
|
|
286
298
|
An unreachable database or missing client is a failed/incomplete check, not a pass.
|
|
@@ -391,7 +403,8 @@ bdbackup restore -c config.toml --backup-id 12 --dst /restore/job-12 --yes
|
|
|
391
403
|
What a restore produces depends on the job type; see
|
|
392
404
|
[file jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_FILE.md#history-restore),
|
|
393
405
|
[mysqldump jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_MYSQLDUMP.md#history-restore),
|
|
394
|
-
[xtrabackup jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_XTRABACKUP.md#history-restore)
|
|
406
|
+
[xtrabackup jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_XTRABACKUP.md#history-restore),
|
|
407
|
+
[pgbackrest jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_PGBACKREST.md#restore) and
|
|
395
408
|
[custom engines](https://github.com/ayder/bdbackup/blob/master/docs/README_ENGINES.md#history-restore).
|
|
396
409
|
|
|
397
410
|
Deleted artifacts remain in history as unavailable. File identity, size, and
|
|
@@ -413,16 +426,21 @@ ruff check bdbackup tests scripts
|
|
|
413
426
|
```
|
|
414
427
|
|
|
415
428
|
Optional database integration tests use disposable, network-isolated Docker
|
|
416
|
-
containers with synthetic data. They remove only the containers and
|
|
417
|
-
created for that run. Pull the matching images before running:
|
|
429
|
+
containers with synthetic data. They remove only the containers, volumes and
|
|
430
|
+
networks created for that run. Pull the matching images before running:
|
|
418
431
|
|
|
419
432
|
```bash
|
|
420
433
|
python scripts/integration_mysql.py # mysql:8.4
|
|
421
434
|
python scripts/integration_physical.py percona # percona-server/xtrabackup:8.4
|
|
422
435
|
python scripts/integration_physical.py percona-encrypted # AES256 + zstd recovery
|
|
423
436
|
python scripts/integration_physical.py mariadb # mariadb:11.4
|
|
437
|
+
python scripts/integration_pgbackrest.py pg16-2.58 # bdbackup-pgbackrest:16-2.58.0
|
|
438
|
+
python scripts/integration_pgbackrest.py pg18-2.60 # bdbackup-pgbackrest:18-2.60.0
|
|
424
439
|
```
|
|
425
440
|
|
|
441
|
+
The pgBackRest images have no official source; build them from
|
|
442
|
+
`scripts/docker/pgbackrest.Dockerfile` with the commands in `tests/AGENTS.md`.
|
|
443
|
+
|
|
426
444
|
Physical recovery returns a prepared data directory; copying it into a server's
|
|
427
445
|
data directory, assigning ownership to the server user, and starting that server
|
|
428
446
|
are separate administrator actions. Use the same database version and
|
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
**Backups by design.**
|
|
4
4
|
|
|
5
|
-
bdbackup is a command-line backup tool and Python library for MySQL, MariaDB
|
|
6
|
-
files on Linux and macOS. It takes MySQL and MariaDB
|
|
7
|
-
Percona XtraBackup and MariaDB Backup (full and
|
|
8
|
-
compressed and optionally encrypted),
|
|
9
|
-
tar.gz or tar.zst, and
|
|
10
|
-
|
|
5
|
+
bdbackup is a command-line backup tool and Python library for MySQL, MariaDB,
|
|
6
|
+
PostgreSQL (pgBackRest) and files on Linux and macOS. It takes MySQL and MariaDB
|
|
7
|
+
backups with mysqldump, Percona XtraBackup and MariaDB Backup (full and
|
|
8
|
+
incremental physical backups, compressed and optionally encrypted), exports
|
|
9
|
+
pgBackRest fulls, archives files and directories as tar, tar.gz or tar.zst, and
|
|
10
|
+
rotates the results across storage stages with GFS (grandfather-father-son)
|
|
11
|
+
retention. Every backup is verified before it is
|
|
11
12
|
published and recorded with a SHA-256 checksum in an SQLite backup history, from
|
|
12
13
|
which a guided restore prepares a recovery copy. Jobs live in one TOML file and
|
|
13
14
|
run from cron.
|
|
@@ -19,6 +20,8 @@ run from cron.
|
|
|
19
20
|
encrypted with Percona, prepared for recovery with `restore --backup`.
|
|
20
21
|
- [MySQL and MariaDB logical backups](https://github.com/ayder/bdbackup/blob/master/docs/README_MYSQLDUMP.md) with mysqldump,
|
|
21
22
|
gzip-compressed, one database or all.
|
|
23
|
+
- [PostgreSQL pgBackRest backups](https://github.com/ayder/bdbackup/blob/master/docs/README_PGBACKREST.md): the newest
|
|
24
|
+
full of a stanza exported as one tar into a GFS stage, restorable on its own.
|
|
22
25
|
- [File and directory backups](https://github.com/ayder/bdbackup/blob/master/docs/README_FILE.md) as tar archives, with
|
|
23
26
|
gitignore-style exclusion templates.
|
|
24
27
|
- [GFS (grandfather-father-son) backup rotation](https://github.com/ayder/bdbackup/blob/master/docs/README_GFS.md): daily,
|
|
@@ -37,8 +40,10 @@ run from cron.
|
|
|
37
40
|
| [File and directory backups with tar](https://github.com/ayder/bdbackup/blob/master/docs/README_FILE.md) | file jobs, template files, exclusion templates, restoring an archive |
|
|
38
41
|
| [MySQL and MariaDB logical backups with mysqldump](https://github.com/ayder/bdbackup/blob/master/docs/README_MYSQLDUMP.md) | mysqldump jobs, credentials, default options |
|
|
39
42
|
| [MySQL and MariaDB physical backups with Percona XtraBackup and MariaDB Backup](https://github.com/ayder/bdbackup/blob/master/docs/README_XTRABACKUP.md) | xtrabackup jobs, full and incremental backups, encryption, preparing a recovery copy, engine pruning |
|
|
43
|
+
| [PostgreSQL pgBackRest backups: nightly fulls exported to a GFS stage](https://github.com/ayder/bdbackup/blob/master/docs/README_PGBACKREST.md) | pgbackrest jobs, taking fulls with archive-copy, the first stage, no new full and `max_full_age_hours`, restore and the printed pgBackRest command, the repository host lost, known limits |
|
|
40
44
|
| [GFS (grandfather-father-son) backup rotation](https://github.com/ayder/bdbackup/blob/master/docs/README_GFS.md) | stages, preparing stage directories, safety rules, run and step logs, ledger copies |
|
|
41
45
|
| [Custom backup engines (plugins)](https://github.com/ayder/bdbackup/blob/master/docs/README_ENGINES.md) | the engine registry and writing your own engine |
|
|
46
|
+
| [Running xtrabackup jobs with systemd timers](https://github.com/ayder/bdbackup/blob/master/docs/README_SYSTEMD.md) | service and timer templates, the mysql account, schedules, CPU, I/O and memory limits |
|
|
42
47
|
| [Annotated configuration](https://github.com/ayder/bdbackup/blob/master/config.toml.example) | every config key with a comment |
|
|
43
48
|
|
|
44
49
|
## Support and safety
|
|
@@ -108,7 +113,7 @@ The CLI uses these exit codes:
|
|
|
108
113
|
| Code | Meaning |
|
|
109
114
|
|------|---------|
|
|
110
115
|
| 0 | Success |
|
|
111
|
-
| 1 | Backup/verify failure (including a job whose backend rejects its settings in a real run), or validation checks failed/incomplete |
|
|
116
|
+
| 1 | Backup/verify failure (including a job whose backend rejects its settings in a real run, except a pgbackrest job: exit 2), or validation checks failed/incomplete |
|
|
112
117
|
| 2 | Usage error, an inactive job, or a configuration error found when the config loads or by `--dry-run` |
|
|
113
118
|
| 3 | Lock held; for GFS, another run of the job is in progress or only deferred work remains |
|
|
114
119
|
|
|
@@ -169,10 +174,12 @@ An xtrabackup job also takes `--incremental`; see
|
|
|
169
174
|
|
|
170
175
|
`--dry-run` reports what a job would do: it runs no backup tool, writes no
|
|
171
176
|
backup and records no history; a GFS dry run creates only its job's lock file
|
|
172
|
-
beside the history database.
|
|
177
|
+
beside the history database. The one exception is a pgbackrest job, which runs
|
|
178
|
+
the read-only `pgbackrest info`. What each job type reports is described with it:
|
|
173
179
|
[file jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_FILE.md#dry-run),
|
|
174
180
|
[mysqldump jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_MYSQLDUMP.md#dry-run),
|
|
175
|
-
[xtrabackup jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_XTRABACKUP.md#dry-run)
|
|
181
|
+
[xtrabackup jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_XTRABACKUP.md#dry-run),
|
|
182
|
+
[pgbackrest jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_PGBACKREST.md#dry-run-and-validation) and
|
|
176
183
|
[GFS jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_GFS.md#dry-run).
|
|
177
184
|
|
|
178
185
|
A dry run exits 1 where the real run would fail before writing anything (an
|
|
@@ -205,6 +212,10 @@ Times use the cron daemon's timezone, and separate lines do not wait for each
|
|
|
205
212
|
other: leave enough time for backups before GFS. Add `--dry-run` to the GFS line
|
|
206
213
|
until its report looks right.
|
|
207
214
|
|
|
215
|
+
xtrabackup jobs can run from systemd timers instead, which also stop the backup
|
|
216
|
+
tool if bdbackup dies and add per-job limits: see
|
|
217
|
+
[Running xtrabackup jobs with systemd timers](https://github.com/ayder/bdbackup/blob/master/docs/README_SYSTEMD.md).
|
|
218
|
+
|
|
208
219
|
### Validate configuration and permissions
|
|
209
220
|
|
|
210
221
|
Check all configured jobs without creating a backup or running retention:
|
|
@@ -246,7 +257,8 @@ Checks cover direct grants; role-derived privileges and partial revokes may need
|
|
|
246
257
|
manual review. Physical datadir checks cover root-directory access, not every data
|
|
247
258
|
file or external tablespace. Custom mysqldump options, routine visibility, GTID
|
|
248
259
|
settings and exact server/binary version compatibility still need review.
|
|
249
|
-
For a GFS job, every stage path after the first
|
|
260
|
+
For a GFS job, every stage path after the first (and the first, when a pgbackrest
|
|
261
|
+
job writes into it) must exist and be writable, and
|
|
250
262
|
its `.bdbackup-destination` marker must be present and writable; a missing
|
|
251
263
|
marker's line names the `--initialize-structure` command that creates it.
|
|
252
264
|
An unreachable database or missing client is a failed/incomplete check, not a pass.
|
|
@@ -357,7 +369,8 @@ bdbackup restore -c config.toml --backup-id 12 --dst /restore/job-12 --yes
|
|
|
357
369
|
What a restore produces depends on the job type; see
|
|
358
370
|
[file jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_FILE.md#history-restore),
|
|
359
371
|
[mysqldump jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_MYSQLDUMP.md#history-restore),
|
|
360
|
-
[xtrabackup jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_XTRABACKUP.md#history-restore)
|
|
372
|
+
[xtrabackup jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_XTRABACKUP.md#history-restore),
|
|
373
|
+
[pgbackrest jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_PGBACKREST.md#restore) and
|
|
361
374
|
[custom engines](https://github.com/ayder/bdbackup/blob/master/docs/README_ENGINES.md#history-restore).
|
|
362
375
|
|
|
363
376
|
Deleted artifacts remain in history as unavailable. File identity, size, and
|
|
@@ -379,16 +392,21 @@ ruff check bdbackup tests scripts
|
|
|
379
392
|
```
|
|
380
393
|
|
|
381
394
|
Optional database integration tests use disposable, network-isolated Docker
|
|
382
|
-
containers with synthetic data. They remove only the containers and
|
|
383
|
-
created for that run. Pull the matching images before running:
|
|
395
|
+
containers with synthetic data. They remove only the containers, volumes and
|
|
396
|
+
networks created for that run. Pull the matching images before running:
|
|
384
397
|
|
|
385
398
|
```bash
|
|
386
399
|
python scripts/integration_mysql.py # mysql:8.4
|
|
387
400
|
python scripts/integration_physical.py percona # percona-server/xtrabackup:8.4
|
|
388
401
|
python scripts/integration_physical.py percona-encrypted # AES256 + zstd recovery
|
|
389
402
|
python scripts/integration_physical.py mariadb # mariadb:11.4
|
|
403
|
+
python scripts/integration_pgbackrest.py pg16-2.58 # bdbackup-pgbackrest:16-2.58.0
|
|
404
|
+
python scripts/integration_pgbackrest.py pg18-2.60 # bdbackup-pgbackrest:18-2.60.0
|
|
390
405
|
```
|
|
391
406
|
|
|
407
|
+
The pgBackRest images have no official source; build them from
|
|
408
|
+
`scripts/docker/pgbackrest.Dockerfile` with the commands in `tests/AGENTS.md`.
|
|
409
|
+
|
|
392
410
|
Physical recovery returns a prepared data directory; copying it into a server's
|
|
393
411
|
data directory, assigning ownership to the server user, and starting that server
|
|
394
412
|
are separate administrator actions. Use the same database version and
|
|
@@ -5,6 +5,8 @@ from __future__ import annotations
|
|
|
5
5
|
import logging
|
|
6
6
|
import subprocess
|
|
7
7
|
import sys
|
|
8
|
+
from contextlib import nullcontext
|
|
9
|
+
from datetime import UTC, datetime
|
|
8
10
|
from pathlib import Path
|
|
9
11
|
|
|
10
12
|
import click
|
|
@@ -17,10 +19,13 @@ from bdbackup.filebackup import FileBackup
|
|
|
17
19
|
from bdbackup.gfs import runner as gfs_runner
|
|
18
20
|
from bdbackup.gfs import store as gfs_store
|
|
19
21
|
from bdbackup.gfs import structure as gfs_structure
|
|
22
|
+
from bdbackup.gfs.stages import fed_first_stages
|
|
20
23
|
from bdbackup.history import History
|
|
21
24
|
from bdbackup.mysql import MySQLBackup, XtraBackup
|
|
25
|
+
from bdbackup.postgres.restore import describe_unit, restore_lines
|
|
22
26
|
from bdbackup.recovery import backup_restore_info, restore_record, suggested_destination
|
|
23
27
|
from bdbackup.templates import TemplateError
|
|
28
|
+
from bdbackup.utils import process_lock
|
|
24
29
|
from bdbackup.validation import validate_config
|
|
25
30
|
|
|
26
31
|
# Exit-code contract: 0 ok, 1 backup/verify failure, 2 usage (Click's usage error), 3 locked.
|
|
@@ -87,10 +92,18 @@ def _protect_history(backend, config):
|
|
|
87
92
|
backend.exclude.update(excluded)
|
|
88
93
|
|
|
89
94
|
|
|
95
|
+
def _now() -> datetime:
|
|
96
|
+
"""The current time, UTC-aware; a function so tests can set the clock."""
|
|
97
|
+
return datetime.now(UTC)
|
|
98
|
+
|
|
99
|
+
|
|
90
100
|
def _handle_errors(func, *args, **kwargs) -> int:
|
|
91
|
-
"""Wrap a command body in the exit-code contract.
|
|
101
|
+
"""Wrap a command body in the exit-code contract.
|
|
102
|
+
|
|
103
|
+
Returns the body's own exit code when it returns one, else ``EXIT_OK``.
|
|
104
|
+
"""
|
|
92
105
|
try:
|
|
93
|
-
func(*args, **kwargs)
|
|
106
|
+
code = func(*args, **kwargs)
|
|
94
107
|
except (click.ClickException, click.Abort):
|
|
95
108
|
raise
|
|
96
109
|
except BlockingIOError as exc:
|
|
@@ -107,7 +120,7 @@ def _handle_errors(func, *args, **kwargs) -> int:
|
|
|
107
120
|
except Exception as exc: # pragma: no cover - safety net
|
|
108
121
|
logging.getLogger("bdbackup.cli").exception("Unexpected error: %s", exc)
|
|
109
122
|
click.get_current_context().exit(EXIT_BACKUP_FAILED)
|
|
110
|
-
return EXIT_OK
|
|
123
|
+
return code if isinstance(code, int) else EXIT_OK
|
|
111
124
|
|
|
112
125
|
|
|
113
126
|
def _dry_run(config: Config, job: Job, incremental: bool) -> None:
|
|
@@ -128,6 +141,47 @@ def _dry_run(config: Config, job: Job, incremental: bool) -> None:
|
|
|
128
141
|
raise click.UsageError(f"--dry-run is not supported for job type {job.type!r}")
|
|
129
142
|
|
|
130
143
|
|
|
144
|
+
def _run_pgbackrest(config: Config, job: Job, *, verify: bool, dry_run: bool) -> int:
|
|
145
|
+
"""Export the newest pgBackRest full of the job's stanza as one tar; return the exit code.
|
|
146
|
+
|
|
147
|
+
A real run holds the job lock from before the full is chosen until the export is published.
|
|
148
|
+
A dry run takes no lock and writes nothing. When there is no new full nothing is recorded.
|
|
149
|
+
"""
|
|
150
|
+
engine = build_backend(job)
|
|
151
|
+
engine.refuse_root()
|
|
152
|
+
with nullcontext() if dry_run else process_lock(engine.lock_file):
|
|
153
|
+
choice = engine.choose(History(config.history), job.name)
|
|
154
|
+
full = choice.full
|
|
155
|
+
if full.page_errors:
|
|
156
|
+
click.echo(
|
|
157
|
+
f"WARNING: full {full.label} has page checksum errors; it is exported, "
|
|
158
|
+
"and restoring it needs checksum-page-error=n"
|
|
159
|
+
)
|
|
160
|
+
if not choice.new:
|
|
161
|
+
hours = max(0, int((_now() - full.stop).total_seconds() // 3600))
|
|
162
|
+
message = f"no new full: newest {full.label}, {hours} hours old"
|
|
163
|
+
limit = engine.max_full_age_hours
|
|
164
|
+
if limit is not None and hours > limit:
|
|
165
|
+
click.echo(f"{message} (older than max_full_age_hours = {limit})")
|
|
166
|
+
return EXIT_BACKUP_FAILED
|
|
167
|
+
click.echo(message)
|
|
168
|
+
return EXIT_OK
|
|
169
|
+
if dry_run:
|
|
170
|
+
engine.require_marker()
|
|
171
|
+
click.echo(
|
|
172
|
+
f"Dry run; would export {full.label} ({full.repo_bytes} bytes) "
|
|
173
|
+
f"of stanza {engine.stanza} to {engine.unit_path(full.label)}"
|
|
174
|
+
)
|
|
175
|
+
return EXIT_OK
|
|
176
|
+
|
|
177
|
+
info = engine.restore_info(full, engine.version())
|
|
178
|
+
result = _tracked_backup(
|
|
179
|
+
config, job.name, "pgbackrest-full", lambda: engine.export(full, verify=verify), info
|
|
180
|
+
)
|
|
181
|
+
click.echo(f"Job {job.name}: {result.path}")
|
|
182
|
+
return EXIT_OK
|
|
183
|
+
|
|
184
|
+
|
|
131
185
|
@main.command(name="run")
|
|
132
186
|
@config_option(required=True)
|
|
133
187
|
@click.option("-j", "--job", "job_name", help="Run this configured job.")
|
|
@@ -141,7 +195,7 @@ def _dry_run(config: Config, job: Job, incremental: bool) -> None:
|
|
|
141
195
|
help="Verify the backup after creation.",
|
|
142
196
|
)
|
|
143
197
|
@click.option("--dry-run", is_flag=True,
|
|
144
|
-
help="Report what the job would do; run no tool and change nothing.")
|
|
198
|
+
help="Report what the job would do; run no backup tool and change nothing.")
|
|
145
199
|
@click.option("--validate", "validate_only", is_flag=True,
|
|
146
200
|
help="Check settings, filesystem access and MySQL grants of every job, or of "
|
|
147
201
|
"--job; run nothing.")
|
|
@@ -191,7 +245,8 @@ def run(
|
|
|
191
245
|
if initialize:
|
|
192
246
|
if job.type != "gfs":
|
|
193
247
|
raise click.UsageError(f"--initialize-structure applies only to gfs jobs: {job.name}")
|
|
194
|
-
|
|
248
|
+
fed = job.params["stage"][0].paths[0] in fed_first_stages(config.jobs)
|
|
249
|
+
ctx.exit(gfs_structure.initialize(job, click.echo, fed))
|
|
195
250
|
if validate_only:
|
|
196
251
|
jobs = [job] if job else list(config.jobs.values())
|
|
197
252
|
if not jobs:
|
|
@@ -208,6 +263,8 @@ def run(
|
|
|
208
263
|
if job.type == "gfs":
|
|
209
264
|
code = gfs_runner.run_job(config, job, out=click.echo, dry_run=dry_run)
|
|
210
265
|
ctx.exit(code if code in (EXIT_OK, EXIT_LOCKED) else EXIT_BACKUP_FAILED)
|
|
266
|
+
if job.type == "pgbackrest":
|
|
267
|
+
ctx.exit(_handle_errors(_run_pgbackrest, config, job, verify=verify, dry_run=dry_run))
|
|
211
268
|
if dry_run:
|
|
212
269
|
return _handle_errors(_dry_run, config, job, incremental)
|
|
213
270
|
info = {}
|
|
@@ -270,6 +327,14 @@ def _restore_mode(config_path, backup_id, job, yes, dst, archive, backup, root,
|
|
|
270
327
|
return "archive" if archive is not None else "backup"
|
|
271
328
|
|
|
272
329
|
|
|
330
|
+
def _echo_restore_command(directory: Path) -> None:
|
|
331
|
+
"""Print the pgbackrest restore command if ``directory`` holds an extracted pgBackRest unit."""
|
|
332
|
+
facts = describe_unit(directory)
|
|
333
|
+
if facts is not None:
|
|
334
|
+
for line in restore_lines(facts, directory.expanduser().absolute()):
|
|
335
|
+
click.echo(line)
|
|
336
|
+
|
|
337
|
+
|
|
273
338
|
@main.command()
|
|
274
339
|
@config_option()
|
|
275
340
|
@click.option("--backup-id", type=click.IntRange(min=1), help="Successful backup ID from history.")
|
|
@@ -309,8 +374,9 @@ def restore(
|
|
|
309
374
|
|
|
310
375
|
def _run():
|
|
311
376
|
if mode == "archive":
|
|
312
|
-
FileBackup.restore_archive(archive, dst)
|
|
313
|
-
click.echo(f"Restored to: {
|
|
377
|
+
restored = FileBackup.restore_archive(archive, dst)
|
|
378
|
+
click.echo(f"Restored to: {restored}")
|
|
379
|
+
_echo_restore_command(restored)
|
|
314
380
|
return
|
|
315
381
|
if mode == "backup":
|
|
316
382
|
xb = XtraBackup(backup_root=root, binary=binary or "xtrabackup",
|
|
@@ -382,6 +448,8 @@ def restore(
|
|
|
382
448
|
click.echo(f"Prepared recovery directory: {restored}")
|
|
383
449
|
else:
|
|
384
450
|
click.echo(f"Restored to: {restored}")
|
|
451
|
+
if record.backup_type == "pgbackrest-full":
|
|
452
|
+
_echo_restore_command(restored)
|
|
385
453
|
|
|
386
454
|
return _handle_errors(_run)
|
|
387
455
|
|
|
@@ -9,7 +9,7 @@ from typing import Any
|
|
|
9
9
|
|
|
10
10
|
from bdbackup.engines import EngineError, get_engine, list_engines
|
|
11
11
|
from bdbackup.filebackup import FileBackup
|
|
12
|
-
from bdbackup.gfs.stages import check_gfs_config, parse_gfs_job
|
|
12
|
+
from bdbackup.gfs.stages import check_gfs_config, parse_gfs_job, pgbackrest_first_stage
|
|
13
13
|
from bdbackup.history import HistorySettings
|
|
14
14
|
|
|
15
15
|
|
|
@@ -108,6 +108,8 @@ class Config:
|
|
|
108
108
|
"out_dir",
|
|
109
109
|
"backup_root",
|
|
110
110
|
"encrypt_key_file",
|
|
111
|
+
"repo_path",
|
|
112
|
+
"config_file",
|
|
111
113
|
):
|
|
112
114
|
if key in params:
|
|
113
115
|
try:
|
|
@@ -124,6 +126,82 @@ class Config:
|
|
|
124
126
|
check_gfs_config(self.jobs, self.history)
|
|
125
127
|
except ValueError as exc:
|
|
126
128
|
raise ConfigError(str(exc)) from exc
|
|
129
|
+
self._check_pgbackrest()
|
|
130
|
+
|
|
131
|
+
def _check_pgbackrest(self) -> None:
|
|
132
|
+
"""Rules for pgbackrest jobs; they follow ``check_gfs_config``, which reads the stages."""
|
|
133
|
+
for name, job in self.jobs.items():
|
|
134
|
+
if job.type != "pgbackrest":
|
|
135
|
+
continue
|
|
136
|
+
if self.history is None:
|
|
137
|
+
raise ConfigError(f"Job {name!r}: pgbackrest jobs require a [history] section")
|
|
138
|
+
for key in ("first_stage", "lock_file"):
|
|
139
|
+
if key in job.params:
|
|
140
|
+
raise ConfigError(f"Job {name!r}: {key} is set by bdbackup, not in the config")
|
|
141
|
+
for key, rule in (
|
|
142
|
+
("repo", "a whole number of 1 or more"),
|
|
143
|
+
("max_full_age_hours", "a positive whole number"),
|
|
144
|
+
):
|
|
145
|
+
value = job.params.get(key, 1)
|
|
146
|
+
if isinstance(value, bool) or not isinstance(value, int) or value < 1:
|
|
147
|
+
raise ConfigError(f"Job {name!r}: {key} must be {rule}")
|
|
148
|
+
try:
|
|
149
|
+
job.params["first_stage"] = pgbackrest_first_stage(job, self.jobs)
|
|
150
|
+
except ValueError as exc:
|
|
151
|
+
raise ConfigError(f"Job {name!r}: {exc}") from exc
|
|
152
|
+
self._check_pgbackrest_layout(name, job)
|
|
153
|
+
job.params["lock_file"] = Path(f"{self.history.database}.pgbackrest-{name}.lock")
|
|
154
|
+
self._check_pgbackrest_jobs_apart()
|
|
155
|
+
|
|
156
|
+
def _check_pgbackrest_jobs_apart(self) -> None:
|
|
157
|
+
"""Refuse two pgbackrest jobs that export one stanza into one ``out_dir``.
|
|
158
|
+
|
|
159
|
+
They hold different locks, and each run removes the stanza's temporary files in
|
|
160
|
+
``out_dir``, so one could remove the file the other is writing.
|
|
161
|
+
"""
|
|
162
|
+
seen: dict[tuple[Path, str], str] = {}
|
|
163
|
+
for name, job in self.jobs.items():
|
|
164
|
+
stanza = job.params.get("stanza")
|
|
165
|
+
if job.type != "pgbackrest" or not isinstance(stanza, str):
|
|
166
|
+
continue # the engine refuses a stanza that is not a string when it is built
|
|
167
|
+
key = (Path(job.params["out_dir"]).expanduser().resolve(), stanza)
|
|
168
|
+
if key in seen:
|
|
169
|
+
raise ConfigError(
|
|
170
|
+
f"Job {name!r}: job {seen[key]!r} already exports stanza {stanza!r} into "
|
|
171
|
+
"this out_dir; give each job its own out_dir"
|
|
172
|
+
)
|
|
173
|
+
seen[key] = name
|
|
174
|
+
|
|
175
|
+
def _check_pgbackrest_layout(self, name: str, job: Job) -> None:
|
|
176
|
+
"""Keep the repository apart from everything bdbackup writes or locks.
|
|
177
|
+
|
|
178
|
+
bdbackup never writes under ``repo_path``; the units, the gfs rotation, the history
|
|
179
|
+
database with its lock and journal files, and the restores do.
|
|
180
|
+
"""
|
|
181
|
+
if "repo_path" not in job.params:
|
|
182
|
+
return # the engine refuses the job when it is built
|
|
183
|
+
repo = Path(job.params["repo_path"]).expanduser().resolve()
|
|
184
|
+
out_dir = Path(job.params["out_dir"]).expanduser().resolve()
|
|
185
|
+
if out_dir.is_relative_to(repo):
|
|
186
|
+
raise ConfigError(f"Job {name!r}: out_dir must be outside repo_path")
|
|
187
|
+
# Both [history] paths are resolved when the section is read.
|
|
188
|
+
for key, path in (
|
|
189
|
+
("[history] database", self.history.database),
|
|
190
|
+
("[history] restore_root", self.history.restore_root),
|
|
191
|
+
("restore_root", job.restore_root),
|
|
192
|
+
):
|
|
193
|
+
if path is not None and path.is_relative_to(repo):
|
|
194
|
+
raise ConfigError(f"Job {name!r}: {key} must be outside repo_path")
|
|
195
|
+
for other in self.jobs.values():
|
|
196
|
+
if other.type != "gfs":
|
|
197
|
+
continue
|
|
198
|
+
for stage in other.params["stage"]:
|
|
199
|
+
if any(repo.is_relative_to(path) for path in stage.paths):
|
|
200
|
+
raise ConfigError(
|
|
201
|
+
f"Job {name!r}: repo_path must be outside every gfs stage path"
|
|
202
|
+
)
|
|
203
|
+
if any(path.is_relative_to(repo) for path in stage.paths):
|
|
204
|
+
raise ConfigError(f"Job {name!r}: a gfs stage path must be outside repo_path")
|
|
127
205
|
|
|
128
206
|
def get(self, name: str) -> Job:
|
|
129
207
|
if name not in self.jobs:
|
|
@@ -5,11 +5,13 @@ Copies go through a ``Transport`` so that object storage can be added later (spe
|
|
|
5
5
|
|
|
6
6
|
from __future__ import annotations
|
|
7
7
|
|
|
8
|
+
import errno
|
|
8
9
|
import hashlib
|
|
9
10
|
import os
|
|
10
11
|
import shutil
|
|
11
12
|
import stat
|
|
12
|
-
from collections.abc import Callable
|
|
13
|
+
from collections.abc import Callable, Iterator
|
|
14
|
+
from contextlib import contextmanager
|
|
13
15
|
from pathlib import Path
|
|
14
16
|
from typing import Protocol
|
|
15
17
|
from uuid import uuid4
|
|
@@ -45,7 +47,23 @@ def _fsync_dir(path: Path) -> None:
|
|
|
45
47
|
|
|
46
48
|
|
|
47
49
|
class LocalTransport:
|
|
48
|
-
"""Local or mounted directories.
|
|
50
|
+
"""Local or mounted directories.
|
|
51
|
+
|
|
52
|
+
A share that maps every user to one account refuses chmod with EPERM. The copy then goes on
|
|
53
|
+
with whatever permission bits the share gave it, and ``modes_refused`` counts the refusals
|
|
54
|
+
for the run's report. Any other error from those calls still fails the copy.
|
|
55
|
+
"""
|
|
56
|
+
|
|
57
|
+
modes_refused: int = 0
|
|
58
|
+
|
|
59
|
+
@contextmanager
|
|
60
|
+
def _mode_may_be_refused(self) -> Iterator[None]:
|
|
61
|
+
try:
|
|
62
|
+
yield
|
|
63
|
+
except PermissionError as exc:
|
|
64
|
+
if exc.errno != errno.EPERM:
|
|
65
|
+
raise
|
|
66
|
+
self.modes_refused += 1
|
|
49
67
|
|
|
50
68
|
def _copy_file(self, source: Path, target: Path) -> str:
|
|
51
69
|
digest = hashlib.sha256()
|
|
@@ -55,7 +73,8 @@ class LocalTransport:
|
|
|
55
73
|
writer.write(chunk)
|
|
56
74
|
writer.flush()
|
|
57
75
|
os.fsync(writer.fileno())
|
|
58
|
-
|
|
76
|
+
with self._mode_may_be_refused():
|
|
77
|
+
shutil.copymode(source, target)
|
|
59
78
|
return digest.hexdigest()
|
|
60
79
|
|
|
61
80
|
def copy(self, source: Path, temp: Path, on_file: Callable[[str, str], None]) -> None:
|
|
@@ -87,7 +106,8 @@ class LocalTransport:
|
|
|
87
106
|
raise Refusal(f"unexpected entry {entry.relative_to(source).as_posix()}")
|
|
88
107
|
_fsync_dir(target_dir)
|
|
89
108
|
for here, target_dir in reversed(directories):
|
|
90
|
-
|
|
109
|
+
with self._mode_may_be_refused():
|
|
110
|
+
os.chmod(target_dir, stat.S_IMODE(here.lstat().st_mode))
|
|
91
111
|
|
|
92
112
|
def rename(self, temp: Path, final: Path) -> None:
|
|
93
113
|
if os.path.lexists(final):
|
|
@@ -19,7 +19,7 @@ from bdbackup.config import Config, Job
|
|
|
19
19
|
from bdbackup.gfs import store
|
|
20
20
|
from bdbackup.gfs.actions import LocalTransport, Refusal, Transport, copy_verified, verify
|
|
21
21
|
from bdbackup.gfs.policy import Decision, Unit, decide
|
|
22
|
-
from bdbackup.gfs.stages import MARKER, Stage
|
|
22
|
+
from bdbackup.gfs.stages import MARKER, Stage, fed_first_stages
|
|
23
23
|
from bdbackup.history import History, artifact_identity
|
|
24
24
|
from bdbackup.utils import process_lock
|
|
25
25
|
|
|
@@ -83,6 +83,8 @@ class _Run:
|
|
|
83
83
|
dry_run: bool):
|
|
84
84
|
self.job = job
|
|
85
85
|
self.stages: tuple[Stage, ...] = job.params["stage"]
|
|
86
|
+
# A pgbackrest job writes into the first stage: it has a marker and a ledger snapshot.
|
|
87
|
+
self.fed = self.stages[0].paths[0] in fed_first_stages(config.jobs)
|
|
86
88
|
self.apply = not dry_run
|
|
87
89
|
self.history = History(config.history)
|
|
88
90
|
self.today = today
|
|
@@ -327,6 +329,8 @@ class _Run:
|
|
|
327
329
|
def snapshot(self) -> None:
|
|
328
330
|
"""Copy the whole ledger to every later stage path, whatever the actions' outcome.
|
|
329
331
|
|
|
332
|
+
The first stage gets it too when a pgbackrest job feeds it, under the same marker rule.
|
|
333
|
+
|
|
330
334
|
One consistent copy is made locally with SQLite's online backup and then copied to
|
|
331
335
|
each path under a temporary name, fsynced and renamed, so SQLite never writes on a
|
|
332
336
|
stage and every path receives the same bytes (spec 2 §4.3, D18).
|
|
@@ -350,7 +354,7 @@ class _Run:
|
|
|
350
354
|
finally:
|
|
351
355
|
os.close(fd)
|
|
352
356
|
name = snapshot_name(self.job)
|
|
353
|
-
for stage in self.stages[1:]:
|
|
357
|
+
for stage in self.stages if self.fed else self.stages[1:]:
|
|
354
358
|
for path in stage.paths:
|
|
355
359
|
if not (path / MARKER).is_file():
|
|
356
360
|
self.snapshot_failed(path, "destination not ready")
|
|
@@ -379,6 +383,9 @@ class _Run:
|
|
|
379
383
|
f"({t.deleted_bytes} bytes), held {t.held}, deferred {t.deferred}, "
|
|
380
384
|
f"refused {t.refused}, failed {t.failed}, unmanaged {unmanaged}"
|
|
381
385
|
)
|
|
386
|
+
if modes_refused := getattr(self.transport, "modes_refused", 0):
|
|
387
|
+
self.out(f"permission bits not kept on {modes_refused} entries: "
|
|
388
|
+
"the destination refused chmod")
|
|
382
389
|
for index, stage in enumerate(self.stages):
|
|
383
390
|
sizes = [size for at, size in self.where.values() if at == index]
|
|
384
391
|
units = "unit" if len(sizes) == 1 else "units"
|