bdbackup 0.7.1__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.
Files changed (84) hide show
  1. {bdbackup-0.7.1 → bdbackup-0.7.2}/PKG-INFO +27 -14
  2. {bdbackup-0.7.1 → bdbackup-0.7.2}/README.md +26 -13
  3. {bdbackup-0.7.1 → bdbackup-0.7.2}/bdbackup/backends.py +1 -0
  4. {bdbackup-0.7.1 → bdbackup-0.7.2}/bdbackup/cli.py +75 -7
  5. {bdbackup-0.7.1 → bdbackup-0.7.2}/bdbackup/config.py +79 -1
  6. {bdbackup-0.7.1 → bdbackup-0.7.2}/bdbackup/engines.py +1 -0
  7. {bdbackup-0.7.1 → bdbackup-0.7.2}/bdbackup/gfs/actions.py +24 -4
  8. {bdbackup-0.7.1 → bdbackup-0.7.2}/bdbackup/gfs/runner.py +9 -2
  9. {bdbackup-0.7.1 → bdbackup-0.7.2}/bdbackup/gfs/stages.py +28 -1
  10. {bdbackup-0.7.1 → bdbackup-0.7.2}/bdbackup/gfs/structure.py +3 -2
  11. {bdbackup-0.7.1 → bdbackup-0.7.2}/bdbackup/history.py +1 -1
  12. bdbackup-0.7.2/bdbackup/postgres/__init__.py +22 -0
  13. bdbackup-0.7.2/bdbackup/postgres/pgbackrest.py +536 -0
  14. bdbackup-0.7.2/bdbackup/postgres/repository.py +238 -0
  15. bdbackup-0.7.2/bdbackup/postgres/restore.py +160 -0
  16. {bdbackup-0.7.1 → bdbackup-0.7.2}/bdbackup/recovery.py +2 -2
  17. {bdbackup-0.7.1 → bdbackup-0.7.2}/bdbackup/validation.py +10 -4
  18. {bdbackup-0.7.1 → bdbackup-0.7.2}/config.toml.example +78 -7
  19. {bdbackup-0.7.1 → bdbackup-0.7.2}/docs/README_ENGINES.md +4 -3
  20. {bdbackup-0.7.1 → bdbackup-0.7.2}/docs/README_FILE.md +4 -0
  21. {bdbackup-0.7.1 → bdbackup-0.7.2}/docs/README_GFS.md +54 -4
  22. bdbackup-0.7.2/docs/README_PGBACKREST.md +466 -0
  23. {bdbackup-0.7.1 → bdbackup-0.7.2}/pyproject.toml +1 -1
  24. bdbackup-0.7.2/scripts/docker/pgbackrest.Dockerfile +28 -0
  25. bdbackup-0.7.2/scripts/integration_pgbackrest.py +747 -0
  26. {bdbackup-0.7.1 → bdbackup-0.7.2}/tests/AGENTS.md +23 -10
  27. bdbackup-0.7.2/tests/pgbackrest_fake.py +198 -0
  28. {bdbackup-0.7.1 → bdbackup-0.7.2}/tests/test_cli_reshape.py +26 -0
  29. {bdbackup-0.7.1 → bdbackup-0.7.2}/tests/test_engines.py +5 -2
  30. {bdbackup-0.7.1 → bdbackup-0.7.2}/tests/test_gfs_init.py +36 -2
  31. {bdbackup-0.7.1 → bdbackup-0.7.2}/tests/test_gfs_run.py +100 -0
  32. {bdbackup-0.7.1 → bdbackup-0.7.2}/tests/test_history.py +26 -0
  33. bdbackup-0.7.2/tests/test_pgbackrest_cli.py +444 -0
  34. bdbackup-0.7.2/tests/test_pgbackrest_engine.py +1129 -0
  35. bdbackup-0.7.2/tests/test_pgbackrest_export.py +519 -0
  36. bdbackup-0.7.2/tests/test_pgbackrest_repository.py +488 -0
  37. bdbackup-0.7.2/tests/test_pgbackrest_restore.py +487 -0
  38. {bdbackup-0.7.1 → bdbackup-0.7.2}/.gitignore +0 -0
  39. {bdbackup-0.7.1 → bdbackup-0.7.2}/LICENSE +0 -0
  40. {bdbackup-0.7.1 → bdbackup-0.7.2}/bdbackup/__init__.py +0 -0
  41. {bdbackup-0.7.1 → bdbackup-0.7.2}/bdbackup/filebackup.py +0 -0
  42. {bdbackup-0.7.1 → bdbackup-0.7.2}/bdbackup/gfs/__init__.py +0 -0
  43. {bdbackup-0.7.1 → bdbackup-0.7.2}/bdbackup/gfs/policy.py +0 -0
  44. {bdbackup-0.7.1 → bdbackup-0.7.2}/bdbackup/gfs/store.py +0 -0
  45. {bdbackup-0.7.1 → bdbackup-0.7.2}/bdbackup/ledger.py +0 -0
  46. {bdbackup-0.7.1 → bdbackup-0.7.2}/bdbackup/mysql/__init__.py +0 -0
  47. {bdbackup-0.7.1 → bdbackup-0.7.2}/bdbackup/mysql/helpers.py +0 -0
  48. {bdbackup-0.7.1 → bdbackup-0.7.2}/bdbackup/mysql/mysqldump.py +0 -0
  49. {bdbackup-0.7.1 → bdbackup-0.7.2}/bdbackup/mysql/xtrabackup.py +0 -0
  50. {bdbackup-0.7.1 → bdbackup-0.7.2}/bdbackup/templates/__init__.py +0 -0
  51. {bdbackup-0.7.1 → bdbackup-0.7.2}/bdbackup/templates/_matching.py +0 -0
  52. {bdbackup-0.7.1 → bdbackup-0.7.2}/bdbackup/templates/python_dev.py +0 -0
  53. {bdbackup-0.7.1 → bdbackup-0.7.2}/bdbackup/utils.py +0 -0
  54. {bdbackup-0.7.1 → bdbackup-0.7.2}/contrib/systemd/bdbackup-incremental@.service +0 -0
  55. {bdbackup-0.7.1 → bdbackup-0.7.2}/contrib/systemd/bdbackup-incremental@.timer +0 -0
  56. {bdbackup-0.7.1 → bdbackup-0.7.2}/contrib/systemd/bdbackup@.service +0 -0
  57. {bdbackup-0.7.1 → bdbackup-0.7.2}/contrib/systemd/bdbackup@.timer +0 -0
  58. {bdbackup-0.7.1 → bdbackup-0.7.2}/docs/README_MYSQLDUMP.md +0 -0
  59. {bdbackup-0.7.1 → bdbackup-0.7.2}/docs/README_SYSTEMD.md +0 -0
  60. {bdbackup-0.7.1 → bdbackup-0.7.2}/docs/README_XTRABACKUP.md +0 -0
  61. {bdbackup-0.7.1 → bdbackup-0.7.2}/scripts/check_release.py +0 -0
  62. {bdbackup-0.7.1 → bdbackup-0.7.2}/scripts/integration_mysql.py +0 -0
  63. {bdbackup-0.7.1 → bdbackup-0.7.2}/scripts/integration_physical.py +0 -0
  64. {bdbackup-0.7.1 → bdbackup-0.7.2}/scripts/smoke_install.py +0 -0
  65. {bdbackup-0.7.1 → bdbackup-0.7.2}/template.txt +0 -0
  66. {bdbackup-0.7.1 → bdbackup-0.7.2}/tests/__init__.py +0 -0
  67. {bdbackup-0.7.1 → bdbackup-0.7.2}/tests/conftest.py +0 -0
  68. {bdbackup-0.7.1 → bdbackup-0.7.2}/tests/test_architecture.py +0 -0
  69. {bdbackup-0.7.1 → bdbackup-0.7.2}/tests/test_correctness.py +0 -0
  70. {bdbackup-0.7.1 → bdbackup-0.7.2}/tests/test_encryption.py +0 -0
  71. {bdbackup-0.7.1 → bdbackup-0.7.2}/tests/test_engine_conditions.py +0 -0
  72. {bdbackup-0.7.1 → bdbackup-0.7.2}/tests/test_gfs_config.py +0 -0
  73. {bdbackup-0.7.1 → bdbackup-0.7.2}/tests/test_gfs_policy.py +0 -0
  74. {bdbackup-0.7.1 → bdbackup-0.7.2}/tests/test_gfs_store.py +0 -0
  75. {bdbackup-0.7.1 → bdbackup-0.7.2}/tests/test_helpers.py +0 -0
  76. {bdbackup-0.7.1 → bdbackup-0.7.2}/tests/test_import.py +0 -0
  77. {bdbackup-0.7.1 → bdbackup-0.7.2}/tests/test_ledger.py +0 -0
  78. {bdbackup-0.7.1 → bdbackup-0.7.2}/tests/test_performance.py +0 -0
  79. {bdbackup-0.7.1 → bdbackup-0.7.2}/tests/test_release_fixes.py +0 -0
  80. {bdbackup-0.7.1 → bdbackup-0.7.2}/tests/test_run_selector.py +0 -0
  81. {bdbackup-0.7.1 → bdbackup-0.7.2}/tests/test_safety_nets.py +0 -0
  82. {bdbackup-0.7.1 → bdbackup-0.7.2}/tests/test_security.py +0 -0
  83. {bdbackup-0.7.1 → bdbackup-0.7.2}/tests/test_systemd_units.py +0 -0
  84. {bdbackup-0.7.1 → 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.1
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 and
40
- files on Linux and macOS. It takes MySQL and MariaDB backups with mysqldump,
41
- Percona XtraBackup and MariaDB Backup (full and incremental physical backups,
42
- compressed and optionally encrypted), archives files and directories as tar,
43
- tar.gz or tar.zst, and rotates the results across storage stages with GFS
44
- (grandfather-father-son) retention. Every backup is verified before it is
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,6 +74,7 @@ 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 |
76
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 |
@@ -143,7 +147,7 @@ The CLI uses these exit codes:
143
147
  | Code | Meaning |
144
148
  |------|---------|
145
149
  | 0 | Success |
146
- | 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 |
147
151
  | 2 | Usage error, an inactive job, or a configuration error found when the config loads or by `--dry-run` |
148
152
  | 3 | Lock held; for GFS, another run of the job is in progress or only deferred work remains |
149
153
 
@@ -204,10 +208,12 @@ An xtrabackup job also takes `--incremental`; see
204
208
 
205
209
  `--dry-run` reports what a job would do: it runs no backup tool, writes no
206
210
  backup and records no history; a GFS dry run creates only its job's lock file
207
- beside the history database. What each job type reports is described with it:
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:
208
213
  [file jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_FILE.md#dry-run),
209
214
  [mysqldump jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_MYSQLDUMP.md#dry-run),
210
- [xtrabackup jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_XTRABACKUP.md#dry-run) and
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
211
217
  [GFS jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_GFS.md#dry-run).
212
218
 
213
219
  A dry run exits 1 where the real run would fail before writing anything (an
@@ -285,7 +291,8 @@ Checks cover direct grants; role-derived privileges and partial revokes may need
285
291
  manual review. Physical datadir checks cover root-directory access, not every data
286
292
  file or external tablespace. Custom mysqldump options, routine visibility, GTID
287
293
  settings and exact server/binary version compatibility still need review.
288
- For a GFS job, every stage path after the first must exist and be writable, and
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
289
296
  its `.bdbackup-destination` marker must be present and writable; a missing
290
297
  marker's line names the `--initialize-structure` command that creates it.
291
298
  An unreachable database or missing client is a failed/incomplete check, not a pass.
@@ -396,7 +403,8 @@ bdbackup restore -c config.toml --backup-id 12 --dst /restore/job-12 --yes
396
403
  What a restore produces depends on the job type; see
397
404
  [file jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_FILE.md#history-restore),
398
405
  [mysqldump jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_MYSQLDUMP.md#history-restore),
399
- [xtrabackup jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_XTRABACKUP.md#history-restore) and
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
400
408
  [custom engines](https://github.com/ayder/bdbackup/blob/master/docs/README_ENGINES.md#history-restore).
401
409
 
402
410
  Deleted artifacts remain in history as unavailable. File identity, size, and
@@ -418,16 +426,21 @@ ruff check bdbackup tests scripts
418
426
  ```
419
427
 
420
428
  Optional database integration tests use disposable, network-isolated Docker
421
- containers with synthetic data. They remove only the containers and volumes
422
- 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:
423
431
 
424
432
  ```bash
425
433
  python scripts/integration_mysql.py # mysql:8.4
426
434
  python scripts/integration_physical.py percona # percona-server/xtrabackup:8.4
427
435
  python scripts/integration_physical.py percona-encrypted # AES256 + zstd recovery
428
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
429
439
  ```
430
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
+
431
444
  Physical recovery returns a prepared data directory; copying it into a server's
432
445
  data directory, assigning ownership to the server user, and starting that server
433
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 and
6
- files on Linux and macOS. It takes MySQL and MariaDB backups with mysqldump,
7
- Percona XtraBackup and MariaDB Backup (full and incremental physical backups,
8
- compressed and optionally encrypted), archives files and directories as tar,
9
- tar.gz or tar.zst, and rotates the results across storage stages with GFS
10
- (grandfather-father-son) retention. Every backup is verified before it is
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,6 +40,7 @@ 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 |
42
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 |
@@ -109,7 +113,7 @@ The CLI uses these exit codes:
109
113
  | Code | Meaning |
110
114
  |------|---------|
111
115
  | 0 | Success |
112
- | 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 |
113
117
  | 2 | Usage error, an inactive job, or a configuration error found when the config loads or by `--dry-run` |
114
118
  | 3 | Lock held; for GFS, another run of the job is in progress or only deferred work remains |
115
119
 
@@ -170,10 +174,12 @@ An xtrabackup job also takes `--incremental`; see
170
174
 
171
175
  `--dry-run` reports what a job would do: it runs no backup tool, writes no
172
176
  backup and records no history; a GFS dry run creates only its job's lock file
173
- beside the history database. What each job type reports is described with it:
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:
174
179
  [file jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_FILE.md#dry-run),
175
180
  [mysqldump jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_MYSQLDUMP.md#dry-run),
176
- [xtrabackup jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_XTRABACKUP.md#dry-run) and
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
177
183
  [GFS jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_GFS.md#dry-run).
178
184
 
179
185
  A dry run exits 1 where the real run would fail before writing anything (an
@@ -251,7 +257,8 @@ Checks cover direct grants; role-derived privileges and partial revokes may need
251
257
  manual review. Physical datadir checks cover root-directory access, not every data
252
258
  file or external tablespace. Custom mysqldump options, routine visibility, GTID
253
259
  settings and exact server/binary version compatibility still need review.
254
- For a GFS job, every stage path after the first must exist and be writable, and
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
255
262
  its `.bdbackup-destination` marker must be present and writable; a missing
256
263
  marker's line names the `--initialize-structure` command that creates it.
257
264
  An unreachable database or missing client is a failed/incomplete check, not a pass.
@@ -362,7 +369,8 @@ bdbackup restore -c config.toml --backup-id 12 --dst /restore/job-12 --yes
362
369
  What a restore produces depends on the job type; see
363
370
  [file jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_FILE.md#history-restore),
364
371
  [mysqldump jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_MYSQLDUMP.md#history-restore),
365
- [xtrabackup jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_XTRABACKUP.md#history-restore) and
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
366
374
  [custom engines](https://github.com/ayder/bdbackup/blob/master/docs/README_ENGINES.md#history-restore).
367
375
 
368
376
  Deleted artifacts remain in history as unavailable. File identity, size, and
@@ -384,16 +392,21 @@ ruff check bdbackup tests scripts
384
392
  ```
385
393
 
386
394
  Optional database integration tests use disposable, network-isolated Docker
387
- containers with synthetic data. They remove only the containers and volumes
388
- 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:
389
397
 
390
398
  ```bash
391
399
  python scripts/integration_mysql.py # mysql:8.4
392
400
  python scripts/integration_physical.py percona # percona-server/xtrabackup:8.4
393
401
  python scripts/integration_physical.py percona-encrypted # AES256 + zstd recovery
394
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
395
405
  ```
396
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
+
397
410
  Physical recovery returns a prepared data directory; copying it into a server's
398
411
  data directory, assigning ownership to the server user, and starting that server
399
412
  are separate administrator actions. Use the same database version and
@@ -15,6 +15,7 @@ class BackupResult:
15
15
  path: Path
16
16
  size_bytes: int = 0
17
17
  success: bool = False
18
+ checksum: str | None = None # SHA-256 an engine computed while writing; history keeps it
18
19
 
19
20
 
20
21
  class BackupError(Exception):
@@ -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
- ctx.exit(gfs_structure.initialize(job, click.echo))
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: {dst}")
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:
@@ -53,6 +53,7 @@ logger = logging.getLogger("bdbackup.engines")
53
53
  # append "bdbackup.postgres" here — nothing else needs to change.
54
54
  FAMILIES: tuple[str, ...] = (
55
55
  "bdbackup.mysql",
56
+ "bdbackup.postgres",
56
57
  )
57
58
 
58
59
 
@@ -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
- shutil.copymode(source, target)
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
- os.chmod(target_dir, stat.S_IMODE(here.lstat().st_mode))
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"
@@ -121,7 +121,12 @@ def _overlap(a: Path, b: Path) -> bool:
121
121
 
122
122
 
123
123
  def _engine_output(job: Job) -> Path | None:
124
- key = {"xtrabackup": "backup_root", "mysqldump": "out_dir", "file": "backup_dst"}.get(job.type)
124
+ key = {
125
+ "xtrabackup": "backup_root",
126
+ "mysqldump": "out_dir",
127
+ "file": "backup_dst",
128
+ "pgbackrest": "out_dir",
129
+ }.get(job.type)
125
130
  value = job.params.get(key) if key else None
126
131
  return Path(value).expanduser().resolve() if value is not None else None
127
132
 
@@ -169,3 +174,25 @@ def check_gfs_config(jobs: Mapping[str, Job], history: HistorySettings | None) -
169
174
  raise ValueError(
170
175
  f"Job {other.name!r} writes into first stage {first}: set timestamp = true"
171
176
  )
177
+
178
+
179
+ def pgbackrest_first_stage(job: Job, jobs: Mapping[str, Job]) -> Path:
180
+ """The first stage path of the gfs job whose first stage holds the job's ``out_dir``.
181
+
182
+ ``out_dir`` holds when it equals that path or lies below it.
183
+ """
184
+ output = _engine_output(job)
185
+ if output is not None:
186
+ for other in jobs.values():
187
+ if other.type == "gfs":
188
+ first = other.params["stage"][0].paths[0]
189
+ if output.is_relative_to(first):
190
+ return first
191
+ raise ValueError("out_dir must be inside the first stage of a gfs job")
192
+
193
+
194
+ def fed_first_stages(jobs: Mapping[str, Job]) -> set[Path]:
195
+ """The first stage paths that some pgbackrest job writes into."""
196
+ return {
197
+ pgbackrest_first_stage(job, jobs) for job in jobs.values() if job.type == "pgbackrest"
198
+ }