bdbackup 0.7.4__tar.gz → 0.7.5__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.4 → bdbackup-0.7.5}/PKG-INFO +21 -11
- {bdbackup-0.7.4 → bdbackup-0.7.5}/README.md +20 -10
- bdbackup-0.7.5/bdbackup/_ssh_status.sh +12 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/bdbackup/cli.py +77 -13
- {bdbackup-0.7.4 → bdbackup-0.7.5}/bdbackup/config.py +112 -22
- bdbackup-0.7.5/bdbackup/copy_runner.py +146 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/bdbackup/engines.py +1 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/bdbackup/gfs/stages.py +1 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/bdbackup/history.py +141 -3
- bdbackup-0.7.5/bdbackup/mongodb/__init__.py +1 -0
- bdbackup-0.7.5/bdbackup/mongodb/export.py +140 -0
- bdbackup-0.7.5/bdbackup/mongodb/pbm.py +233 -0
- bdbackup-0.7.5/bdbackup/mongodb/restore.py +72 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/bdbackup/postgres/pgbackrest.py +9 -89
- {bdbackup-0.7.4 → bdbackup-0.7.5}/bdbackup/recovery.py +2 -2
- bdbackup-0.7.5/bdbackup/ssh_copy.py +344 -0
- bdbackup-0.7.5/bdbackup/tar_export.py +101 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/bdbackup/validation.py +215 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/config.toml.example +54 -6
- bdbackup-0.7.5/docs/README_COPY.md +147 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/docs/README_ENGINES.md +2 -1
- {bdbackup-0.7.4 → bdbackup-0.7.5}/docs/README_FILE.md +12 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/docs/README_GFS.md +10 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/docs/README_METRICS.md +1 -1
- {bdbackup-0.7.4 → bdbackup-0.7.5}/docs/README_MYSQLDUMP.md +13 -0
- bdbackup-0.7.5/docs/README_PBM.md +197 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/docs/README_PGBACKREST.md +26 -7
- {bdbackup-0.7.4 → bdbackup-0.7.5}/pyproject.toml +1 -1
- bdbackup-0.7.5/scripts/docker/pbm.Dockerfile +15 -0
- bdbackup-0.7.5/scripts/docker/ssh-copy.Dockerfile +21 -0
- bdbackup-0.7.5/scripts/integration_pbm.py +862 -0
- bdbackup-0.7.5/scripts/integration_ssh_copy.py +807 -0
- bdbackup-0.7.5/scripts/smoke_install.py +163 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/tests/AGENTS.md +52 -8
- bdbackup-0.7.5/tests/pbm_fake.py +17 -0
- bdbackup-0.7.5/tests/ssh_copy_fake.py +58 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/tests/test_encryption.py +5 -3
- {bdbackup-0.7.4 → bdbackup-0.7.5}/tests/test_engines.py +5 -2
- {bdbackup-0.7.4 → bdbackup-0.7.5}/tests/test_gfs_store.py +2 -2
- {bdbackup-0.7.4 → bdbackup-0.7.5}/tests/test_last_runs.py +5 -4
- {bdbackup-0.7.4 → bdbackup-0.7.5}/tests/test_ledger.py +1 -1
- {bdbackup-0.7.4 → bdbackup-0.7.5}/tests/test_metrics_collect.py +1 -1
- bdbackup-0.7.5/tests/test_pbm_cli.py +407 -0
- bdbackup-0.7.5/tests/test_pbm_commands.py +185 -0
- bdbackup-0.7.5/tests/test_pbm_config.py +156 -0
- bdbackup-0.7.5/tests/test_pbm_docs.py +43 -0
- bdbackup-0.7.5/tests/test_pbm_export.py +218 -0
- bdbackup-0.7.5/tests/test_pbm_integration.py +291 -0
- bdbackup-0.7.5/tests/test_pbm_validation.py +245 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/tests/test_pgbackrest_cli.py +195 -2
- bdbackup-0.7.5/tests/test_smoke_install.py +55 -0
- bdbackup-0.7.5/tests/test_ssh_copy_artifact.py +274 -0
- bdbackup-0.7.5/tests/test_ssh_copy_config.py +197 -0
- bdbackup-0.7.5/tests/test_ssh_copy_connection.py +185 -0
- bdbackup-0.7.5/tests/test_ssh_copy_docs.py +38 -0
- bdbackup-0.7.5/tests/test_ssh_copy_history.py +344 -0
- bdbackup-0.7.5/tests/test_ssh_copy_integration.py +72 -0
- bdbackup-0.7.5/tests/test_ssh_copy_probe.py +10 -0
- bdbackup-0.7.5/tests/test_ssh_copy_runner.py +631 -0
- bdbackup-0.7.5/tests/test_ssh_copy_validation.py +243 -0
- bdbackup-0.7.4/scripts/smoke_install.py +0 -78
- {bdbackup-0.7.4 → bdbackup-0.7.5}/.gitignore +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/LICENSE +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/bdbackup/__init__.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/bdbackup/backends.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/bdbackup/filebackup.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/bdbackup/gfs/__init__.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/bdbackup/gfs/actions.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/bdbackup/gfs/drift.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/bdbackup/gfs/policy.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/bdbackup/gfs/runner.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/bdbackup/gfs/store.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/bdbackup/gfs/structure.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/bdbackup/ledger.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/bdbackup/metrics/__init__.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/bdbackup/metrics/collector.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/bdbackup/metrics/data.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/bdbackup/metrics/families.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/bdbackup/metrics/gfs.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/bdbackup/metrics/jobs.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/bdbackup/metrics/probe.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/bdbackup/metrics/registry.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/bdbackup/metrics/render.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/bdbackup/metrics/run.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/bdbackup/metrics/settings.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/bdbackup/metrics/units.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/bdbackup/metrics/write.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/bdbackup/metrics_command.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/bdbackup/mysql/__init__.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/bdbackup/mysql/helpers.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/bdbackup/mysql/mysqldump.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/bdbackup/mysql/xtrabackup.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/bdbackup/postgres/__init__.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/bdbackup/postgres/metrics.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/bdbackup/postgres/repository.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/bdbackup/postgres/restore.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/bdbackup/templates/__init__.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/bdbackup/templates/_matching.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/bdbackup/templates/python_dev.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/bdbackup/utils.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/contrib/systemd/bdbackup-incremental@.service +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/contrib/systemd/bdbackup-incremental@.timer +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/contrib/systemd/bdbackup@.service +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/contrib/systemd/bdbackup@.timer +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/docs/README_SYSTEMD.md +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/docs/README_XTRABACKUP.md +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/scripts/check_release.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/scripts/docker/nfs-outage.Dockerfile +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/scripts/docker/pgbackrest.Dockerfile +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/scripts/integration_mysql.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/scripts/integration_nfs_outage.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/scripts/integration_pgbackrest.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/scripts/integration_physical.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/template.txt +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/tests/__init__.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/tests/conftest.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/tests/pgbackrest_fake.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/tests/test_architecture.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/tests/test_broken_pipe.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/tests/test_cli_reshape.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/tests/test_config_lexical.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/tests/test_correctness.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/tests/test_engine_conditions.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/tests/test_gfs_config.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/tests/test_gfs_drift.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/tests/test_gfs_init.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/tests/test_gfs_policy.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/tests/test_gfs_run.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/tests/test_helpers.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/tests/test_history.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/tests/test_import.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/tests/test_metrics_command.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/tests/test_metrics_config.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/tests/test_metrics_gfs.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/tests/test_metrics_hang.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/tests/test_metrics_phases.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/tests/test_metrics_probe.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/tests/test_metrics_render.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/tests/test_metrics_write.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/tests/test_performance.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/tests/test_pgbackrest_engine.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/tests/test_pgbackrest_export.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/tests/test_pgbackrest_metrics.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/tests/test_pgbackrest_repository.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/tests/test_pgbackrest_restore.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/tests/test_release_fixes.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/tests/test_run_selector.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/tests/test_safety_nets.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/tests/test_security.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/tests/test_systemd_units.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/tests/test_templates.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/tests/test_validate_metrics.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/tests/test_validate_os_errors.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/tests/test_validate_os_user.py +0 -0
- {bdbackup-0.7.4 → bdbackup-0.7.5}/tests/test_validate_unreachable.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.5
|
|
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
|
|
@@ -37,15 +37,17 @@ Description-Content-Type: text/markdown
|
|
|
37
37
|
**Backups by design.**
|
|
38
38
|
|
|
39
39
|
bdbackup is a command-line backup tool and Python library for MySQL, MariaDB,
|
|
40
|
-
PostgreSQL
|
|
40
|
+
PostgreSQL, MongoDB and files on Linux and macOS. It takes MySQL and MariaDB
|
|
41
41
|
backups with mysqldump, Percona XtraBackup and MariaDB Backup (full and
|
|
42
42
|
incremental physical backups, compressed and optionally encrypted), exports
|
|
43
|
-
pgBackRest fulls,
|
|
43
|
+
pgBackRest fulls, takes and exports full MongoDB backups with Percona Backup for
|
|
44
|
+
MongoDB (PBM), archives files and directories as tar, tar.gz or tar.zst, and
|
|
44
45
|
rotates the results across storage stages with GFS (grandfather-father-son)
|
|
45
46
|
retention. Every backup is verified before it is
|
|
46
47
|
published and recorded with a SHA-256 checksum in an SQLite backup history, from
|
|
47
|
-
which a guided restore prepares a recovery copy.
|
|
48
|
-
|
|
48
|
+
which a guided restore prepares a recovery copy. File, mysqldump, pgbackrest
|
|
49
|
+
and pbm jobs can send their published archives to an SSH server with rsync or scp.
|
|
50
|
+
Jobs live in one TOML file and run from cron.
|
|
49
51
|
|
|
50
52
|
## Features
|
|
51
53
|
|
|
@@ -56,6 +58,8 @@ run from cron.
|
|
|
56
58
|
gzip-compressed, one database or all.
|
|
57
59
|
- [PostgreSQL pgBackRest backups](https://github.com/ayder/bdbackup/blob/master/docs/README_PGBACKREST.md): the newest
|
|
58
60
|
full of a stanza exported as one tar into a GFS stage, restorable on its own.
|
|
61
|
+
- Take full logical or physical MongoDB backups and export each as one tar.
|
|
62
|
+
[MongoDB backups with PBM](https://github.com/ayder/bdbackup/blob/master/docs/README_PBM.md)
|
|
59
63
|
- [File and directory backups](https://github.com/ayder/bdbackup/blob/master/docs/README_FILE.md) as tar archives, with
|
|
60
64
|
gitignore-style exclusion templates.
|
|
61
65
|
- [GFS (grandfather-father-son) backup rotation](https://github.com/ayder/bdbackup/blob/master/docs/README_GFS.md): daily,
|
|
@@ -64,7 +68,8 @@ run from cron.
|
|
|
64
68
|
- [Backup history and guided restore](#backup-history-and-guided-restore) with
|
|
65
69
|
SHA-256 checksums in SQLite.
|
|
66
70
|
- [Configuration validation](#validate-configuration-and-permissions) of
|
|
67
|
-
settings, filesystem permissions
|
|
71
|
+
settings, filesystem permissions, MySQL grants, PBM and SSH copy readiness,
|
|
72
|
+
without running a backup.
|
|
68
73
|
- [Prometheus metrics](https://github.com/ayder/bdbackup/blob/master/docs/README_METRICS.md): a read-only
|
|
69
74
|
`bdbackup metrics` writes a textfile for node_exporter and PMM with the last run of each
|
|
70
75
|
pgbackrest and gfs job, the history, the GFS stages, the destinations and the pgBackRest
|
|
@@ -79,7 +84,9 @@ run from cron.
|
|
|
79
84
|
| [MySQL and MariaDB logical backups with mysqldump](https://github.com/ayder/bdbackup/blob/master/docs/README_MYSQLDUMP.md) | mysqldump jobs, credentials, default options |
|
|
80
85
|
| [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 |
|
|
81
86
|
| [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 |
|
|
87
|
+
| [MongoDB backups with Percona Backup for MongoDB](https://github.com/ayder/bdbackup/blob/master/docs/README_PBM.md) | pbm jobs, secondary and shared storage, logical and physical backups, GFS and SSH copy, restore and retention |
|
|
82
88
|
| [GFS (grandfather-father-son) backup rotation](https://github.com/ayder/bdbackup/blob/master/docs/README_GFS.md) | stages, the `verify` key, preparing stage directories, safety rules and renames, final name exists, drift, run and step logs, ledger copies, known limits |
|
|
89
|
+
| [Copy published backups to an SSH server](https://github.com/ayder/bdbackup/blob/master/docs/README_COPY.md) | per-job configuration, rsync and scp, server setup, verified publication, retries and failure remedies |
|
|
83
90
|
| [Prometheus metrics: `bdbackup metrics`](https://github.com/ayder/bdbackup/blob/master/docs/README_METRICS.md) | the metrics command and `[metrics]`, the textfile for node_exporter and PMM, every metric (coverage and drift of the GFS stages included), alerting, hangs and outages, known limits |
|
|
84
91
|
| [Custom backup engines (plugins)](https://github.com/ayder/bdbackup/blob/master/docs/README_ENGINES.md) | the engine registry, writing your own engine and its metrics collector |
|
|
85
92
|
| [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 |
|
|
@@ -94,7 +101,8 @@ with Zstandard support. Database binaries are separate system dependencies.
|
|
|
94
101
|
Every built-in backend verifies staging output before publishing it. A missing
|
|
95
102
|
or unreadable file fails the backup and preserves the previous archive. A process
|
|
96
103
|
lock prevents concurrent writers to the same file destination or physical root.
|
|
97
|
-
`--no-verify` skips
|
|
104
|
+
`--no-verify` skips the job's optional verification pass. For pgbackrest and
|
|
105
|
+
pbm jobs this pass reads the temporary tar before publication.
|
|
98
106
|
Verification checks archive readability or physical checkpoints; it does not
|
|
99
107
|
replace testing a restore. File backups are not filesystem snapshots: quiesce
|
|
100
108
|
applications or back up snapshots when files can change during a run.
|
|
@@ -156,9 +164,9 @@ The CLI uses these exit codes:
|
|
|
156
164
|
| Code | Meaning |
|
|
157
165
|
|------|---------|
|
|
158
166
|
| 0 | Success |
|
|
159
|
-
| 1 | Backup
|
|
167
|
+
| 1 | Backup, verification, or SSH copy failure, or failed or incomplete validation. A backend rejecting its settings in a real run also exits 1, except pgbackrest reports a usage error. For `metrics`, the file was written with an error series or could not be written. |
|
|
160
168
|
| 2 | Usage error, an inactive job, or a configuration error found when the config loads or by `--dry-run` |
|
|
161
|
-
| 3 | Lock held
|
|
169
|
+
| 3 | Lock held, including another run holding the job's SSH copy lock. For GFS, another run is in progress or only deferred work remains. For `metrics`, another metrics run holds its lock. |
|
|
162
170
|
|
|
163
171
|
## Config-driven jobs
|
|
164
172
|
|
|
@@ -222,7 +230,8 @@ the read-only `pgbackrest info`. What each job type reports is described with it
|
|
|
222
230
|
[file jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_FILE.md#dry-run),
|
|
223
231
|
[mysqldump jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_MYSQLDUMP.md#dry-run),
|
|
224
232
|
[xtrabackup jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_XTRABACKUP.md#dry-run),
|
|
225
|
-
[pgbackrest jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_PGBACKREST.md#dry-run-and-validation)
|
|
233
|
+
[pgbackrest jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_PGBACKREST.md#dry-run-and-validation),
|
|
234
|
+
[pbm jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_PBM.md#run-and-validate) and
|
|
226
235
|
[GFS jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_GFS.md#dry-run).
|
|
227
236
|
|
|
228
237
|
A dry run exits 1 where the real run would fail before writing anything (an
|
|
@@ -431,7 +440,8 @@ What a restore produces depends on the job type; see
|
|
|
431
440
|
[file jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_FILE.md#history-restore),
|
|
432
441
|
[mysqldump jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_MYSQLDUMP.md#history-restore),
|
|
433
442
|
[xtrabackup jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_XTRABACKUP.md#history-restore),
|
|
434
|
-
[pgbackrest jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_PGBACKREST.md#restore)
|
|
443
|
+
[pgbackrest jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_PGBACKREST.md#restore),
|
|
444
|
+
[pbm jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_PBM.md#restore) and
|
|
435
445
|
[custom engines](https://github.com/ayder/bdbackup/blob/master/docs/README_ENGINES.md#history-restore).
|
|
436
446
|
|
|
437
447
|
Deleted artifacts remain in history as unavailable. File identity, size, and
|
|
@@ -3,15 +3,17 @@
|
|
|
3
3
|
**Backups by design.**
|
|
4
4
|
|
|
5
5
|
bdbackup is a command-line backup tool and Python library for MySQL, MariaDB,
|
|
6
|
-
PostgreSQL
|
|
6
|
+
PostgreSQL, MongoDB and files on Linux and macOS. It takes MySQL and MariaDB
|
|
7
7
|
backups with mysqldump, Percona XtraBackup and MariaDB Backup (full and
|
|
8
8
|
incremental physical backups, compressed and optionally encrypted), exports
|
|
9
|
-
pgBackRest fulls,
|
|
9
|
+
pgBackRest fulls, takes and exports full MongoDB backups with Percona Backup for
|
|
10
|
+
MongoDB (PBM), archives files and directories as tar, tar.gz or tar.zst, and
|
|
10
11
|
rotates the results across storage stages with GFS (grandfather-father-son)
|
|
11
12
|
retention. Every backup is verified before it is
|
|
12
13
|
published and recorded with a SHA-256 checksum in an SQLite backup history, from
|
|
13
|
-
which a guided restore prepares a recovery copy.
|
|
14
|
-
|
|
14
|
+
which a guided restore prepares a recovery copy. File, mysqldump, pgbackrest
|
|
15
|
+
and pbm jobs can send their published archives to an SSH server with rsync or scp.
|
|
16
|
+
Jobs live in one TOML file and run from cron.
|
|
15
17
|
|
|
16
18
|
## Features
|
|
17
19
|
|
|
@@ -22,6 +24,8 @@ run from cron.
|
|
|
22
24
|
gzip-compressed, one database or all.
|
|
23
25
|
- [PostgreSQL pgBackRest backups](https://github.com/ayder/bdbackup/blob/master/docs/README_PGBACKREST.md): the newest
|
|
24
26
|
full of a stanza exported as one tar into a GFS stage, restorable on its own.
|
|
27
|
+
- Take full logical or physical MongoDB backups and export each as one tar.
|
|
28
|
+
[MongoDB backups with PBM](https://github.com/ayder/bdbackup/blob/master/docs/README_PBM.md)
|
|
25
29
|
- [File and directory backups](https://github.com/ayder/bdbackup/blob/master/docs/README_FILE.md) as tar archives, with
|
|
26
30
|
gitignore-style exclusion templates.
|
|
27
31
|
- [GFS (grandfather-father-son) backup rotation](https://github.com/ayder/bdbackup/blob/master/docs/README_GFS.md): daily,
|
|
@@ -30,7 +34,8 @@ run from cron.
|
|
|
30
34
|
- [Backup history and guided restore](#backup-history-and-guided-restore) with
|
|
31
35
|
SHA-256 checksums in SQLite.
|
|
32
36
|
- [Configuration validation](#validate-configuration-and-permissions) of
|
|
33
|
-
settings, filesystem permissions
|
|
37
|
+
settings, filesystem permissions, MySQL grants, PBM and SSH copy readiness,
|
|
38
|
+
without running a backup.
|
|
34
39
|
- [Prometheus metrics](https://github.com/ayder/bdbackup/blob/master/docs/README_METRICS.md): a read-only
|
|
35
40
|
`bdbackup metrics` writes a textfile for node_exporter and PMM with the last run of each
|
|
36
41
|
pgbackrest and gfs job, the history, the GFS stages, the destinations and the pgBackRest
|
|
@@ -45,7 +50,9 @@ run from cron.
|
|
|
45
50
|
| [MySQL and MariaDB logical backups with mysqldump](https://github.com/ayder/bdbackup/blob/master/docs/README_MYSQLDUMP.md) | mysqldump jobs, credentials, default options |
|
|
46
51
|
| [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 |
|
|
47
52
|
| [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 |
|
|
53
|
+
| [MongoDB backups with Percona Backup for MongoDB](https://github.com/ayder/bdbackup/blob/master/docs/README_PBM.md) | pbm jobs, secondary and shared storage, logical and physical backups, GFS and SSH copy, restore and retention |
|
|
48
54
|
| [GFS (grandfather-father-son) backup rotation](https://github.com/ayder/bdbackup/blob/master/docs/README_GFS.md) | stages, the `verify` key, preparing stage directories, safety rules and renames, final name exists, drift, run and step logs, ledger copies, known limits |
|
|
55
|
+
| [Copy published backups to an SSH server](https://github.com/ayder/bdbackup/blob/master/docs/README_COPY.md) | per-job configuration, rsync and scp, server setup, verified publication, retries and failure remedies |
|
|
49
56
|
| [Prometheus metrics: `bdbackup metrics`](https://github.com/ayder/bdbackup/blob/master/docs/README_METRICS.md) | the metrics command and `[metrics]`, the textfile for node_exporter and PMM, every metric (coverage and drift of the GFS stages included), alerting, hangs and outages, known limits |
|
|
50
57
|
| [Custom backup engines (plugins)](https://github.com/ayder/bdbackup/blob/master/docs/README_ENGINES.md) | the engine registry, writing your own engine and its metrics collector |
|
|
51
58
|
| [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 |
|
|
@@ -60,7 +67,8 @@ with Zstandard support. Database binaries are separate system dependencies.
|
|
|
60
67
|
Every built-in backend verifies staging output before publishing it. A missing
|
|
61
68
|
or unreadable file fails the backup and preserves the previous archive. A process
|
|
62
69
|
lock prevents concurrent writers to the same file destination or physical root.
|
|
63
|
-
`--no-verify` skips
|
|
70
|
+
`--no-verify` skips the job's optional verification pass. For pgbackrest and
|
|
71
|
+
pbm jobs this pass reads the temporary tar before publication.
|
|
64
72
|
Verification checks archive readability or physical checkpoints; it does not
|
|
65
73
|
replace testing a restore. File backups are not filesystem snapshots: quiesce
|
|
66
74
|
applications or back up snapshots when files can change during a run.
|
|
@@ -122,9 +130,9 @@ The CLI uses these exit codes:
|
|
|
122
130
|
| Code | Meaning |
|
|
123
131
|
|------|---------|
|
|
124
132
|
| 0 | Success |
|
|
125
|
-
| 1 | Backup
|
|
133
|
+
| 1 | Backup, verification, or SSH copy failure, or failed or incomplete validation. A backend rejecting its settings in a real run also exits 1, except pgbackrest reports a usage error. For `metrics`, the file was written with an error series or could not be written. |
|
|
126
134
|
| 2 | Usage error, an inactive job, or a configuration error found when the config loads or by `--dry-run` |
|
|
127
|
-
| 3 | Lock held
|
|
135
|
+
| 3 | Lock held, including another run holding the job's SSH copy lock. For GFS, another run is in progress or only deferred work remains. For `metrics`, another metrics run holds its lock. |
|
|
128
136
|
|
|
129
137
|
## Config-driven jobs
|
|
130
138
|
|
|
@@ -188,7 +196,8 @@ the read-only `pgbackrest info`. What each job type reports is described with it
|
|
|
188
196
|
[file jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_FILE.md#dry-run),
|
|
189
197
|
[mysqldump jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_MYSQLDUMP.md#dry-run),
|
|
190
198
|
[xtrabackup jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_XTRABACKUP.md#dry-run),
|
|
191
|
-
[pgbackrest jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_PGBACKREST.md#dry-run-and-validation)
|
|
199
|
+
[pgbackrest jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_PGBACKREST.md#dry-run-and-validation),
|
|
200
|
+
[pbm jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_PBM.md#run-and-validate) and
|
|
192
201
|
[GFS jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_GFS.md#dry-run).
|
|
193
202
|
|
|
194
203
|
A dry run exits 1 where the real run would fail before writing anything (an
|
|
@@ -397,7 +406,8 @@ What a restore produces depends on the job type; see
|
|
|
397
406
|
[file jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_FILE.md#history-restore),
|
|
398
407
|
[mysqldump jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_MYSQLDUMP.md#history-restore),
|
|
399
408
|
[xtrabackup jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_XTRABACKUP.md#history-restore),
|
|
400
|
-
[pgbackrest jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_PGBACKREST.md#restore)
|
|
409
|
+
[pgbackrest jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_PGBACKREST.md#restore),
|
|
410
|
+
[pbm jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_PBM.md#restore) and
|
|
401
411
|
[custom engines](https://github.com/ayder/bdbackup/blob/master/docs/README_ENGINES.md#history-restore).
|
|
402
412
|
|
|
403
413
|
Deleted artifacts remain in history as unavailable. File identity, size, and
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
# The transfer tool owns the SSH streams. Record only the SSH process status.
|
|
3
|
+
status_file=${BDBACKUP_SSH_STATUS:?missing SSH status path}
|
|
4
|
+
if ! command -v ssh >/dev/null 2>&1; then
|
|
5
|
+
printf '%s\n' 'missing' > "$status_file"
|
|
6
|
+
printf '%s\n' 'ssh: executable not found' >&2
|
|
7
|
+
exit 127
|
|
8
|
+
fi
|
|
9
|
+
ssh "$@"
|
|
10
|
+
status=$?
|
|
11
|
+
printf '%s\n' "$status" > "$status_file"
|
|
12
|
+
exit "$status"
|
|
@@ -14,7 +14,7 @@ from pathlib import Path
|
|
|
14
14
|
import click
|
|
15
15
|
from click.core import ParameterSource
|
|
16
16
|
|
|
17
|
-
from bdbackup import __version__
|
|
17
|
+
from bdbackup import __version__, copy_runner
|
|
18
18
|
from bdbackup.backends import BackupError, setup_logging
|
|
19
19
|
from bdbackup.config import Config, ConfigError, Job, build_backend
|
|
20
20
|
from bdbackup.filebackup import FileBackup
|
|
@@ -24,10 +24,14 @@ from bdbackup.gfs import structure as gfs_structure
|
|
|
24
24
|
from bdbackup.gfs.stages import fed_first_stages
|
|
25
25
|
from bdbackup.history import History, HistoryError
|
|
26
26
|
from bdbackup.metrics_command import run_metrics
|
|
27
|
+
from bdbackup.mongodb.pbm import PBM
|
|
28
|
+
from bdbackup.mongodb.restore import describe_unit as describe_pbm_unit
|
|
29
|
+
from bdbackup.mongodb.restore import restore_lines as pbm_restore_lines
|
|
27
30
|
from bdbackup.mysql import MySQLBackup, XtraBackup
|
|
28
31
|
from bdbackup.postgres.pgbackrest import ExportProgress
|
|
29
32
|
from bdbackup.postgres.restore import describe_unit, restore_lines
|
|
30
33
|
from bdbackup.recovery import backup_restore_info, restore_record, suggested_destination
|
|
34
|
+
from bdbackup.ssh_copy import CopySettings
|
|
31
35
|
from bdbackup.templates import TemplateError
|
|
32
36
|
from bdbackup.utils import process_lock
|
|
33
37
|
from bdbackup.validation import validate_config
|
|
@@ -58,7 +62,8 @@ def config_option(**kwargs):
|
|
|
58
62
|
def main(log_level: str) -> None:
|
|
59
63
|
"""Backups by design.
|
|
60
64
|
|
|
61
|
-
File
|
|
65
|
+
File, MySQL, MariaDB, PostgreSQL and MongoDB backups with verification,
|
|
66
|
+
retention, and guided recovery.
|
|
62
67
|
"""
|
|
63
68
|
setup_logging(getattr(logging, log_level.upper(), logging.INFO))
|
|
64
69
|
|
|
@@ -105,14 +110,23 @@ def _history_config(path: Path | None) -> Config:
|
|
|
105
110
|
return config
|
|
106
111
|
|
|
107
112
|
|
|
108
|
-
def _tracked_backup(
|
|
113
|
+
def _tracked_backup(
|
|
114
|
+
config, name, backup_type, action, restore_info=None, *,
|
|
115
|
+
encrypted=False, copy: CopySettings | None = None,
|
|
116
|
+
):
|
|
109
117
|
if config.history:
|
|
110
118
|
return History(config.history).run(
|
|
111
|
-
name, backup_type, action, restore_info, encrypted=encrypted,
|
|
119
|
+
name, backup_type, action, restore_info, encrypted=encrypted, copy=copy,
|
|
112
120
|
)
|
|
113
121
|
return action()
|
|
114
122
|
|
|
115
123
|
|
|
124
|
+
def _run_copy(config: Config, job: Job) -> int:
|
|
125
|
+
if job.copy is None:
|
|
126
|
+
return EXIT_OK
|
|
127
|
+
return copy_runner.run_job(History(config.history), job.name, job.copy, _echo)
|
|
128
|
+
|
|
129
|
+
|
|
116
130
|
def _protect_history(backend, config):
|
|
117
131
|
if config.history and isinstance(backend, FileBackup):
|
|
118
132
|
database = config.history.database
|
|
@@ -153,6 +167,11 @@ def _handle_errors(func, *args, **kwargs) -> int:
|
|
|
153
167
|
return code if isinstance(code, int) else EXIT_OK
|
|
154
168
|
|
|
155
169
|
|
|
170
|
+
def _dry_copy(job: Job) -> None:
|
|
171
|
+
if job.copy is not None:
|
|
172
|
+
_echo(f"Dry run; configured copy: {job.copy.destination} ({job.copy.method})")
|
|
173
|
+
|
|
174
|
+
|
|
156
175
|
def _dry_run(config: Config, job: Job, incremental: bool) -> None:
|
|
157
176
|
"""Report what a run of ``job`` would do; run no tool and write nothing."""
|
|
158
177
|
backend = build_backend(job)
|
|
@@ -162,6 +181,9 @@ def _dry_run(config: Config, job: Job, incremental: bool) -> None:
|
|
|
162
181
|
_echo(f"Dry run; would create: {backend.tar_filename}")
|
|
163
182
|
elif isinstance(backend, MySQLBackup):
|
|
164
183
|
_echo(f"Dry run; would dump {backend.selection()} into {backend.out_dir}")
|
|
184
|
+
elif isinstance(backend, PBM):
|
|
185
|
+
_echo(f"Dry run; would take a {backend.backup_type} PBM backup and export it into "
|
|
186
|
+
f"{backend.out_dir}")
|
|
165
187
|
elif isinstance(backend, XtraBackup) and incremental:
|
|
166
188
|
_echo(f"Dry run; would take an incremental of {backend.incremental_parent()} "
|
|
167
189
|
f"under {backend.backup_root}")
|
|
@@ -169,6 +191,7 @@ def _dry_run(config: Config, job: Job, incremental: bool) -> None:
|
|
|
169
191
|
_echo(f"Dry run; would take a full backup under {backend.backup_root}")
|
|
170
192
|
else:
|
|
171
193
|
raise click.UsageError(f"--dry-run is not supported for job type {job.type!r}")
|
|
194
|
+
_dry_copy(job)
|
|
172
195
|
|
|
173
196
|
|
|
174
197
|
@dataclass
|
|
@@ -307,13 +330,34 @@ def _run_pgbackrest(
|
|
|
307
330
|
began.append(_now())
|
|
308
331
|
return engine.export(full, verify=verify, progress=outcome.progress)
|
|
309
332
|
|
|
310
|
-
result = _tracked_backup(config, job.name, "pgbackrest-full", export, info)
|
|
333
|
+
result = _tracked_backup(config, job.name, "pgbackrest-full", export, info, copy=job.copy)
|
|
311
334
|
outcome.result = "exported"
|
|
312
335
|
outcome.facts = _export_facts(full, result, outcome.progress, began[0])
|
|
313
336
|
_echo(f"Job {job.name}: {result.path}")
|
|
314
337
|
return EXIT_OK
|
|
315
338
|
|
|
316
339
|
|
|
340
|
+
def _run_pgbackrest_job(
|
|
341
|
+
config: Config, job: Job, *, verify: bool, dry_run: bool, outcome: _Outcome
|
|
342
|
+
) -> int:
|
|
343
|
+
code = _run_pgbackrest(config, job, verify=verify, dry_run=dry_run, outcome=outcome)
|
|
344
|
+
if dry_run:
|
|
345
|
+
_dry_copy(job)
|
|
346
|
+
return code
|
|
347
|
+
if code != EXIT_OK or job.copy is None:
|
|
348
|
+
return code
|
|
349
|
+
|
|
350
|
+
# The export lock is released. Keep its facts and report any copy-phase failure.
|
|
351
|
+
export_result = outcome.result
|
|
352
|
+
outcome.result = "copy_failed"
|
|
353
|
+
code = _run_copy(config, job)
|
|
354
|
+
if code == EXIT_OK:
|
|
355
|
+
outcome.result = export_result
|
|
356
|
+
elif code == EXIT_LOCKED:
|
|
357
|
+
outcome.result = "copy_deferred"
|
|
358
|
+
return code
|
|
359
|
+
|
|
360
|
+
|
|
317
361
|
@main.command(name="run")
|
|
318
362
|
@config_option(required=True)
|
|
319
363
|
@click.option("-j", "--job", "job_name", help="Run this configured job.")
|
|
@@ -404,7 +448,7 @@ def run(
|
|
|
404
448
|
outcome = _Outcome()
|
|
405
449
|
with nullcontext() if dry_run else _last_run(config, job, outcome):
|
|
406
450
|
ctx.exit(_handle_errors(
|
|
407
|
-
|
|
451
|
+
_run_pgbackrest_job, config, job, verify=verify, dry_run=dry_run, outcome=outcome
|
|
408
452
|
))
|
|
409
453
|
if dry_run:
|
|
410
454
|
return _handle_errors(_dry_run, config, job, incremental)
|
|
@@ -412,6 +456,9 @@ def run(
|
|
|
412
456
|
|
|
413
457
|
def _create():
|
|
414
458
|
backend = build_backend(job)
|
|
459
|
+
if isinstance(backend, PBM):
|
|
460
|
+
# PBM verifies its temporary tar before publication.
|
|
461
|
+
return backend.backup(job.name, verify=verify, restore_info=info)
|
|
415
462
|
_protect_history(backend, config)
|
|
416
463
|
info.update(backup_restore_info(backend))
|
|
417
464
|
result = (
|
|
@@ -425,13 +472,18 @@ def run(
|
|
|
425
472
|
return result
|
|
426
473
|
|
|
427
474
|
backup_type = job.type
|
|
475
|
+
guard = nullcontext()
|
|
428
476
|
if job.type == "xtrabackup":
|
|
429
477
|
backup_type = "xtrabackup-incremental" if incremental else "xtrabackup-full"
|
|
478
|
+
elif job.type == "pbm":
|
|
479
|
+
backup_type = f"pbm-{job.params.get('backup_type', 'logical')}"
|
|
480
|
+
guard = process_lock(Path(f"{config.history.database}.pbm-{job.name}.lock"))
|
|
430
481
|
try:
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
482
|
+
with guard:
|
|
483
|
+
result = _tracked_backup(
|
|
484
|
+
config, job.name, backup_type, _create, info,
|
|
485
|
+
encrypted=job.params.get("encrypt") is True, copy=job.copy,
|
|
486
|
+
)
|
|
435
487
|
except BlockingIOError as exc:
|
|
436
488
|
logger.error("Job %r locked: %s", job.name, exc)
|
|
437
489
|
ctx.exit(EXIT_LOCKED)
|
|
@@ -439,7 +491,7 @@ def run(
|
|
|
439
491
|
logger.error("Job %r failed: %s", job.name, exc)
|
|
440
492
|
ctx.exit(EXIT_BACKUP_FAILED)
|
|
441
493
|
_echo(f"Job {job.name}: {result.path}")
|
|
442
|
-
|
|
494
|
+
ctx.exit(_handle_errors(_run_copy, config, job))
|
|
443
495
|
|
|
444
496
|
|
|
445
497
|
def _restore_mode(config_path, backup_id, job, yes, dst, archive, backup, root, binary,
|
|
@@ -469,11 +521,14 @@ def _restore_mode(config_path, backup_id, job, yes, dst, archive, backup, root,
|
|
|
469
521
|
|
|
470
522
|
|
|
471
523
|
def _echo_restore_command(directory: Path) -> None:
|
|
472
|
-
"""Print the
|
|
524
|
+
"""Print the operator steps for an extracted pgBackRest or PBM unit."""
|
|
473
525
|
facts = describe_unit(directory)
|
|
474
526
|
if facts is not None:
|
|
475
527
|
for line in restore_lines(facts, directory.expanduser().absolute()):
|
|
476
528
|
_echo(line)
|
|
529
|
+
elif (pbm_facts := describe_pbm_unit(directory)) is not None:
|
|
530
|
+
for line in pbm_restore_lines(pbm_facts):
|
|
531
|
+
_echo(line)
|
|
477
532
|
|
|
478
533
|
|
|
479
534
|
@main.command()
|
|
@@ -589,7 +644,7 @@ def restore(
|
|
|
589
644
|
_echo(f"Prepared recovery directory: {restored}")
|
|
590
645
|
else:
|
|
591
646
|
_echo(f"Restored to: {restored}")
|
|
592
|
-
if record.backup_type
|
|
647
|
+
if record.backup_type in {"pgbackrest-full", "pbm-logical", "pbm-physical"}:
|
|
593
648
|
_echo_restore_command(restored)
|
|
594
649
|
|
|
595
650
|
return _handle_errors(_run)
|
|
@@ -621,16 +676,25 @@ def history_cmd(config_path: Path, job: str | None, successful: bool,
|
|
|
621
676
|
records = history.records(job=job, successful=successful)
|
|
622
677
|
suffixes = gfs_store.listing_suffixes(history)
|
|
623
678
|
known = gfs_store.places(history)
|
|
679
|
+
deliveries = {delivery.record_id: delivery for delivery in history.deliveries(job=job)}
|
|
624
680
|
if not records:
|
|
625
681
|
_echo("No backup history found.")
|
|
626
682
|
for record in records:
|
|
627
683
|
available = "available" if gfs_store.available(record, known) else "unavailable"
|
|
684
|
+
# A backup can finish between the records and deliveries reads.
|
|
685
|
+
delivery = deliveries.get(record.id) if record.status == "success" else None
|
|
686
|
+
copy_suffix = ""
|
|
687
|
+
if delivery is not None:
|
|
688
|
+
copy_suffix = f" | copy {delivery.status}"
|
|
689
|
+
if delivery.failure_class is not None:
|
|
690
|
+
copy_suffix += f" ({delivery.failure_class})"
|
|
628
691
|
_echo(
|
|
629
692
|
f"{record.id}: {record.job_name} | {record.backup_type} | {record.started_at} | "
|
|
630
693
|
f"{record.status} | {available} | "
|
|
631
694
|
f"{'encrypted' if record.encrypted else 'unencrypted'} | {record.path or '-'}"
|
|
632
695
|
f" | unit {record.unit or '-'}"
|
|
633
696
|
f"{suffixes.get(record.unit, '') if record.unit else ''}"
|
|
697
|
+
f"{copy_suffix}"
|
|
634
698
|
)
|
|
635
699
|
|
|
636
700
|
_handle_errors(_checksums if create_checksum else _listing)
|
|
@@ -12,6 +12,10 @@ from bdbackup.filebackup import FileBackup
|
|
|
12
12
|
from bdbackup.gfs.stages import check_gfs_config, parse_gfs_job, pgbackrest_first_stage
|
|
13
13
|
from bdbackup.history import HistorySettings
|
|
14
14
|
from bdbackup.metrics.settings import MetricsSettings, parse_metrics
|
|
15
|
+
from bdbackup.mongodb.pbm import PBM
|
|
16
|
+
from bdbackup.mysql.mysqldump import MySQLBackup
|
|
17
|
+
from bdbackup.postgres.pgbackrest import PgBackRest
|
|
18
|
+
from bdbackup.ssh_copy import CopySettings, parse_copy_settings, safe_artifact_name
|
|
15
19
|
from bdbackup.utils import lexical_path, real_path
|
|
16
20
|
|
|
17
21
|
|
|
@@ -24,6 +28,7 @@ class Job:
|
|
|
24
28
|
params: dict[str, Any]
|
|
25
29
|
restore_root: Path | None = None
|
|
26
30
|
active: bool = True
|
|
31
|
+
copy: CopySettings | None = None
|
|
27
32
|
|
|
28
33
|
|
|
29
34
|
class ConfigError(Exception):
|
|
@@ -32,6 +37,9 @@ class ConfigError(Exception):
|
|
|
32
37
|
|
|
33
38
|
# Keys removed in 0.7.0, by the job types that had them (None: every type).
|
|
34
39
|
_REMOVED_KEYS = {"schedule": None, "apply": {"gfs"}, "jobs": {"mysqldump"}}
|
|
40
|
+
_COPY_ENGINES = {"mysqldump": MySQLBackup, "pgbackrest": PgBackRest, "pbm": PBM}
|
|
41
|
+
_PBM_PATHS = ("storage_path", "out_dir")
|
|
42
|
+
_PBM_KEYS = frozenset((*_PBM_PATHS, "backup_type", "binary", "mongodb_uri"))
|
|
35
43
|
|
|
36
44
|
|
|
37
45
|
def supported_types() -> set[str]:
|
|
@@ -43,8 +51,8 @@ class Config:
|
|
|
43
51
|
"""Load and validate a TOML job configuration file.
|
|
44
52
|
|
|
45
53
|
With ``lexical`` the paths of the shares (gfs stages, engine outputs, ``repo_path``,
|
|
46
|
-
``out_dir`` and the restore roots) are normalised from their text
|
|
47
|
-
|
|
54
|
+
``storage_path``, ``out_dir`` and the restore roots) are normalised from their text without
|
|
55
|
+
filesystem access on a share that may hang. ``bdbackup metrics`` reads its
|
|
48
56
|
configuration so; a path written through a link then stays as written. The configuration
|
|
49
57
|
file itself and ``[history] database`` are local and always resolved.
|
|
50
58
|
"""
|
|
@@ -89,6 +97,7 @@ class Config:
|
|
|
89
97
|
raise ConfigError("[metrics] requires a [history] section")
|
|
90
98
|
self.metrics = settings
|
|
91
99
|
|
|
100
|
+
destinations: dict[tuple[str, str | None, str], str] = {}
|
|
92
101
|
for name, section in data.items():
|
|
93
102
|
if not isinstance(section, dict):
|
|
94
103
|
raise ConfigError(f"Job {name!r} must be a table")
|
|
@@ -105,6 +114,16 @@ class Config:
|
|
|
105
114
|
active = section.pop("active", True)
|
|
106
115
|
if not isinstance(active, bool):
|
|
107
116
|
raise ConfigError(f"Job {name!r}: active must be true or false")
|
|
117
|
+
copy = None
|
|
118
|
+
if "copy" in section:
|
|
119
|
+
try:
|
|
120
|
+
copy, destination = self._load_copy(job_type, section)
|
|
121
|
+
if destination in destinations:
|
|
122
|
+
other = destinations[destination]
|
|
123
|
+
raise ValueError(f"copy.destination is already used by job {other!r}")
|
|
124
|
+
destinations[destination] = name
|
|
125
|
+
except ValueError as exc:
|
|
126
|
+
raise ConfigError(f"Job {name!r}: {exc}") from exc
|
|
108
127
|
if job_type == "gfs":
|
|
109
128
|
try:
|
|
110
129
|
params = parse_gfs_job(section, self.path.parent, self._resolve)
|
|
@@ -121,28 +140,31 @@ class Config:
|
|
|
121
140
|
raise ConfigError(f"Job {name!r}: restore_root requires a [history] section")
|
|
122
141
|
restore_root = self._resolve(self.path.parent / Path(value).expanduser())
|
|
123
142
|
params = {k: v for k, v in section.items() if k not in {"type", "restore_root"}}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
+
if job_type == "pbm":
|
|
144
|
+
self._check_pbm_settings(name, params)
|
|
145
|
+
else:
|
|
146
|
+
# Config paths are relative to the config file; file-template entries
|
|
147
|
+
# and excludes remain relative to the explicitly selected source path.
|
|
148
|
+
for key in (
|
|
149
|
+
"template_filename",
|
|
150
|
+
"backup_dst",
|
|
151
|
+
"chdir",
|
|
152
|
+
"out_dir",
|
|
153
|
+
"backup_root",
|
|
154
|
+
"encrypt_key_file",
|
|
155
|
+
"repo_path",
|
|
156
|
+
"config_file",
|
|
157
|
+
):
|
|
158
|
+
if key in params:
|
|
159
|
+
try:
|
|
160
|
+
params[key] = self.path.parent / Path(params[key]).expanduser()
|
|
161
|
+
except TypeError as exc:
|
|
162
|
+
raise ConfigError(f"Job {name!r}: {key} must be a path string") from exc
|
|
163
|
+
if self._resolve is lexical_path:
|
|
164
|
+
params[key] = lexical_path(params[key])
|
|
143
165
|
self.jobs[name] = Job(
|
|
144
166
|
name=name, type=job_type, params=params, restore_root=restore_root,
|
|
145
|
-
active=active,
|
|
167
|
+
active=active, copy=copy,
|
|
146
168
|
)
|
|
147
169
|
|
|
148
170
|
if any(job.type == "gfs" for job in self.jobs.values()):
|
|
@@ -151,6 +173,30 @@ class Config:
|
|
|
151
173
|
except ValueError as exc:
|
|
152
174
|
raise ConfigError(str(exc)) from exc
|
|
153
175
|
self._check_pgbackrest()
|
|
176
|
+
self._check_pbm_layouts()
|
|
177
|
+
|
|
178
|
+
def _load_copy(
|
|
179
|
+
self, job_type: str, section: dict[str, Any],
|
|
180
|
+
) -> tuple[CopySettings, tuple[str, str | None, str]]:
|
|
181
|
+
if job_type != "file" and (
|
|
182
|
+
job_type not in _COPY_ENGINES
|
|
183
|
+
or get_engine(job_type).backend is not _COPY_ENGINES[job_type]
|
|
184
|
+
):
|
|
185
|
+
raise ValueError(
|
|
186
|
+
"copy is supported only by built-in file, mysqldump, pgbackrest and pbm jobs"
|
|
187
|
+
)
|
|
188
|
+
if self.history is None:
|
|
189
|
+
raise ValueError("copy requires a [history] section")
|
|
190
|
+
if job_type == "file":
|
|
191
|
+
if section.get("timestamp") is not True:
|
|
192
|
+
raise ValueError("copy requires timestamp = true")
|
|
193
|
+
destination = section.get("backup_dst")
|
|
194
|
+
if not isinstance(destination, str) or not safe_artifact_name(Path(destination).name):
|
|
195
|
+
raise ValueError("copy requires a shell-safe backup_dst name")
|
|
196
|
+
if job_type == "pgbackrest" and not safe_artifact_name(section.get("stanza")):
|
|
197
|
+
raise ValueError("copy requires a shell-safe stanza name")
|
|
198
|
+
# Mysqldump percent-encodes the database label before using it in the archive name.
|
|
199
|
+
return parse_copy_settings(section.pop("copy"), self.path.parent, self._resolve)
|
|
154
200
|
|
|
155
201
|
def _check_pgbackrest(self) -> None:
|
|
156
202
|
"""Rules for pgbackrest jobs; they follow ``check_gfs_config``, which reads the stages."""
|
|
@@ -227,6 +273,50 @@ class Config:
|
|
|
227
273
|
if any(path.is_relative_to(repo) for path in stage.paths):
|
|
228
274
|
raise ConfigError(f"Job {name!r}: a gfs stage path must be outside repo_path")
|
|
229
275
|
|
|
276
|
+
def _check_pbm_settings(self, name: str, params: dict[str, Any]) -> None:
|
|
277
|
+
if self.history is None:
|
|
278
|
+
raise ConfigError(f"Job {name!r}: pbm jobs require a [history] section")
|
|
279
|
+
if not safe_artifact_name(name):
|
|
280
|
+
raise ConfigError(f"Job {name!r}: pbm job name must be shell-safe")
|
|
281
|
+
unknown = params.keys() - _PBM_KEYS
|
|
282
|
+
if unknown:
|
|
283
|
+
raise ConfigError(f"Job {name!r}: unknown pbm key(s): {', '.join(sorted(unknown))}")
|
|
284
|
+
for key in _PBM_PATHS:
|
|
285
|
+
if key not in params:
|
|
286
|
+
raise ConfigError(f"Job {name!r}: {key} is required for pbm")
|
|
287
|
+
value = params[key]
|
|
288
|
+
if not isinstance(value, str) or not value.strip():
|
|
289
|
+
raise ConfigError(f"Job {name!r}: {key} must be a nonempty path string")
|
|
290
|
+
params[key] = self._resolve(self.path.parent / Path(value).expanduser())
|
|
291
|
+
if params.get("backup_type", "logical") not in ("logical", "physical"):
|
|
292
|
+
raise ConfigError(f"Job {name!r}: backup_type must be logical or physical")
|
|
293
|
+
for key in ("binary", "mongodb_uri"):
|
|
294
|
+
if key in params and (not isinstance(params[key], str) or not params[key].strip()):
|
|
295
|
+
raise ConfigError(f"Job {name!r}: {key} must be a nonempty string")
|
|
296
|
+
|
|
297
|
+
def _check_pbm_layouts(self) -> None:
|
|
298
|
+
stage_paths = [
|
|
299
|
+
("gfs stage path", path)
|
|
300
|
+
for job in self.jobs.values() if job.type == "gfs"
|
|
301
|
+
for stage in job.params["stage"]
|
|
302
|
+
for path in stage.paths
|
|
303
|
+
]
|
|
304
|
+
for name, job in self.jobs.items():
|
|
305
|
+
if job.type != "pbm":
|
|
306
|
+
continue
|
|
307
|
+
storage = job.params["storage_path"]
|
|
308
|
+
for key, path in (
|
|
309
|
+
("out_dir", job.params["out_dir"]),
|
|
310
|
+
("[history] database", self.history.database),
|
|
311
|
+
("[history] restore_root", self.history.restore_root),
|
|
312
|
+
("restore_root", job.restore_root),
|
|
313
|
+
*stage_paths,
|
|
314
|
+
):
|
|
315
|
+
if path is not None and (
|
|
316
|
+
path.is_relative_to(storage) or storage.is_relative_to(path)
|
|
317
|
+
):
|
|
318
|
+
raise ConfigError(f"Job {name!r}: {key} and storage_path must not overlap")
|
|
319
|
+
|
|
230
320
|
def get(self, name: str) -> Job:
|
|
231
321
|
if name not in self.jobs:
|
|
232
322
|
raise ConfigError(f"Job {name!r} not found in {self.path}")
|