bdbackup 0.7.2__tar.gz → 0.7.3__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.2 → bdbackup-0.7.3}/PKG-INFO +42 -9
- {bdbackup-0.7.2 → bdbackup-0.7.3}/README.md +41 -8
- {bdbackup-0.7.2 → bdbackup-0.7.3}/bdbackup/cli.py +187 -37
- {bdbackup-0.7.2 → bdbackup-0.7.3}/bdbackup/config.py +34 -10
- {bdbackup-0.7.2 → bdbackup-0.7.3}/bdbackup/engines.py +10 -1
- {bdbackup-0.7.2 → bdbackup-0.7.3}/bdbackup/gfs/runner.py +16 -2
- {bdbackup-0.7.2 → bdbackup-0.7.3}/bdbackup/gfs/stages.py +28 -12
- {bdbackup-0.7.2 → bdbackup-0.7.3}/bdbackup/history.py +92 -5
- bdbackup-0.7.3/bdbackup/metrics/__init__.py +5 -0
- bdbackup-0.7.3/bdbackup/metrics/collector.py +152 -0
- bdbackup-0.7.3/bdbackup/metrics/data.py +97 -0
- bdbackup-0.7.3/bdbackup/metrics/families.py +96 -0
- bdbackup-0.7.3/bdbackup/metrics/gfs.py +124 -0
- bdbackup-0.7.3/bdbackup/metrics/jobs.py +103 -0
- bdbackup-0.7.3/bdbackup/metrics/probe.py +179 -0
- bdbackup-0.7.3/bdbackup/metrics/registry.py +55 -0
- bdbackup-0.7.3/bdbackup/metrics/render.py +82 -0
- bdbackup-0.7.3/bdbackup/metrics/run.py +246 -0
- bdbackup-0.7.3/bdbackup/metrics/settings.py +35 -0
- bdbackup-0.7.3/bdbackup/metrics/units.py +75 -0
- bdbackup-0.7.3/bdbackup/metrics/write.py +31 -0
- bdbackup-0.7.3/bdbackup/metrics_command.py +220 -0
- bdbackup-0.7.3/bdbackup/postgres/metrics.py +263 -0
- {bdbackup-0.7.2 → bdbackup-0.7.3}/bdbackup/postgres/pgbackrest.py +96 -13
- {bdbackup-0.7.2 → bdbackup-0.7.3}/bdbackup/utils.py +14 -0
- {bdbackup-0.7.2 → bdbackup-0.7.3}/bdbackup/validation.py +18 -0
- {bdbackup-0.7.2 → bdbackup-0.7.3}/config.toml.example +19 -2
- bdbackup-0.7.3/docs/README_ENGINES.md +115 -0
- {bdbackup-0.7.2 → bdbackup-0.7.3}/docs/README_GFS.md +16 -1
- bdbackup-0.7.3/docs/README_METRICS.md +358 -0
- {bdbackup-0.7.2 → bdbackup-0.7.3}/docs/README_PGBACKREST.md +47 -4
- {bdbackup-0.7.2 → bdbackup-0.7.3}/pyproject.toml +1 -1
- bdbackup-0.7.3/scripts/docker/nfs-outage.Dockerfile +26 -0
- bdbackup-0.7.3/scripts/integration_nfs_outage.py +381 -0
- {bdbackup-0.7.2 → bdbackup-0.7.3}/scripts/integration_pgbackrest.py +169 -1
- {bdbackup-0.7.2 → bdbackup-0.7.3}/tests/AGENTS.md +19 -8
- {bdbackup-0.7.2 → bdbackup-0.7.3}/tests/pgbackrest_fake.py +53 -8
- bdbackup-0.7.3/tests/test_broken_pipe.py +149 -0
- {bdbackup-0.7.2 → bdbackup-0.7.3}/tests/test_cli_reshape.py +3 -2
- bdbackup-0.7.3/tests/test_config_lexical.py +159 -0
- {bdbackup-0.7.2 → bdbackup-0.7.3}/tests/test_encryption.py +4 -3
- {bdbackup-0.7.2 → bdbackup-0.7.3}/tests/test_gfs_run.py +148 -3
- {bdbackup-0.7.2 → bdbackup-0.7.3}/tests/test_gfs_store.py +3 -3
- bdbackup-0.7.3/tests/test_last_runs.py +175 -0
- {bdbackup-0.7.2 → bdbackup-0.7.3}/tests/test_ledger.py +1 -1
- bdbackup-0.7.3/tests/test_metrics_collect.py +792 -0
- bdbackup-0.7.3/tests/test_metrics_command.py +336 -0
- bdbackup-0.7.3/tests/test_metrics_config.py +126 -0
- bdbackup-0.7.3/tests/test_metrics_hang.py +161 -0
- bdbackup-0.7.3/tests/test_metrics_phases.py +170 -0
- bdbackup-0.7.3/tests/test_metrics_probe.py +427 -0
- bdbackup-0.7.3/tests/test_metrics_render.py +217 -0
- bdbackup-0.7.3/tests/test_metrics_write.py +209 -0
- {bdbackup-0.7.2 → bdbackup-0.7.3}/tests/test_pgbackrest_cli.py +317 -1
- {bdbackup-0.7.2 → bdbackup-0.7.3}/tests/test_pgbackrest_engine.py +131 -1
- {bdbackup-0.7.2 → bdbackup-0.7.3}/tests/test_pgbackrest_export.py +169 -1
- bdbackup-0.7.3/tests/test_pgbackrest_metrics.py +708 -0
- bdbackup-0.7.3/tests/test_validate_metrics.py +129 -0
- bdbackup-0.7.2/docs/README_ENGINES.md +0 -64
- {bdbackup-0.7.2 → bdbackup-0.7.3}/.gitignore +0 -0
- {bdbackup-0.7.2 → bdbackup-0.7.3}/LICENSE +0 -0
- {bdbackup-0.7.2 → bdbackup-0.7.3}/bdbackup/__init__.py +0 -0
- {bdbackup-0.7.2 → bdbackup-0.7.3}/bdbackup/backends.py +0 -0
- {bdbackup-0.7.2 → bdbackup-0.7.3}/bdbackup/filebackup.py +0 -0
- {bdbackup-0.7.2 → bdbackup-0.7.3}/bdbackup/gfs/__init__.py +0 -0
- {bdbackup-0.7.2 → bdbackup-0.7.3}/bdbackup/gfs/actions.py +0 -0
- {bdbackup-0.7.2 → bdbackup-0.7.3}/bdbackup/gfs/policy.py +0 -0
- {bdbackup-0.7.2 → bdbackup-0.7.3}/bdbackup/gfs/store.py +0 -0
- {bdbackup-0.7.2 → bdbackup-0.7.3}/bdbackup/gfs/structure.py +0 -0
- {bdbackup-0.7.2 → bdbackup-0.7.3}/bdbackup/ledger.py +0 -0
- {bdbackup-0.7.2 → bdbackup-0.7.3}/bdbackup/mysql/__init__.py +0 -0
- {bdbackup-0.7.2 → bdbackup-0.7.3}/bdbackup/mysql/helpers.py +0 -0
- {bdbackup-0.7.2 → bdbackup-0.7.3}/bdbackup/mysql/mysqldump.py +0 -0
- {bdbackup-0.7.2 → bdbackup-0.7.3}/bdbackup/mysql/xtrabackup.py +0 -0
- {bdbackup-0.7.2 → bdbackup-0.7.3}/bdbackup/postgres/__init__.py +0 -0
- {bdbackup-0.7.2 → bdbackup-0.7.3}/bdbackup/postgres/repository.py +0 -0
- {bdbackup-0.7.2 → bdbackup-0.7.3}/bdbackup/postgres/restore.py +0 -0
- {bdbackup-0.7.2 → bdbackup-0.7.3}/bdbackup/recovery.py +0 -0
- {bdbackup-0.7.2 → bdbackup-0.7.3}/bdbackup/templates/__init__.py +0 -0
- {bdbackup-0.7.2 → bdbackup-0.7.3}/bdbackup/templates/_matching.py +0 -0
- {bdbackup-0.7.2 → bdbackup-0.7.3}/bdbackup/templates/python_dev.py +0 -0
- {bdbackup-0.7.2 → bdbackup-0.7.3}/contrib/systemd/bdbackup-incremental@.service +0 -0
- {bdbackup-0.7.2 → bdbackup-0.7.3}/contrib/systemd/bdbackup-incremental@.timer +0 -0
- {bdbackup-0.7.2 → bdbackup-0.7.3}/contrib/systemd/bdbackup@.service +0 -0
- {bdbackup-0.7.2 → bdbackup-0.7.3}/contrib/systemd/bdbackup@.timer +0 -0
- {bdbackup-0.7.2 → bdbackup-0.7.3}/docs/README_FILE.md +0 -0
- {bdbackup-0.7.2 → bdbackup-0.7.3}/docs/README_MYSQLDUMP.md +0 -0
- {bdbackup-0.7.2 → bdbackup-0.7.3}/docs/README_SYSTEMD.md +0 -0
- {bdbackup-0.7.2 → bdbackup-0.7.3}/docs/README_XTRABACKUP.md +0 -0
- {bdbackup-0.7.2 → bdbackup-0.7.3}/scripts/check_release.py +0 -0
- {bdbackup-0.7.2 → bdbackup-0.7.3}/scripts/docker/pgbackrest.Dockerfile +0 -0
- {bdbackup-0.7.2 → bdbackup-0.7.3}/scripts/integration_mysql.py +0 -0
- {bdbackup-0.7.2 → bdbackup-0.7.3}/scripts/integration_physical.py +0 -0
- {bdbackup-0.7.2 → bdbackup-0.7.3}/scripts/smoke_install.py +0 -0
- {bdbackup-0.7.2 → bdbackup-0.7.3}/template.txt +0 -0
- {bdbackup-0.7.2 → bdbackup-0.7.3}/tests/__init__.py +0 -0
- {bdbackup-0.7.2 → bdbackup-0.7.3}/tests/conftest.py +0 -0
- {bdbackup-0.7.2 → bdbackup-0.7.3}/tests/test_architecture.py +0 -0
- {bdbackup-0.7.2 → bdbackup-0.7.3}/tests/test_correctness.py +0 -0
- {bdbackup-0.7.2 → bdbackup-0.7.3}/tests/test_engine_conditions.py +0 -0
- {bdbackup-0.7.2 → bdbackup-0.7.3}/tests/test_engines.py +0 -0
- {bdbackup-0.7.2 → bdbackup-0.7.3}/tests/test_gfs_config.py +0 -0
- {bdbackup-0.7.2 → bdbackup-0.7.3}/tests/test_gfs_init.py +0 -0
- {bdbackup-0.7.2 → bdbackup-0.7.3}/tests/test_gfs_policy.py +0 -0
- {bdbackup-0.7.2 → bdbackup-0.7.3}/tests/test_helpers.py +0 -0
- {bdbackup-0.7.2 → bdbackup-0.7.3}/tests/test_history.py +0 -0
- {bdbackup-0.7.2 → bdbackup-0.7.3}/tests/test_import.py +0 -0
- {bdbackup-0.7.2 → bdbackup-0.7.3}/tests/test_performance.py +0 -0
- {bdbackup-0.7.2 → bdbackup-0.7.3}/tests/test_pgbackrest_repository.py +0 -0
- {bdbackup-0.7.2 → bdbackup-0.7.3}/tests/test_pgbackrest_restore.py +0 -0
- {bdbackup-0.7.2 → bdbackup-0.7.3}/tests/test_release_fixes.py +0 -0
- {bdbackup-0.7.2 → bdbackup-0.7.3}/tests/test_run_selector.py +0 -0
- {bdbackup-0.7.2 → bdbackup-0.7.3}/tests/test_safety_nets.py +0 -0
- {bdbackup-0.7.2 → bdbackup-0.7.3}/tests/test_security.py +0 -0
- {bdbackup-0.7.2 → bdbackup-0.7.3}/tests/test_systemd_units.py +0 -0
- {bdbackup-0.7.2 → bdbackup-0.7.3}/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.3
|
|
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
|
|
@@ -65,6 +65,10 @@ run from cron.
|
|
|
65
65
|
SHA-256 checksums in SQLite.
|
|
66
66
|
- [Configuration validation](#validate-configuration-and-permissions) of
|
|
67
67
|
settings, filesystem permissions and MySQL grants, without running a backup.
|
|
68
|
+
- [Prometheus metrics](https://github.com/ayder/bdbackup/blob/master/docs/README_METRICS.md): a read-only
|
|
69
|
+
`bdbackup metrics` writes a textfile for node_exporter and PMM with the last run of each
|
|
70
|
+
pgbackrest and gfs job, the history, the GFS stages, the destinations and the pgBackRest
|
|
71
|
+
repository.
|
|
68
72
|
- [Custom backup engines](https://github.com/ayder/bdbackup/blob/master/docs/README_ENGINES.md) as plugins.
|
|
69
73
|
|
|
70
74
|
## Documentation
|
|
@@ -76,7 +80,8 @@ run from cron.
|
|
|
76
80
|
| [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
81
|
| [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 |
|
|
78
82
|
| [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 |
|
|
79
|
-
| [
|
|
83
|
+
| [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, alerting, hangs and outages, known limits |
|
|
84
|
+
| [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 |
|
|
80
85
|
| [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 |
|
|
81
86
|
| [Annotated configuration](https://github.com/ayder/bdbackup/blob/master/config.toml.example) | every config key with a comment |
|
|
82
87
|
|
|
@@ -124,7 +129,7 @@ pip install -e ".[dev]"
|
|
|
124
129
|
|
|
125
130
|
## Commands
|
|
126
131
|
|
|
127
|
-
`bdbackup` has
|
|
132
|
+
`bdbackup` has four commands; everything else is an option:
|
|
128
133
|
|
|
129
134
|
```bash
|
|
130
135
|
bdbackup run -c CONFIG -j JOB [--full | --incremental] [--no-verify] [--dry-run]
|
|
@@ -134,6 +139,7 @@ bdbackup restore -c CONFIG [--backup-id N] [--job JOB] [-y] [-d DIR] [--encrypt
|
|
|
134
139
|
bdbackup restore --archive ARCHIVE -d DIR
|
|
135
140
|
bdbackup restore --backup BACKUP --root ROOT -d DIR [--binary BINARY] [--encrypt-key-file KEY]
|
|
136
141
|
bdbackup history -c CONFIG [--job JOB] [--successful | --create-checksum]
|
|
142
|
+
bdbackup metrics -c CONFIG
|
|
137
143
|
```
|
|
138
144
|
|
|
139
145
|
`-c` is `--config` on every command; `-j` is the short form of `--job` on `run`
|
|
@@ -142,14 +148,17 @@ only (`restore` and `history` take `--job`). `bdbackup` itself takes only
|
|
|
142
148
|
`bdbackup --logging DEBUG run -c config.toml -j files-daily`. Levels: `DEBUG`,
|
|
143
149
|
`INFO`, `WARNING`, `ERROR`.
|
|
144
150
|
|
|
151
|
+
When the program reading a command's output exits early (`bdbackup history -c config.toml | head`),
|
|
152
|
+
the rest of the output is dropped and the command ends quietly with the exit code it would have had.
|
|
153
|
+
|
|
145
154
|
The CLI uses these exit codes:
|
|
146
155
|
|
|
147
156
|
| Code | Meaning |
|
|
148
157
|
|------|---------|
|
|
149
158
|
| 0 | Success |
|
|
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 |
|
|
159
|
+
| 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; for `metrics`, the file was written with an error series or could not be written |
|
|
151
160
|
| 2 | Usage error, an inactive job, or a configuration error found when the config loads or by `--dry-run` |
|
|
152
|
-
| 3 | Lock held; for GFS, another run of the job is in progress or only deferred work remains |
|
|
161
|
+
| 3 | Lock held; for GFS, another run of the job is in progress or only deferred work remains; for `metrics`, another metrics run holds its lock |
|
|
153
162
|
|
|
154
163
|
## Config-driven jobs
|
|
155
164
|
|
|
@@ -189,7 +198,7 @@ config file's directory. Template entries and `exclude` entries resolve against
|
|
|
189
198
|
mysqldump job, set `database = "mydatabase"`; for all databases include
|
|
190
199
|
`--all-databases` in `options`.
|
|
191
200
|
|
|
192
|
-
Except for the optional `[history]` settings, each top-level table is one job;
|
|
201
|
+
Except for the optional `[history]` and `[metrics]` settings, each top-level table is one job;
|
|
193
202
|
its keys (except `type`, `active` and `restore_root`) are passed
|
|
194
203
|
to the backend constructor, so they use Python-style underscores
|
|
195
204
|
(`exclude_templates`). See [config.toml.example](https://github.com/ayder/bdbackup/blob/master/config.toml.example)
|
|
@@ -246,6 +255,14 @@ Times use the cron daemon's timezone, and separate lines do not wait for each
|
|
|
246
255
|
other: leave enough time for backups before GFS. Add `--dry-run` to the GFS line
|
|
247
256
|
until its report looks right.
|
|
248
257
|
|
|
258
|
+
`bdbackup metrics` writes the Prometheus textfile and runs every 10 to 15 minutes, as the
|
|
259
|
+
OS account that owns the history database; see
|
|
260
|
+
[Prometheus metrics](https://github.com/ayder/bdbackup/blob/master/docs/README_METRICS.md):
|
|
261
|
+
|
|
262
|
+
```cron
|
|
263
|
+
*/10 * * * * bdbackup metrics -c /opt/dbs/config.toml
|
|
264
|
+
```
|
|
265
|
+
|
|
249
266
|
xtrabackup jobs can run from systemd timers instead, which also stop the backup
|
|
250
267
|
tool if bdbackup dies and add per-job limits: see
|
|
251
268
|
[Running xtrabackup jobs with systemd timers](https://github.com/ayder/bdbackup/blob/master/docs/README_SYSTEMD.md).
|
|
@@ -362,8 +379,10 @@ missing or was replaced, or `<id>: skipped: unexpected unit` for a physical back
|
|
|
362
379
|
outside its dated layout, and then exits 1. A checksum already recorded is never
|
|
363
380
|
changed. `--create-checksum` cannot be combined with `--successful`. The checksum lives in the `checksum` column of the `backup_runs` table.
|
|
364
381
|
|
|
365
|
-
History uses schema version
|
|
366
|
-
write; bdbackup 0.
|
|
382
|
+
History uses schema version 6, from bdbackup 0.7.3. A database at an older schema upgrades
|
|
383
|
+
on the next write; bdbackup 0.7.2 or earlier refuses a version-6 database. Version 6 adds the
|
|
384
|
+
`last_runs` table: the outcome of the last run of each pgbackrest and gfs job, which
|
|
385
|
+
`bdbackup metrics` reads.
|
|
367
386
|
|
|
368
387
|
History is written before work starts, and success only after the backup and its
|
|
369
388
|
requested verification finish. If history cannot be written, the command fails;
|
|
@@ -436,10 +455,24 @@ python scripts/integration_physical.py percona-encrypted # AES256 + zstd recover
|
|
|
436
455
|
python scripts/integration_physical.py mariadb # mariadb:11.4
|
|
437
456
|
python scripts/integration_pgbackrest.py pg16-2.58 # bdbackup-pgbackrest:16-2.58.0
|
|
438
457
|
python scripts/integration_pgbackrest.py pg18-2.60 # bdbackup-pgbackrest:18-2.60.0
|
|
458
|
+
python scripts/integration_nfs_outage.py # bdbackup-nfs-outage:test, privileged
|
|
439
459
|
```
|
|
440
460
|
|
|
441
461
|
The pgBackRest images have no official source; build them from
|
|
442
|
-
`scripts/docker/pgbackrest.Dockerfile` with the commands in `tests/AGENTS.md`.
|
|
462
|
+
`scripts/docker/pgbackrest.Dockerfile` with the commands in `tests/AGENTS.md`. The NFS
|
|
463
|
+
outage test runs `bdbackup metrics` against a hard NFS mount whose server stops answering. Its
|
|
464
|
+
image installs bdbackup from a wheel built on the host, and the script refuses an image built
|
|
465
|
+
from other sources:
|
|
466
|
+
|
|
467
|
+
```bash
|
|
468
|
+
rm -rf dist && python -m build -q
|
|
469
|
+
docker build -f scripts/docker/nfs-outage.Dockerfile \
|
|
470
|
+
--build-arg SOURCE_HASH="$(python scripts/integration_nfs_outage.py --source-hash)" \
|
|
471
|
+
-t bdbackup-nfs-outage:test dist
|
|
472
|
+
```
|
|
473
|
+
|
|
474
|
+
It runs a container with `--privileged --network none`, so it needs a Linux kernel with an NFS
|
|
475
|
+
server and iptables.
|
|
443
476
|
|
|
444
477
|
Physical recovery returns a prepared data directory; copying it into a server's
|
|
445
478
|
data directory, assigning ownership to the server user, and starting that server
|
|
@@ -31,6 +31,10 @@ run from cron.
|
|
|
31
31
|
SHA-256 checksums in SQLite.
|
|
32
32
|
- [Configuration validation](#validate-configuration-and-permissions) of
|
|
33
33
|
settings, filesystem permissions and MySQL grants, without running a backup.
|
|
34
|
+
- [Prometheus metrics](https://github.com/ayder/bdbackup/blob/master/docs/README_METRICS.md): a read-only
|
|
35
|
+
`bdbackup metrics` writes a textfile for node_exporter and PMM with the last run of each
|
|
36
|
+
pgbackrest and gfs job, the history, the GFS stages, the destinations and the pgBackRest
|
|
37
|
+
repository.
|
|
34
38
|
- [Custom backup engines](https://github.com/ayder/bdbackup/blob/master/docs/README_ENGINES.md) as plugins.
|
|
35
39
|
|
|
36
40
|
## Documentation
|
|
@@ -42,7 +46,8 @@ run from cron.
|
|
|
42
46
|
| [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
47
|
| [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 |
|
|
44
48
|
| [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 |
|
|
45
|
-
| [
|
|
49
|
+
| [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, alerting, hangs and outages, known limits |
|
|
50
|
+
| [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 |
|
|
46
51
|
| [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 |
|
|
47
52
|
| [Annotated configuration](https://github.com/ayder/bdbackup/blob/master/config.toml.example) | every config key with a comment |
|
|
48
53
|
|
|
@@ -90,7 +95,7 @@ pip install -e ".[dev]"
|
|
|
90
95
|
|
|
91
96
|
## Commands
|
|
92
97
|
|
|
93
|
-
`bdbackup` has
|
|
98
|
+
`bdbackup` has four commands; everything else is an option:
|
|
94
99
|
|
|
95
100
|
```bash
|
|
96
101
|
bdbackup run -c CONFIG -j JOB [--full | --incremental] [--no-verify] [--dry-run]
|
|
@@ -100,6 +105,7 @@ bdbackup restore -c CONFIG [--backup-id N] [--job JOB] [-y] [-d DIR] [--encrypt
|
|
|
100
105
|
bdbackup restore --archive ARCHIVE -d DIR
|
|
101
106
|
bdbackup restore --backup BACKUP --root ROOT -d DIR [--binary BINARY] [--encrypt-key-file KEY]
|
|
102
107
|
bdbackup history -c CONFIG [--job JOB] [--successful | --create-checksum]
|
|
108
|
+
bdbackup metrics -c CONFIG
|
|
103
109
|
```
|
|
104
110
|
|
|
105
111
|
`-c` is `--config` on every command; `-j` is the short form of `--job` on `run`
|
|
@@ -108,14 +114,17 @@ only (`restore` and `history` take `--job`). `bdbackup` itself takes only
|
|
|
108
114
|
`bdbackup --logging DEBUG run -c config.toml -j files-daily`. Levels: `DEBUG`,
|
|
109
115
|
`INFO`, `WARNING`, `ERROR`.
|
|
110
116
|
|
|
117
|
+
When the program reading a command's output exits early (`bdbackup history -c config.toml | head`),
|
|
118
|
+
the rest of the output is dropped and the command ends quietly with the exit code it would have had.
|
|
119
|
+
|
|
111
120
|
The CLI uses these exit codes:
|
|
112
121
|
|
|
113
122
|
| Code | Meaning |
|
|
114
123
|
|------|---------|
|
|
115
124
|
| 0 | Success |
|
|
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 |
|
|
125
|
+
| 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; for `metrics`, the file was written with an error series or could not be written |
|
|
117
126
|
| 2 | Usage error, an inactive job, or a configuration error found when the config loads or by `--dry-run` |
|
|
118
|
-
| 3 | Lock held; for GFS, another run of the job is in progress or only deferred work remains |
|
|
127
|
+
| 3 | Lock held; for GFS, another run of the job is in progress or only deferred work remains; for `metrics`, another metrics run holds its lock |
|
|
119
128
|
|
|
120
129
|
## Config-driven jobs
|
|
121
130
|
|
|
@@ -155,7 +164,7 @@ config file's directory. Template entries and `exclude` entries resolve against
|
|
|
155
164
|
mysqldump job, set `database = "mydatabase"`; for all databases include
|
|
156
165
|
`--all-databases` in `options`.
|
|
157
166
|
|
|
158
|
-
Except for the optional `[history]` settings, each top-level table is one job;
|
|
167
|
+
Except for the optional `[history]` and `[metrics]` settings, each top-level table is one job;
|
|
159
168
|
its keys (except `type`, `active` and `restore_root`) are passed
|
|
160
169
|
to the backend constructor, so they use Python-style underscores
|
|
161
170
|
(`exclude_templates`). See [config.toml.example](https://github.com/ayder/bdbackup/blob/master/config.toml.example)
|
|
@@ -212,6 +221,14 @@ Times use the cron daemon's timezone, and separate lines do not wait for each
|
|
|
212
221
|
other: leave enough time for backups before GFS. Add `--dry-run` to the GFS line
|
|
213
222
|
until its report looks right.
|
|
214
223
|
|
|
224
|
+
`bdbackup metrics` writes the Prometheus textfile and runs every 10 to 15 minutes, as the
|
|
225
|
+
OS account that owns the history database; see
|
|
226
|
+
[Prometheus metrics](https://github.com/ayder/bdbackup/blob/master/docs/README_METRICS.md):
|
|
227
|
+
|
|
228
|
+
```cron
|
|
229
|
+
*/10 * * * * bdbackup metrics -c /opt/dbs/config.toml
|
|
230
|
+
```
|
|
231
|
+
|
|
215
232
|
xtrabackup jobs can run from systemd timers instead, which also stop the backup
|
|
216
233
|
tool if bdbackup dies and add per-job limits: see
|
|
217
234
|
[Running xtrabackup jobs with systemd timers](https://github.com/ayder/bdbackup/blob/master/docs/README_SYSTEMD.md).
|
|
@@ -328,8 +345,10 @@ missing or was replaced, or `<id>: skipped: unexpected unit` for a physical back
|
|
|
328
345
|
outside its dated layout, and then exits 1. A checksum already recorded is never
|
|
329
346
|
changed. `--create-checksum` cannot be combined with `--successful`. The checksum lives in the `checksum` column of the `backup_runs` table.
|
|
330
347
|
|
|
331
|
-
History uses schema version
|
|
332
|
-
write; bdbackup 0.
|
|
348
|
+
History uses schema version 6, from bdbackup 0.7.3. A database at an older schema upgrades
|
|
349
|
+
on the next write; bdbackup 0.7.2 or earlier refuses a version-6 database. Version 6 adds the
|
|
350
|
+
`last_runs` table: the outcome of the last run of each pgbackrest and gfs job, which
|
|
351
|
+
`bdbackup metrics` reads.
|
|
333
352
|
|
|
334
353
|
History is written before work starts, and success only after the backup and its
|
|
335
354
|
requested verification finish. If history cannot be written, the command fails;
|
|
@@ -402,10 +421,24 @@ python scripts/integration_physical.py percona-encrypted # AES256 + zstd recover
|
|
|
402
421
|
python scripts/integration_physical.py mariadb # mariadb:11.4
|
|
403
422
|
python scripts/integration_pgbackrest.py pg16-2.58 # bdbackup-pgbackrest:16-2.58.0
|
|
404
423
|
python scripts/integration_pgbackrest.py pg18-2.60 # bdbackup-pgbackrest:18-2.60.0
|
|
424
|
+
python scripts/integration_nfs_outage.py # bdbackup-nfs-outage:test, privileged
|
|
405
425
|
```
|
|
406
426
|
|
|
407
427
|
The pgBackRest images have no official source; build them from
|
|
408
|
-
`scripts/docker/pgbackrest.Dockerfile` with the commands in `tests/AGENTS.md`.
|
|
428
|
+
`scripts/docker/pgbackrest.Dockerfile` with the commands in `tests/AGENTS.md`. The NFS
|
|
429
|
+
outage test runs `bdbackup metrics` against a hard NFS mount whose server stops answering. Its
|
|
430
|
+
image installs bdbackup from a wheel built on the host, and the script refuses an image built
|
|
431
|
+
from other sources:
|
|
432
|
+
|
|
433
|
+
```bash
|
|
434
|
+
rm -rf dist && python -m build -q
|
|
435
|
+
docker build -f scripts/docker/nfs-outage.Dockerfile \
|
|
436
|
+
--build-arg SOURCE_HASH="$(python scripts/integration_nfs_outage.py --source-hash)" \
|
|
437
|
+
-t bdbackup-nfs-outage:test dist
|
|
438
|
+
```
|
|
439
|
+
|
|
440
|
+
It runs a container with `--privileged --network none`, so it needs a Linux kernel with an NFS
|
|
441
|
+
server and iptables.
|
|
409
442
|
|
|
410
443
|
Physical recovery returns a prepared data directory; copying it into a server's
|
|
411
444
|
data directory, assigning ownership to the server user, and starting that server
|
|
@@ -3,9 +3,11 @@
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
5
|
import logging
|
|
6
|
+
import os
|
|
6
7
|
import subprocess
|
|
7
8
|
import sys
|
|
8
|
-
from contextlib import nullcontext
|
|
9
|
+
from contextlib import contextmanager, nullcontext
|
|
10
|
+
from dataclasses import dataclass, field
|
|
9
11
|
from datetime import UTC, datetime
|
|
10
12
|
from pathlib import Path
|
|
11
13
|
|
|
@@ -20,8 +22,10 @@ from bdbackup.gfs import runner as gfs_runner
|
|
|
20
22
|
from bdbackup.gfs import store as gfs_store
|
|
21
23
|
from bdbackup.gfs import structure as gfs_structure
|
|
22
24
|
from bdbackup.gfs.stages import fed_first_stages
|
|
23
|
-
from bdbackup.history import History
|
|
25
|
+
from bdbackup.history import History, HistoryError
|
|
26
|
+
from bdbackup.metrics_command import run_metrics
|
|
24
27
|
from bdbackup.mysql import MySQLBackup, XtraBackup
|
|
28
|
+
from bdbackup.postgres.pgbackrest import ExportProgress
|
|
25
29
|
from bdbackup.postgres.restore import describe_unit, restore_lines
|
|
26
30
|
from bdbackup.recovery import backup_restore_info, restore_record, suggested_destination
|
|
27
31
|
from bdbackup.templates import TemplateError
|
|
@@ -59,6 +63,32 @@ def main(log_level: str) -> None:
|
|
|
59
63
|
setup_logging(getattr(logging, log_level.upper(), logging.INFO))
|
|
60
64
|
|
|
61
65
|
|
|
66
|
+
def _echo(message: str = "") -> None:
|
|
67
|
+
"""Print one line; a reader that went away discards the rest of the output, not the run.
|
|
68
|
+
|
|
69
|
+
On the first ``BrokenPipeError`` (``bdbackup history | head``) stdout is pointed at
|
|
70
|
+
``/dev/null``. That line, every later one and Python's flush at exit then succeed, so the
|
|
71
|
+
command finishes its work and exits with the code it would have had.
|
|
72
|
+
"""
|
|
73
|
+
try:
|
|
74
|
+
click.echo(message)
|
|
75
|
+
except BrokenPipeError:
|
|
76
|
+
_discard_stdout()
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def _discard_stdout() -> None:
|
|
80
|
+
"""Point stdout's file descriptor at ``/dev/null``; a stream without one is left alone."""
|
|
81
|
+
try:
|
|
82
|
+
descriptor = sys.stdout.fileno()
|
|
83
|
+
except (OSError, ValueError, AttributeError): # a captured stream, or no stdout
|
|
84
|
+
return
|
|
85
|
+
devnull = os.open(os.devnull, os.O_WRONLY)
|
|
86
|
+
try:
|
|
87
|
+
os.dup2(devnull, descriptor)
|
|
88
|
+
finally:
|
|
89
|
+
os.close(devnull)
|
|
90
|
+
|
|
91
|
+
|
|
62
92
|
def _load_config(path: Path) -> Config:
|
|
63
93
|
try:
|
|
64
94
|
return Config(path)
|
|
@@ -129,23 +159,117 @@ def _dry_run(config: Config, job: Job, incremental: bool) -> None:
|
|
|
129
159
|
if isinstance(backend, FileBackup):
|
|
130
160
|
_protect_history(backend, config)
|
|
131
161
|
backend.backup(dry_run=True)
|
|
132
|
-
|
|
162
|
+
_echo(f"Dry run; would create: {backend.tar_filename}")
|
|
133
163
|
elif isinstance(backend, MySQLBackup):
|
|
134
|
-
|
|
164
|
+
_echo(f"Dry run; would dump {backend.selection()} into {backend.out_dir}")
|
|
135
165
|
elif isinstance(backend, XtraBackup) and incremental:
|
|
136
|
-
|
|
166
|
+
_echo(f"Dry run; would take an incremental of {backend.incremental_parent()} "
|
|
137
167
|
f"under {backend.backup_root}")
|
|
138
168
|
elif isinstance(backend, XtraBackup):
|
|
139
|
-
|
|
169
|
+
_echo(f"Dry run; would take a full backup under {backend.backup_root}")
|
|
140
170
|
else:
|
|
141
171
|
raise click.UsageError(f"--dry-run is not supported for job type {job.type!r}")
|
|
142
172
|
|
|
143
173
|
|
|
144
|
-
|
|
174
|
+
@dataclass
|
|
175
|
+
class _Outcome:
|
|
176
|
+
"""What a pgbackrest or gfs run decided; ``_last_run`` turns it into a ``last_runs`` row.
|
|
177
|
+
|
|
178
|
+
A run sets ``result`` and ``facts`` where it decides them. What it leaves unset is worked
|
|
179
|
+
out from the exit code and from how far an export got (``progress``), or, for a gfs run,
|
|
180
|
+
from ``gfs`` and ``raised``.
|
|
181
|
+
"""
|
|
182
|
+
|
|
183
|
+
result: str | None = None
|
|
184
|
+
facts: dict | None = None
|
|
185
|
+
progress: ExportProgress = field(default_factory=ExportProgress)
|
|
186
|
+
gfs: gfs_runner.RunOutcome = field(default_factory=gfs_runner.RunOutcome)
|
|
187
|
+
raised: bool = False
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
# The result of a failed pgbackrest run, by the step its export reached.
|
|
191
|
+
_FAILED_AT = {
|
|
192
|
+
"destination": "destination_not_ready",
|
|
193
|
+
"write": "export_failed",
|
|
194
|
+
"publish": "export_failed",
|
|
195
|
+
"verify": "verify_failed",
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def _result_of(job: Job, outcome: _Outcome, code: int) -> str:
|
|
200
|
+
"""The ``last_runs`` result word of a run that ended with exit code ``code``."""
|
|
201
|
+
if job.type == "gfs":
|
|
202
|
+
if outcome.raised:
|
|
203
|
+
return "error"
|
|
204
|
+
if code == EXIT_OK:
|
|
205
|
+
return "completed"
|
|
206
|
+
if code == EXIT_LOCKED:
|
|
207
|
+
return "locked" if outcome.gfs.locked else "deferred"
|
|
208
|
+
return "failed"
|
|
209
|
+
if outcome.result is not None:
|
|
210
|
+
return outcome.result
|
|
211
|
+
if code == EXIT_LOCKED:
|
|
212
|
+
return "locked"
|
|
213
|
+
return _FAILED_AT.get(outcome.progress.step, "failed")
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
@contextmanager
|
|
217
|
+
def _last_run(config: Config, job: Job, outcome: _Outcome):
|
|
218
|
+
"""Record the run in the block in ``last_runs`` when it ends, however it ends.
|
|
219
|
+
|
|
220
|
+
The exit code is the one the block exits with (click's ``Exit``, or a ``ClickException``
|
|
221
|
+
such as a usage error); an exception that escapes counts as 1. Whatever ended the block is
|
|
222
|
+
raised again. A failure to record is a warning: it never changes the exit code or the output.
|
|
223
|
+
"""
|
|
224
|
+
code = EXIT_OK
|
|
225
|
+
# A pgbackrest run is refused for root so that nothing is left owned by root: no database,
|
|
226
|
+
# no directory for it, and no row in one that exists.
|
|
227
|
+
record = not (job.type == "pgbackrest" and os.geteuid() == 0)
|
|
228
|
+
try:
|
|
229
|
+
yield
|
|
230
|
+
except click.exceptions.Exit as exc:
|
|
231
|
+
code = exc.exit_code
|
|
232
|
+
raise
|
|
233
|
+
except click.ClickException as exc:
|
|
234
|
+
code = exc.exit_code
|
|
235
|
+
raise
|
|
236
|
+
except BaseException:
|
|
237
|
+
code = EXIT_BACKUP_FAILED
|
|
238
|
+
outcome.raised = True
|
|
239
|
+
raise
|
|
240
|
+
finally:
|
|
241
|
+
if record:
|
|
242
|
+
try:
|
|
243
|
+
History(config.history).record_last_run(
|
|
244
|
+
job.name, job.type, code, _result_of(job, outcome, code), outcome.facts
|
|
245
|
+
)
|
|
246
|
+
except (HistoryError, OSError) as exc:
|
|
247
|
+
logging.getLogger("bdbackup.cli").warning(
|
|
248
|
+
"Could not record the last run of job %r: %s", job.name, exc
|
|
249
|
+
)
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
def _export_facts(full, result, progress: ExportProgress, started: datetime) -> dict:
|
|
253
|
+
"""The facts an export leaves in ``last_runs``: its phases, label, size and the full's age."""
|
|
254
|
+
phases = {"write": progress.write_seconds}
|
|
255
|
+
if progress.verify_seconds is not None:
|
|
256
|
+
phases["verify"] = progress.verify_seconds
|
|
257
|
+
return {
|
|
258
|
+
"phases": phases,
|
|
259
|
+
"label": full.label,
|
|
260
|
+
"bytes": result.size_bytes,
|
|
261
|
+
"full_age_seconds": max(0, int((started - full.stop).total_seconds())),
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
def _run_pgbackrest(
|
|
266
|
+
config: Config, job: Job, *, verify: bool, dry_run: bool, outcome: _Outcome
|
|
267
|
+
) -> int:
|
|
145
268
|
"""Export the newest pgBackRest full of the job's stanza as one tar; return the exit code.
|
|
146
269
|
|
|
147
270
|
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
|
|
271
|
+
A dry run takes no lock and writes nothing. When there is no new full nothing is recorded in
|
|
272
|
+
the history of backups. The result a run decides is set on ``outcome``.
|
|
149
273
|
"""
|
|
150
274
|
engine = build_backend(job)
|
|
151
275
|
engine.refuse_root()
|
|
@@ -153,7 +277,7 @@ def _run_pgbackrest(config: Config, job: Job, *, verify: bool, dry_run: bool) ->
|
|
|
153
277
|
choice = engine.choose(History(config.history), job.name)
|
|
154
278
|
full = choice.full
|
|
155
279
|
if full.page_errors:
|
|
156
|
-
|
|
280
|
+
_echo(
|
|
157
281
|
f"WARNING: full {full.label} has page checksum errors; it is exported, "
|
|
158
282
|
"and restoring it needs checksum-page-error=n"
|
|
159
283
|
)
|
|
@@ -162,23 +286,31 @@ def _run_pgbackrest(config: Config, job: Job, *, verify: bool, dry_run: bool) ->
|
|
|
162
286
|
message = f"no new full: newest {full.label}, {hours} hours old"
|
|
163
287
|
limit = engine.max_full_age_hours
|
|
164
288
|
if limit is not None and hours > limit:
|
|
165
|
-
|
|
289
|
+
_echo(f"{message} (older than max_full_age_hours = {limit})")
|
|
290
|
+
outcome.result = "full_too_old"
|
|
166
291
|
return EXIT_BACKUP_FAILED
|
|
167
|
-
|
|
292
|
+
_echo(message)
|
|
293
|
+
outcome.result = "no_new_full"
|
|
168
294
|
return EXIT_OK
|
|
169
295
|
if dry_run:
|
|
170
296
|
engine.require_marker()
|
|
171
|
-
|
|
297
|
+
_echo(
|
|
172
298
|
f"Dry run; would export {full.label} ({full.repo_bytes} bytes) "
|
|
173
299
|
f"of stanza {engine.stanza} to {engine.unit_path(full.label)}"
|
|
174
300
|
)
|
|
175
301
|
return EXIT_OK
|
|
176
302
|
|
|
177
303
|
info = engine.restore_info(full, engine.version())
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
)
|
|
181
|
-
|
|
304
|
+
began = []
|
|
305
|
+
|
|
306
|
+
def export():
|
|
307
|
+
began.append(_now())
|
|
308
|
+
return engine.export(full, verify=verify, progress=outcome.progress)
|
|
309
|
+
|
|
310
|
+
result = _tracked_backup(config, job.name, "pgbackrest-full", export, info)
|
|
311
|
+
outcome.result = "exported"
|
|
312
|
+
outcome.facts = _export_facts(full, result, outcome.progress, began[0])
|
|
313
|
+
_echo(f"Job {job.name}: {result.path}")
|
|
182
314
|
return EXIT_OK
|
|
183
315
|
|
|
184
316
|
|
|
@@ -246,13 +378,13 @@ def run(
|
|
|
246
378
|
if job.type != "gfs":
|
|
247
379
|
raise click.UsageError(f"--initialize-structure applies only to gfs jobs: {job.name}")
|
|
248
380
|
fed = job.params["stage"][0].paths[0] in fed_first_stages(config.jobs)
|
|
249
|
-
ctx.exit(gfs_structure.initialize(job,
|
|
381
|
+
ctx.exit(gfs_structure.initialize(job, _echo, fed))
|
|
250
382
|
if validate_only:
|
|
251
383
|
jobs = [job] if job else list(config.jobs.values())
|
|
252
384
|
if not jobs:
|
|
253
385
|
raise click.UsageError("No configured jobs selected")
|
|
254
386
|
lines, ok = validate_config(config, jobs)
|
|
255
|
-
|
|
387
|
+
_echo("\n".join(lines))
|
|
256
388
|
ctx.exit(EXIT_OK if ok else EXIT_BACKUP_FAILED)
|
|
257
389
|
if job is None:
|
|
258
390
|
raise click.UsageError("Provide --job NAME or --validate")
|
|
@@ -261,10 +393,18 @@ def run(
|
|
|
261
393
|
logger = logging.getLogger("bdbackup.cli")
|
|
262
394
|
logger.info("Running job %r (%s)%s", job.name, job.type, " as a dry run" if dry_run else "")
|
|
263
395
|
if job.type == "gfs":
|
|
264
|
-
|
|
265
|
-
|
|
396
|
+
outcome = _Outcome()
|
|
397
|
+
with nullcontext() if dry_run else _last_run(config, job, outcome):
|
|
398
|
+
code = gfs_runner.run_job(
|
|
399
|
+
config, job, out=_echo, dry_run=dry_run, outcome=outcome.gfs
|
|
400
|
+
)
|
|
401
|
+
ctx.exit(code if code in (EXIT_OK, EXIT_LOCKED) else EXIT_BACKUP_FAILED)
|
|
266
402
|
if job.type == "pgbackrest":
|
|
267
|
-
|
|
403
|
+
outcome = _Outcome()
|
|
404
|
+
with nullcontext() if dry_run else _last_run(config, job, outcome):
|
|
405
|
+
ctx.exit(_handle_errors(
|
|
406
|
+
_run_pgbackrest, config, job, verify=verify, dry_run=dry_run, outcome=outcome
|
|
407
|
+
))
|
|
268
408
|
if dry_run:
|
|
269
409
|
return _handle_errors(_dry_run, config, job, incremental)
|
|
270
410
|
info = {}
|
|
@@ -297,7 +437,7 @@ def run(
|
|
|
297
437
|
except Exception as exc:
|
|
298
438
|
logger.error("Job %r failed: %s", job.name, exc)
|
|
299
439
|
ctx.exit(EXIT_BACKUP_FAILED)
|
|
300
|
-
|
|
440
|
+
_echo(f"Job {job.name}: {result.path}")
|
|
301
441
|
return EXIT_OK
|
|
302
442
|
|
|
303
443
|
|
|
@@ -332,7 +472,7 @@ def _echo_restore_command(directory: Path) -> None:
|
|
|
332
472
|
facts = describe_unit(directory)
|
|
333
473
|
if facts is not None:
|
|
334
474
|
for line in restore_lines(facts, directory.expanduser().absolute()):
|
|
335
|
-
|
|
475
|
+
_echo(line)
|
|
336
476
|
|
|
337
477
|
|
|
338
478
|
@main.command()
|
|
@@ -375,13 +515,13 @@ def restore(
|
|
|
375
515
|
def _run():
|
|
376
516
|
if mode == "archive":
|
|
377
517
|
restored = FileBackup.restore_archive(archive, dst)
|
|
378
|
-
|
|
518
|
+
_echo(f"Restored to: {restored}")
|
|
379
519
|
_echo_restore_command(restored)
|
|
380
520
|
return
|
|
381
521
|
if mode == "backup":
|
|
382
522
|
xb = XtraBackup(backup_root=root, binary=binary or "xtrabackup",
|
|
383
523
|
encrypt_key_file=encrypt_key_file)
|
|
384
|
-
|
|
524
|
+
_echo(f"Prepared recovery directory: {xb.prepare(backup, dst)}")
|
|
385
525
|
return
|
|
386
526
|
config = _history_config(config_path)
|
|
387
527
|
history = History(config.history)
|
|
@@ -400,9 +540,9 @@ def restore(
|
|
|
400
540
|
if gfs_store.available(r, known)]
|
|
401
541
|
if not records:
|
|
402
542
|
raise BackupError("No successful, available backups found")
|
|
403
|
-
|
|
543
|
+
_echo("Successful backups (newest first):")
|
|
404
544
|
for record in records:
|
|
405
|
-
|
|
545
|
+
_echo(
|
|
406
546
|
f"{record.id}: {record.job_name} | {record.backup_type} | "
|
|
407
547
|
f"{record.started_at} | "
|
|
408
548
|
f"{'encrypted' if record.encrypted else 'unencrypted'} | {shown(record)}"
|
|
@@ -427,27 +567,27 @@ def restore(
|
|
|
427
567
|
destination = dst or suggested_destination(record, restore_root)
|
|
428
568
|
if managed:
|
|
429
569
|
# `Backup:` follows once restore has chosen the copy it restores from.
|
|
430
|
-
|
|
570
|
+
_echo("Locations: " + ", ".join(
|
|
431
571
|
str(p.member) for p in known[record.id] if gfs_store.place_available(p)))
|
|
432
572
|
else:
|
|
433
|
-
|
|
573
|
+
_echo(f"Backup: {record.path}")
|
|
434
574
|
if dst is None and not yes:
|
|
435
575
|
destination = Path(click.prompt("Restore destination", default=str(destination)))
|
|
436
|
-
|
|
576
|
+
_echo(f"Recovery destination: {destination}")
|
|
437
577
|
if not yes:
|
|
438
578
|
click.confirm("Restore this backup?", abort=True)
|
|
439
579
|
if encrypt_key_file is not None and not record.backup_type.startswith("xtrabackup"):
|
|
440
580
|
raise click.UsageError("--encrypt-key-file requires a physical backup")
|
|
441
581
|
restored = restore_record(record, destination, encrypt_key_file=encrypt_key_file,
|
|
442
582
|
history=history,
|
|
443
|
-
on_source=(lambda path:
|
|
583
|
+
on_source=(lambda path: _echo(f"Backup: {path}"))
|
|
444
584
|
if managed else None)
|
|
445
585
|
if record.backup_type == "mysqldump":
|
|
446
|
-
|
|
586
|
+
_echo(f"SQL recovered to: {restored / 'backup.sql'} (not imported into a server)")
|
|
447
587
|
elif record.backup_type.startswith("xtrabackup"):
|
|
448
|
-
|
|
588
|
+
_echo(f"Prepared recovery directory: {restored}")
|
|
449
589
|
else:
|
|
450
|
-
|
|
590
|
+
_echo(f"Restored to: {restored}")
|
|
451
591
|
if record.backup_type == "pgbackrest-full":
|
|
452
592
|
_echo_restore_command(restored)
|
|
453
593
|
|
|
@@ -470,7 +610,7 @@ def history_cmd(config_path: Path, job: str | None, successful: bool,
|
|
|
470
610
|
def _checksums():
|
|
471
611
|
config = _history_config(config_path)
|
|
472
612
|
for record_id, outcome in History(config.history).record_checksums(job):
|
|
473
|
-
|
|
613
|
+
_echo(f"{record_id}: {outcome}")
|
|
474
614
|
if outcome == "skipped: unexpected unit":
|
|
475
615
|
unexpected.append(record_id)
|
|
476
616
|
|
|
@@ -481,10 +621,10 @@ def history_cmd(config_path: Path, job: str | None, successful: bool,
|
|
|
481
621
|
suffixes = gfs_store.listing_suffixes(history)
|
|
482
622
|
known = gfs_store.places(history)
|
|
483
623
|
if not records:
|
|
484
|
-
|
|
624
|
+
_echo("No backup history found.")
|
|
485
625
|
for record in records:
|
|
486
626
|
available = "available" if gfs_store.available(record, known) else "unavailable"
|
|
487
|
-
|
|
627
|
+
_echo(
|
|
488
628
|
f"{record.id}: {record.job_name} | {record.backup_type} | {record.started_at} | "
|
|
489
629
|
f"{record.status} | {available} | "
|
|
490
630
|
f"{'encrypted' if record.encrypted else 'unencrypted'} | {record.path or '-'}"
|
|
@@ -498,5 +638,15 @@ def history_cmd(config_path: Path, job: str | None, successful: bool,
|
|
|
498
638
|
return EXIT_OK
|
|
499
639
|
|
|
500
640
|
|
|
641
|
+
@main.command(name="metrics")
|
|
642
|
+
@config_option(required=True)
|
|
643
|
+
def metrics_cmd(config_path: Path) -> None:
|
|
644
|
+
"""Write the Prometheus textfile of the jobs, the history and the pgBackRest repository.
|
|
645
|
+
|
|
646
|
+
Read-only: it never backs up, prunes or writes the history. Run it from cron.
|
|
647
|
+
"""
|
|
648
|
+
click.get_current_context().exit(run_metrics(config_path))
|
|
649
|
+
|
|
650
|
+
|
|
501
651
|
if __name__ == "__main__":
|
|
502
652
|
sys.exit(main())
|