bdbackup 0.7.3__tar.gz → 0.7.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. {bdbackup-0.7.3 → bdbackup-0.7.4}/PKG-INFO +14 -5
  2. {bdbackup-0.7.3 → bdbackup-0.7.4}/README.md +13 -4
  3. {bdbackup-0.7.3 → bdbackup-0.7.4}/bdbackup/cli.py +1 -0
  4. {bdbackup-0.7.3 → bdbackup-0.7.4}/bdbackup/gfs/actions.py +67 -15
  5. bdbackup-0.7.4/bdbackup/gfs/drift.py +236 -0
  6. {bdbackup-0.7.3 → bdbackup-0.7.4}/bdbackup/gfs/policy.py +15 -0
  7. {bdbackup-0.7.3 → bdbackup-0.7.4}/bdbackup/gfs/runner.py +206 -29
  8. {bdbackup-0.7.3 → bdbackup-0.7.4}/bdbackup/gfs/stages.py +6 -2
  9. {bdbackup-0.7.3 → bdbackup-0.7.4}/bdbackup/gfs/store.py +20 -6
  10. {bdbackup-0.7.3 → bdbackup-0.7.4}/bdbackup/metrics/collector.py +26 -2
  11. {bdbackup-0.7.3 → bdbackup-0.7.4}/bdbackup/metrics/data.py +56 -2
  12. bdbackup-0.7.4/bdbackup/metrics/families.py +224 -0
  13. bdbackup-0.7.4/bdbackup/metrics/gfs.py +343 -0
  14. {bdbackup-0.7.3 → bdbackup-0.7.4}/bdbackup/metrics/probe.py +17 -3
  15. {bdbackup-0.7.3 → bdbackup-0.7.4}/bdbackup/metrics/run.py +13 -7
  16. {bdbackup-0.7.3 → bdbackup-0.7.4}/bdbackup/metrics/units.py +18 -0
  17. {bdbackup-0.7.3 → bdbackup-0.7.4}/bdbackup/validation.py +143 -20
  18. {bdbackup-0.7.3 → bdbackup-0.7.4}/config.toml.example +3 -0
  19. {bdbackup-0.7.3 → bdbackup-0.7.4}/docs/README_GFS.md +242 -35
  20. {bdbackup-0.7.3 → bdbackup-0.7.4}/docs/README_METRICS.md +192 -13
  21. {bdbackup-0.7.3 → bdbackup-0.7.4}/docs/README_PGBACKREST.md +7 -3
  22. {bdbackup-0.7.3 → bdbackup-0.7.4}/pyproject.toml +1 -1
  23. {bdbackup-0.7.3 → bdbackup-0.7.4}/scripts/integration_nfs_outage.py +185 -7
  24. {bdbackup-0.7.3 → bdbackup-0.7.4}/tests/AGENTS.md +5 -3
  25. {bdbackup-0.7.3 → bdbackup-0.7.4}/tests/conftest.py +14 -0
  26. {bdbackup-0.7.3 → bdbackup-0.7.4}/tests/test_gfs_config.py +41 -0
  27. bdbackup-0.7.4/tests/test_gfs_drift.py +438 -0
  28. {bdbackup-0.7.3 → bdbackup-0.7.4}/tests/test_gfs_run.py +956 -15
  29. {bdbackup-0.7.3 → bdbackup-0.7.4}/tests/test_metrics_collect.py +12 -2
  30. {bdbackup-0.7.3 → bdbackup-0.7.4}/tests/test_metrics_command.py +30 -0
  31. bdbackup-0.7.4/tests/test_metrics_gfs.py +733 -0
  32. {bdbackup-0.7.3 → bdbackup-0.7.4}/tests/test_metrics_probe.py +24 -1
  33. bdbackup-0.7.4/tests/test_validate_os_errors.py +188 -0
  34. bdbackup-0.7.4/tests/test_validate_os_user.py +100 -0
  35. bdbackup-0.7.4/tests/test_validate_unreachable.py +222 -0
  36. bdbackup-0.7.3/bdbackup/metrics/families.py +0 -96
  37. bdbackup-0.7.3/bdbackup/metrics/gfs.py +0 -124
  38. {bdbackup-0.7.3 → bdbackup-0.7.4}/.gitignore +0 -0
  39. {bdbackup-0.7.3 → bdbackup-0.7.4}/LICENSE +0 -0
  40. {bdbackup-0.7.3 → bdbackup-0.7.4}/bdbackup/__init__.py +0 -0
  41. {bdbackup-0.7.3 → bdbackup-0.7.4}/bdbackup/backends.py +0 -0
  42. {bdbackup-0.7.3 → bdbackup-0.7.4}/bdbackup/config.py +0 -0
  43. {bdbackup-0.7.3 → bdbackup-0.7.4}/bdbackup/engines.py +0 -0
  44. {bdbackup-0.7.3 → bdbackup-0.7.4}/bdbackup/filebackup.py +0 -0
  45. {bdbackup-0.7.3 → bdbackup-0.7.4}/bdbackup/gfs/__init__.py +0 -0
  46. {bdbackup-0.7.3 → bdbackup-0.7.4}/bdbackup/gfs/structure.py +0 -0
  47. {bdbackup-0.7.3 → bdbackup-0.7.4}/bdbackup/history.py +0 -0
  48. {bdbackup-0.7.3 → bdbackup-0.7.4}/bdbackup/ledger.py +0 -0
  49. {bdbackup-0.7.3 → bdbackup-0.7.4}/bdbackup/metrics/__init__.py +0 -0
  50. {bdbackup-0.7.3 → bdbackup-0.7.4}/bdbackup/metrics/jobs.py +0 -0
  51. {bdbackup-0.7.3 → bdbackup-0.7.4}/bdbackup/metrics/registry.py +0 -0
  52. {bdbackup-0.7.3 → bdbackup-0.7.4}/bdbackup/metrics/render.py +0 -0
  53. {bdbackup-0.7.3 → bdbackup-0.7.4}/bdbackup/metrics/settings.py +0 -0
  54. {bdbackup-0.7.3 → bdbackup-0.7.4}/bdbackup/metrics/write.py +0 -0
  55. {bdbackup-0.7.3 → bdbackup-0.7.4}/bdbackup/metrics_command.py +0 -0
  56. {bdbackup-0.7.3 → bdbackup-0.7.4}/bdbackup/mysql/__init__.py +0 -0
  57. {bdbackup-0.7.3 → bdbackup-0.7.4}/bdbackup/mysql/helpers.py +0 -0
  58. {bdbackup-0.7.3 → bdbackup-0.7.4}/bdbackup/mysql/mysqldump.py +0 -0
  59. {bdbackup-0.7.3 → bdbackup-0.7.4}/bdbackup/mysql/xtrabackup.py +0 -0
  60. {bdbackup-0.7.3 → bdbackup-0.7.4}/bdbackup/postgres/__init__.py +0 -0
  61. {bdbackup-0.7.3 → bdbackup-0.7.4}/bdbackup/postgres/metrics.py +0 -0
  62. {bdbackup-0.7.3 → bdbackup-0.7.4}/bdbackup/postgres/pgbackrest.py +0 -0
  63. {bdbackup-0.7.3 → bdbackup-0.7.4}/bdbackup/postgres/repository.py +0 -0
  64. {bdbackup-0.7.3 → bdbackup-0.7.4}/bdbackup/postgres/restore.py +0 -0
  65. {bdbackup-0.7.3 → bdbackup-0.7.4}/bdbackup/recovery.py +0 -0
  66. {bdbackup-0.7.3 → bdbackup-0.7.4}/bdbackup/templates/__init__.py +0 -0
  67. {bdbackup-0.7.3 → bdbackup-0.7.4}/bdbackup/templates/_matching.py +0 -0
  68. {bdbackup-0.7.3 → bdbackup-0.7.4}/bdbackup/templates/python_dev.py +0 -0
  69. {bdbackup-0.7.3 → bdbackup-0.7.4}/bdbackup/utils.py +0 -0
  70. {bdbackup-0.7.3 → bdbackup-0.7.4}/contrib/systemd/bdbackup-incremental@.service +0 -0
  71. {bdbackup-0.7.3 → bdbackup-0.7.4}/contrib/systemd/bdbackup-incremental@.timer +0 -0
  72. {bdbackup-0.7.3 → bdbackup-0.7.4}/contrib/systemd/bdbackup@.service +0 -0
  73. {bdbackup-0.7.3 → bdbackup-0.7.4}/contrib/systemd/bdbackup@.timer +0 -0
  74. {bdbackup-0.7.3 → bdbackup-0.7.4}/docs/README_ENGINES.md +0 -0
  75. {bdbackup-0.7.3 → bdbackup-0.7.4}/docs/README_FILE.md +0 -0
  76. {bdbackup-0.7.3 → bdbackup-0.7.4}/docs/README_MYSQLDUMP.md +0 -0
  77. {bdbackup-0.7.3 → bdbackup-0.7.4}/docs/README_SYSTEMD.md +0 -0
  78. {bdbackup-0.7.3 → bdbackup-0.7.4}/docs/README_XTRABACKUP.md +0 -0
  79. {bdbackup-0.7.3 → bdbackup-0.7.4}/scripts/check_release.py +0 -0
  80. {bdbackup-0.7.3 → bdbackup-0.7.4}/scripts/docker/nfs-outage.Dockerfile +0 -0
  81. {bdbackup-0.7.3 → bdbackup-0.7.4}/scripts/docker/pgbackrest.Dockerfile +0 -0
  82. {bdbackup-0.7.3 → bdbackup-0.7.4}/scripts/integration_mysql.py +0 -0
  83. {bdbackup-0.7.3 → bdbackup-0.7.4}/scripts/integration_pgbackrest.py +0 -0
  84. {bdbackup-0.7.3 → bdbackup-0.7.4}/scripts/integration_physical.py +0 -0
  85. {bdbackup-0.7.3 → bdbackup-0.7.4}/scripts/smoke_install.py +0 -0
  86. {bdbackup-0.7.3 → bdbackup-0.7.4}/template.txt +0 -0
  87. {bdbackup-0.7.3 → bdbackup-0.7.4}/tests/__init__.py +0 -0
  88. {bdbackup-0.7.3 → bdbackup-0.7.4}/tests/pgbackrest_fake.py +0 -0
  89. {bdbackup-0.7.3 → bdbackup-0.7.4}/tests/test_architecture.py +0 -0
  90. {bdbackup-0.7.3 → bdbackup-0.7.4}/tests/test_broken_pipe.py +0 -0
  91. {bdbackup-0.7.3 → bdbackup-0.7.4}/tests/test_cli_reshape.py +0 -0
  92. {bdbackup-0.7.3 → bdbackup-0.7.4}/tests/test_config_lexical.py +0 -0
  93. {bdbackup-0.7.3 → bdbackup-0.7.4}/tests/test_correctness.py +0 -0
  94. {bdbackup-0.7.3 → bdbackup-0.7.4}/tests/test_encryption.py +0 -0
  95. {bdbackup-0.7.3 → bdbackup-0.7.4}/tests/test_engine_conditions.py +0 -0
  96. {bdbackup-0.7.3 → bdbackup-0.7.4}/tests/test_engines.py +0 -0
  97. {bdbackup-0.7.3 → bdbackup-0.7.4}/tests/test_gfs_init.py +0 -0
  98. {bdbackup-0.7.3 → bdbackup-0.7.4}/tests/test_gfs_policy.py +0 -0
  99. {bdbackup-0.7.3 → bdbackup-0.7.4}/tests/test_gfs_store.py +0 -0
  100. {bdbackup-0.7.3 → bdbackup-0.7.4}/tests/test_helpers.py +0 -0
  101. {bdbackup-0.7.3 → bdbackup-0.7.4}/tests/test_history.py +0 -0
  102. {bdbackup-0.7.3 → bdbackup-0.7.4}/tests/test_import.py +0 -0
  103. {bdbackup-0.7.3 → bdbackup-0.7.4}/tests/test_last_runs.py +0 -0
  104. {bdbackup-0.7.3 → bdbackup-0.7.4}/tests/test_ledger.py +0 -0
  105. {bdbackup-0.7.3 → bdbackup-0.7.4}/tests/test_metrics_config.py +0 -0
  106. {bdbackup-0.7.3 → bdbackup-0.7.4}/tests/test_metrics_hang.py +0 -0
  107. {bdbackup-0.7.3 → bdbackup-0.7.4}/tests/test_metrics_phases.py +0 -0
  108. {bdbackup-0.7.3 → bdbackup-0.7.4}/tests/test_metrics_render.py +0 -0
  109. {bdbackup-0.7.3 → bdbackup-0.7.4}/tests/test_metrics_write.py +0 -0
  110. {bdbackup-0.7.3 → bdbackup-0.7.4}/tests/test_performance.py +0 -0
  111. {bdbackup-0.7.3 → bdbackup-0.7.4}/tests/test_pgbackrest_cli.py +0 -0
  112. {bdbackup-0.7.3 → bdbackup-0.7.4}/tests/test_pgbackrest_engine.py +0 -0
  113. {bdbackup-0.7.3 → bdbackup-0.7.4}/tests/test_pgbackrest_export.py +0 -0
  114. {bdbackup-0.7.3 → bdbackup-0.7.4}/tests/test_pgbackrest_metrics.py +0 -0
  115. {bdbackup-0.7.3 → bdbackup-0.7.4}/tests/test_pgbackrest_repository.py +0 -0
  116. {bdbackup-0.7.3 → bdbackup-0.7.4}/tests/test_pgbackrest_restore.py +0 -0
  117. {bdbackup-0.7.3 → bdbackup-0.7.4}/tests/test_release_fixes.py +0 -0
  118. {bdbackup-0.7.3 → bdbackup-0.7.4}/tests/test_run_selector.py +0 -0
  119. {bdbackup-0.7.3 → bdbackup-0.7.4}/tests/test_safety_nets.py +0 -0
  120. {bdbackup-0.7.3 → bdbackup-0.7.4}/tests/test_security.py +0 -0
  121. {bdbackup-0.7.3 → bdbackup-0.7.4}/tests/test_systemd_units.py +0 -0
  122. {bdbackup-0.7.3 → bdbackup-0.7.4}/tests/test_templates.py +0 -0
  123. {bdbackup-0.7.3 → bdbackup-0.7.4}/tests/test_validate_metrics.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: bdbackup
3
- Version: 0.7.3
3
+ Version: 0.7.4
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
@@ -79,8 +79,8 @@ run from cron.
79
79
  | [MySQL and MariaDB logical backups with mysqldump](https://github.com/ayder/bdbackup/blob/master/docs/README_MYSQLDUMP.md) | mysqldump jobs, credentials, default options |
80
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 |
81
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 |
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 |
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 |
82
+ | [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 |
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 (coverage and drift of the GFS stages included), alerting, hangs and outages, known limits |
84
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 |
85
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 |
86
86
  | [Annotated configuration](https://github.com/ayder/bdbackup/blob/master/config.toml.example) | every config key with a comment |
@@ -312,6 +312,13 @@ For a GFS job, every stage path after the first (and the first, when a pgbackres
312
312
  job writes into it) must exist and be writable, and
313
313
  its `.bdbackup-destination` marker must be present and writable; a missing
314
314
  marker's line names the `--initialize-structure` command that creates it.
315
+ A path below a directory the OS user cannot search is a FAIL line that names the directory:
316
+ `<label>: <path> is not reachable by OS user <user>: <directory> lacks search (x) permission;
317
+ see namei -l <path>`. Any other error the system returns for a checked path (on NFS,
318
+ `ESTALE`, `EIO` or `ETIMEDOUT`) is `<label>: cannot check <path>: <reason> (<errno name>)`, and
319
+ validation goes on with its other checks. When the account has no entry in the passwd database
320
+ (a container, a directory service that is down), the reports name it `uid <n>`, for example
321
+ `Validation as OS user uid 1000`.
315
322
  An unreachable database or missing client is a failed/incomplete check, not a pass.
316
323
  Validation does not add SQLite history rows. It exits 0 when its checks pass, 1
317
324
  for failed or incomplete checks, and 2 for invalid command or configuration syntax.
@@ -382,7 +389,8 @@ changed. `--create-checksum` cannot be combined with `--successful`. The checksu
382
389
  History uses schema version 6, from bdbackup 0.7.3. A database at an older schema upgrades
383
390
  on the next write; bdbackup 0.7.2 or earlier refuses a version-6 database. Version 6 adds the
384
391
  `last_runs` table: the outcome of the last run of each pgbackrest and gfs job, which
385
- `bdbackup metrics` reads.
392
+ `bdbackup metrics` reads. For a gfs job it also keeps the facts of its last finished run (reason
393
+ classes, moves by rename and by copy, drift).
386
394
 
387
395
  History is written before work starts, and success only after the backup and its
388
396
  requested verification finish. If history cannot be written, the command fails;
@@ -460,7 +468,8 @@ python scripts/integration_nfs_outage.py # bdbackup-nfs-outage:test, privileged
460
468
 
461
469
  The pgBackRest images have no official source; build them from
462
470
  `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
471
+ outage test runs `bdbackup metrics` against a hard NFS mount whose server stops answering, and
472
+ checks that GFS copies a unit onto the share and renames it within it. Its
464
473
  image installs bdbackup from a wheel built on the host, and the script refuses an image built
465
474
  from other sources:
466
475
 
@@ -45,8 +45,8 @@ run from cron.
45
45
  | [MySQL and MariaDB logical backups with mysqldump](https://github.com/ayder/bdbackup/blob/master/docs/README_MYSQLDUMP.md) | mysqldump jobs, credentials, default options |
46
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 |
47
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 |
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 |
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 |
48
+ | [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 |
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 (coverage and drift of the GFS stages included), alerting, hangs and outages, known limits |
50
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 |
51
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 |
52
52
  | [Annotated configuration](https://github.com/ayder/bdbackup/blob/master/config.toml.example) | every config key with a comment |
@@ -278,6 +278,13 @@ For a GFS job, every stage path after the first (and the first, when a pgbackres
278
278
  job writes into it) must exist and be writable, and
279
279
  its `.bdbackup-destination` marker must be present and writable; a missing
280
280
  marker's line names the `--initialize-structure` command that creates it.
281
+ A path below a directory the OS user cannot search is a FAIL line that names the directory:
282
+ `<label>: <path> is not reachable by OS user <user>: <directory> lacks search (x) permission;
283
+ see namei -l <path>`. Any other error the system returns for a checked path (on NFS,
284
+ `ESTALE`, `EIO` or `ETIMEDOUT`) is `<label>: cannot check <path>: <reason> (<errno name>)`, and
285
+ validation goes on with its other checks. When the account has no entry in the passwd database
286
+ (a container, a directory service that is down), the reports name it `uid <n>`, for example
287
+ `Validation as OS user uid 1000`.
281
288
  An unreachable database or missing client is a failed/incomplete check, not a pass.
282
289
  Validation does not add SQLite history rows. It exits 0 when its checks pass, 1
283
290
  for failed or incomplete checks, and 2 for invalid command or configuration syntax.
@@ -348,7 +355,8 @@ changed. `--create-checksum` cannot be combined with `--successful`. The checksu
348
355
  History uses schema version 6, from bdbackup 0.7.3. A database at an older schema upgrades
349
356
  on the next write; bdbackup 0.7.2 or earlier refuses a version-6 database. Version 6 adds the
350
357
  `last_runs` table: the outcome of the last run of each pgbackrest and gfs job, which
351
- `bdbackup metrics` reads.
358
+ `bdbackup metrics` reads. For a gfs job it also keeps the facts of its last finished run (reason
359
+ classes, moves by rename and by copy, drift).
352
360
 
353
361
  History is written before work starts, and success only after the backup and its
354
362
  requested verification finish. If history cannot be written, the command fails;
@@ -426,7 +434,8 @@ python scripts/integration_nfs_outage.py # bdbackup-nfs-outage:test, privileged
426
434
 
427
435
  The pgBackRest images have no official source; build them from
428
436
  `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
437
+ outage test runs `bdbackup metrics` against a hard NFS mount whose server stops answering, and
438
+ checks that GFS copies a unit onto the share and renames it within it. Its
430
439
  image installs bdbackup from a wheel built on the host, and the script refuses an image built
431
440
  from other sources:
432
441
 
@@ -398,6 +398,7 @@ def run(
398
398
  code = gfs_runner.run_job(
399
399
  config, job, out=_echo, dry_run=dry_run, outcome=outcome.gfs
400
400
  )
401
+ outcome.facts = outcome.gfs.facts # none for a busy lock, and a raise never gets here
401
402
  ctx.exit(code if code in (EXIT_OK, EXIT_LOCKED) else EXIT_BACKUP_FAILED)
402
403
  if job.type == "pgbackrest":
403
404
  outcome = _Outcome()
@@ -1,4 +1,4 @@
1
- """GFS filesystem actions: contents check, verified copy and removal (spec 2 §4.3, §4.4).
1
+ """GFS filesystem actions: contents check, verified copy, rename and removal (spec 2 §4.3, §4.4).
2
2
 
3
3
  Copies go through a ``Transport`` so that object storage can be added later (spec 2 §5).
4
4
  """
@@ -22,16 +22,37 @@ from bdbackup.ledger import LedgerError, checksum
22
22
  _CHUNK = 1024 * 1024
23
23
 
24
24
 
25
+ # The classes of a refusal (spec 16 section 6.1), fixed: metrics never parses the reason text.
26
+ REFUSAL_CLASSES = (
27
+ "checksum_mismatch", "unexpected_entry", "missing_location", "stage_not_configured",
28
+ "destination_not_ready", "final_name_exists", "other",
29
+ )
30
+
31
+
25
32
  class Refusal(Exception):
26
- """GFS will not act on this unit now; the reason is reported and recorded."""
33
+ """GFS will not act on this unit now; the reason is reported and recorded.
27
34
 
28
- def __init__(self, reason: str):
35
+ ``reason_class`` is one of ``REFUSAL_CLASSES``; a refusal that names none is ``other``.
36
+ """
37
+
38
+ def __init__(self, reason: str, reason_class: str = "other"):
29
39
  super().__init__(reason)
30
40
  self.reason = reason
41
+ self.reason_class = reason_class
42
+
43
+
44
+ def final_name_exists(final: Path) -> Refusal:
45
+ """The refusal when a unit's final name is taken; the docs say how to clear it (D7)."""
46
+ return Refusal(
47
+ f'final name exists: {final}; see docs/README_GFS.md, "Final name exists"',
48
+ "final_name_exists",
49
+ )
31
50
 
32
51
 
33
52
  class Transport(Protocol):
34
53
  def copy(self, source: Path, temp: Path, on_file: Callable[[str, str], None]) -> None: ...
54
+ def same_filesystem(self, a: Path, b: Path) -> bool: ...
55
+ def relocate(self, source: Path, final: Path) -> None: ...
35
56
  def rename(self, temp: Path, final: Path) -> None: ...
36
57
  def replace(self, temp: Path, final: Path) -> None: ...
37
58
  def remove(self, path: Path) -> None: ...
@@ -103,15 +124,40 @@ class LocalTransport:
103
124
  relative = entry.relative_to(source).as_posix()
104
125
  on_file(relative, self._copy_file(entry, target))
105
126
  else:
106
- raise Refusal(f"unexpected entry {entry.relative_to(source).as_posix()}")
127
+ raise Refusal(
128
+ f"unexpected entry {entry.relative_to(source).as_posix()}",
129
+ "unexpected_entry",
130
+ )
107
131
  _fsync_dir(target_dir)
108
132
  for here, target_dir in reversed(directories):
109
133
  with self._mode_may_be_refused():
110
134
  os.chmod(target_dir, stat.S_IMODE(here.lstat().st_mode))
111
135
 
136
+ def same_filesystem(self, a: Path, b: Path) -> bool:
137
+ """Whether two live paths are on one device; a path that cannot be examined is not."""
138
+ try:
139
+ return os.stat(a).st_dev == os.stat(b).st_dev
140
+ except OSError:
141
+ return False
142
+
143
+ def relocate(self, source: Path, final: Path) -> None:
144
+ """Rename a unit to its final name on one filesystem, reading none of its data.
145
+
146
+ ``os.rename`` silently replaces a file or an empty directory, so a taken name is refused
147
+ first. It fails with EXDEV when the two paths are on different mounts of one device;
148
+ the caller then copies.
149
+ """
150
+ final.parent.mkdir(parents=True, exist_ok=True)
151
+ if os.path.lexists(final):
152
+ raise final_name_exists(final)
153
+ os.rename(source, final)
154
+ _fsync_dir(final.parent)
155
+ if source.parent != final.parent:
156
+ _fsync_dir(source.parent)
157
+
112
158
  def rename(self, temp: Path, final: Path) -> None:
113
159
  if os.path.lexists(final):
114
- raise Refusal(f"final name exists: {final}")
160
+ raise final_name_exists(final)
115
161
  os.rename(temp, final)
116
162
  _fsync_dir(final.parent)
117
163
 
@@ -142,10 +188,10 @@ def check_contents(unit: ManagedUnit, at: Path) -> None:
142
188
  Inside a member only regular files and directories are allowed (spec 2 §2).
143
189
  """
144
190
  if not os.path.lexists(at):
145
- raise Refusal(f"missing location {at}")
191
+ raise Refusal(f"missing location {at}", "missing_location")
146
192
  if unit.kind != "xtrabackup":
147
193
  if not stat.S_ISREG(at.lstat().st_mode):
148
- raise Refusal(f"unexpected entry {at.name}")
194
+ raise Refusal(f"unexpected entry {at.name}", "unexpected_entry")
149
195
  return
150
196
  members = set(_member_paths(unit))
151
197
  fulls = {m for m in members if "/" not in m}
@@ -157,7 +203,7 @@ def check_contents(unit: ManagedUnit, at: Path) -> None:
157
203
  if any(relative == m or relative.startswith(m + "/") for m in members):
158
204
  mode = entry.lstat().st_mode
159
205
  if not (stat.S_ISREG(mode) or stat.S_ISDIR(mode)):
160
- raise Refusal(f"unexpected entry {relative}")
206
+ raise Refusal(f"unexpected entry {relative}", "unexpected_entry")
161
207
  continue
162
208
  parts = relative.split("/")
163
209
  if relative == ".full_success" and entry.is_file() and not entry.is_symlink():
@@ -169,21 +215,27 @@ def check_contents(unit: ManagedUnit, at: Path) -> None:
169
215
  and (len(parts) == 1 or (len(parts) == 2 and parts[1].startswith("Full_")))
170
216
  ):
171
217
  continue
172
- raise Refusal(f"unexpected entry {relative}")
218
+ raise Refusal(f"unexpected entry {relative}", "unexpected_entry")
219
+
173
220
 
221
+ def verify(unit: ManagedUnit, at: Path, *, checksums: bool = True) -> None:
222
+ """Check a location against the ledger: its contents, then every member's checksum.
174
223
 
175
- def verify(unit: ManagedUnit, at: Path) -> None:
176
- """Recompute every member's checksum at a location and compare with the ledger."""
224
+ The contents check reads metadata only and always runs; ``checksums=False`` skips the
225
+ read of the data (a stage with ``verify = false``).
226
+ """
177
227
  check_contents(unit, at)
228
+ if not checksums:
229
+ return
178
230
  for member, relative in zip(unit.members, _member_paths(unit), strict=True):
179
231
  try:
180
232
  actual = checksum(at / relative if relative != "." else at)
181
233
  except LedgerError as exc:
182
- raise Refusal(f"unexpected entry {exc}") from None
234
+ raise Refusal(f"unexpected entry {exc}", "unexpected_entry") from None
183
235
  except OSError:
184
- raise Refusal(f"missing location {at / relative}") from None
236
+ raise Refusal(f"missing location {at / relative}", "missing_location") from None
185
237
  if actual != member.checksum:
186
- raise Refusal("checksum mismatch")
238
+ raise Refusal("checksum mismatch", "checksum_mismatch")
187
239
 
188
240
 
189
241
  def _manifest(digests: dict[str, str], member: str) -> str:
@@ -208,7 +260,7 @@ def copy_verified(unit: ManagedUnit, source: Path, final: Path, transport: Trans
208
260
  transport.copy(source, temp, lambda name, digest: digests.__setitem__(name, digest))
209
261
  for member, relative in zip(unit.members, _member_paths(unit), strict=True):
210
262
  if _manifest(digests, relative) != member.checksum:
211
- raise Refusal("checksum mismatch")
263
+ raise Refusal("checksum mismatch", "checksum_mismatch")
212
264
  except BaseException:
213
265
  if transport.exists(temp):
214
266
  transport.remove(temp)
@@ -0,0 +1,236 @@
1
+ """Drift: what the stage paths hold against what the ledger records (spec 16 section 6.3).
2
+
3
+ A stage path can differ from the ledger without any action looking at it: a unit removed by
4
+ hand, a rename a crash cut short, a share remounted onto the wrong export. Drift counts, per
5
+ stage path, the recorded locations that are not there (``missing``) and, for a path that carries
6
+ the destination marker, the entries that are not recorded (``unknown``). It reads the
7
+ filesystem's metadata only, never a unit's data.
8
+
9
+ Every check that touches a share runs in a child process under one deadline, as the metrics
10
+ probes do: a hung hard mount must not hang the run. The child's source imports nothing from
11
+ bdbackup, so it starts fast and cannot import a share-bound module.
12
+ """
13
+
14
+ from __future__ import annotations
15
+
16
+ import json
17
+ import subprocess
18
+ import sys
19
+ from collections.abc import Callable
20
+ from dataclasses import dataclass
21
+ from pathlib import Path
22
+
23
+ # The child reads a JSON list of requests on stdin and prints one flushed JSON line per request,
24
+ # in order. A request names a stage path, the marker that says the share is mounted, the name
25
+ # of the ledger snapshot, the recorded locations to look at, and every path the ledger knows
26
+ # below the stage path. ``check`` is the whole of it; the tests run it in-process.
27
+ CHILD_SOURCE = r'''
28
+ import json, os, stat, sys
29
+
30
+ LOCK = ".bdbackup.lock"
31
+ TEMP = ".gfs-tmp-"
32
+ # What a filesystem or an appliance keeps in a directory of its own: lost+found at the root of
33
+ # a local filesystem, and .snapshot, which some appliances show in every directory of an export.
34
+ FILESYSTEM = {"lost+found", ".snapshot"}
35
+
36
+
37
+ def device_of(path):
38
+ return os.lstat(path).st_dev
39
+
40
+
41
+ def own_temporary(name):
42
+ # bdbackup's own temporary names: a GFS copy, and a pgbackrest export's tar before its rename.
43
+ return name.startswith(TEMP) or (name.startswith(".") and ".tar.tmp-" in name)
44
+
45
+
46
+ def ignored(name):
47
+ return name == LOCK or name in FILESYSTEM or own_temporary(name)
48
+
49
+
50
+ def holds_entries(directory):
51
+ """Whether a directory holds anything the walk would count. GFS makes the parent directory
52
+ of a unit and never removes it, so one a unit has left is empty, or has only its lock."""
53
+ with os.scandir(directory) as scan:
54
+ return any(not ignored(entry.name) for entry in scan)
55
+
56
+
57
+ def walk(root, known, ancestors, skip_at_root):
58
+ """The entries below ``root`` that are neither known nor a directory above a known path.
59
+
60
+ It never follows a symlink and never enters another device: a directory whose device is
61
+ not the root's counts as one entry. An unknown entry is one entry, whatever it holds. A
62
+ directory that holds nothing countable is not an entry.
63
+ """
64
+ unknown = 0
65
+ device = device_of(root)
66
+ pending = [(root, True)]
67
+ while pending:
68
+ directory, top = pending.pop()
69
+ with os.scandir(directory) as scan:
70
+ for entry in scan:
71
+ name = entry.name
72
+ path = os.path.join(directory, name)
73
+ if ignored(name):
74
+ continue
75
+ if top and name in skip_at_root:
76
+ continue
77
+ if path in known:
78
+ continue
79
+ if entry.is_dir(follow_symlinks=False):
80
+ if device_of(path) != device:
81
+ unknown += 1
82
+ elif path in ancestors:
83
+ pending.append((path, False))
84
+ elif holds_entries(path):
85
+ unknown += 1
86
+ else:
87
+ unknown += 1
88
+ return unknown
89
+
90
+
91
+ def check(request):
92
+ """``{"checked": True, "missing": n, "unknown": m}``, or why the path was not checked."""
93
+ root = request["path"]
94
+ # A path that is walked must carry its marker (an unmounted share has none). One that is
95
+ # only looked at for missing locations, an unfed first stage, must exist.
96
+ walked = request["walk"]
97
+ problem = "no marker" if walked else "no path"
98
+ wanted = stat.S_ISREG if walked else stat.S_ISDIR
99
+ try:
100
+ found = os.stat(os.path.join(root, request["marker"]) if walked else root)
101
+ except (FileNotFoundError, NotADirectoryError):
102
+ return {"checked": False, "problem": problem}
103
+ except OSError as exc:
104
+ return {"checked": False, "problem": "error: " + (exc.strerror or str(exc))}
105
+ if not wanted(found.st_mode):
106
+ return {"checked": False, "problem": problem}
107
+ try:
108
+ missing = 0
109
+ for location in request["locations"]:
110
+ try:
111
+ os.lstat(location)
112
+ except (FileNotFoundError, NotADirectoryError):
113
+ missing += 1
114
+ known = set(request["known"])
115
+ ancestors = set()
116
+ for path in known:
117
+ parent = os.path.dirname(path)
118
+ while parent.startswith(root + os.sep) and parent not in ancestors:
119
+ ancestors.add(parent)
120
+ parent = os.path.dirname(parent)
121
+ unknown = None
122
+ if walked:
123
+ unknown = walk(root, known, ancestors, {request["marker"], request["snapshot"]})
124
+ except OSError as exc:
125
+ return {"checked": False, "problem": "error: " + (exc.strerror or str(exc))}
126
+ return {"checked": True, "missing": missing, "unknown": unknown}
127
+
128
+
129
+ def main():
130
+ for i, request in enumerate(json.load(sys.stdin)):
131
+ line = dict(check(request), i=i)
132
+ sys.stdout.write(json.dumps(line) + "\n")
133
+ sys.stdout.flush()
134
+
135
+
136
+ if __name__ == "__main__":
137
+ main()
138
+ '''
139
+
140
+
141
+ @dataclass(frozen=True)
142
+ class DriftRequest:
143
+ """One stage path to check."""
144
+
145
+ path: Path
146
+ marker: str # the file whose presence says the share is mounted (when the path is walked)
147
+ snapshot: str # the ledger snapshot's name, which is not an unknown entry
148
+ locations: tuple[str, ...] # the recorded locations in this stage path: each must exist
149
+ known: tuple[str, ...] # every path the ledger knows below it: none of them is unknown
150
+ walk: bool = True # False: only the locations are looked at, and the path must exist
151
+
152
+
153
+ @dataclass(frozen=True)
154
+ class DriftResult:
155
+ """What the check found at one stage path; ``problem`` says why it was not checked."""
156
+
157
+ path: Path
158
+ checked: bool
159
+ missing: int = 0
160
+ unknown: int | None = 0 # None: the path was not walked
161
+ problem: str = "" # "no marker", "no path", "timeout" or "error: <what the system said>"
162
+
163
+
164
+ Drift = Callable[[list[DriftRequest], float], list[DriftResult]]
165
+
166
+
167
+ def load_child() -> dict:
168
+ """The child's code as a namespace, for a test or a stand-in that runs it in-process."""
169
+ namespace = {"__name__": "gfs_drift_child"}
170
+ exec(compile(CHILD_SOURCE, "<gfs drift child>", "exec"), namespace) # noqa: S102
171
+ return namespace
172
+
173
+
174
+ def _wire(request: DriftRequest) -> dict:
175
+ return {
176
+ "path": str(request.path), "marker": request.marker, "snapshot": request.snapshot,
177
+ "locations": list(request.locations), "known": list(request.known),
178
+ "walk": request.walk,
179
+ }
180
+
181
+
182
+ def _child_argv() -> list[str]:
183
+ """The command of the child; tests replace it with one that hangs."""
184
+ return [sys.executable, "-I", "-c", CHILD_SOURCE]
185
+
186
+
187
+ def _result(request: DriftRequest, line: dict) -> DriftResult:
188
+ if line["checked"]:
189
+ unknown = None if line["unknown"] is None else int(line["unknown"])
190
+ return DriftResult(request.path, True, int(line["missing"]), unknown)
191
+ return DriftResult(request.path, False, problem=str(line["problem"]))
192
+
193
+
194
+ def run_child(requests: list[DriftRequest], timeout_seconds: float) -> list[DriftResult]:
195
+ """Check each request in one child under one deadline; never raises.
196
+
197
+ A request the child did not answer before the deadline is ``timeout``: the child is killed
198
+ and not waited for, as a hard mount may not release it until its I/O ends. A child that
199
+ cannot start, or that stops early, leaves its unanswered requests with an ``error``.
200
+ """
201
+ if not requests:
202
+ return []
203
+ payload = json.dumps([_wire(request) for request in requests]).encode()
204
+ timed_out = False
205
+ try:
206
+ child = subprocess.Popen( # noqa: S603
207
+ _child_argv(), stdin=subprocess.PIPE, stdout=subprocess.PIPE,
208
+ stderr=subprocess.DEVNULL, close_fds=True,
209
+ )
210
+ except (OSError, ValueError) as exc:
211
+ return [DriftResult(r.path, False, problem=f"error: {exc}") for r in requests]
212
+ try:
213
+ output, _ = child.communicate(payload, timeout=timeout_seconds)
214
+ except subprocess.TimeoutExpired as exc:
215
+ output, timed_out = exc.stdout, True
216
+ child.kill()
217
+ except OSError:
218
+ output = None
219
+ child.kill()
220
+ for pipe in (child.stdin, child.stdout):
221
+ try:
222
+ if pipe is not None:
223
+ pipe.close()
224
+ except OSError:
225
+ pass
226
+ answered: dict[int, DriftResult] = {}
227
+ text = output.decode("utf-8", "replace") if isinstance(output, bytes) else (output or "")
228
+ for raw in text.split("\n")[:-1]: # what follows the last newline is incomplete or empty
229
+ try:
230
+ line = json.loads(raw)
231
+ answered[line["i"]] = _result(requests[line["i"]], line)
232
+ except (ValueError, KeyError, TypeError, IndexError):
233
+ break
234
+ why = "timeout" if timed_out else "error: the drift check ended early"
235
+ return [answered.get(i) or DriftResult(r.path, False, problem=why)
236
+ for i, r in enumerate(requests)]
@@ -46,6 +46,21 @@ def _bucket_label(day: date, period: str) -> str:
46
46
  return str(day.year)
47
47
 
48
48
 
49
+ def bucket_span(day: date, period: str) -> tuple[date, date]:
50
+ """The first and last day of the bucket of ``period`` that holds ``day``.
51
+
52
+ A bucket is the day itself (``daily``), its ISO week, its month or its year.
53
+ """
54
+ if period == "daily":
55
+ return day, day
56
+ if period == "weekly":
57
+ first = day - timedelta(days=day.weekday())
58
+ return first, first + timedelta(days=6)
59
+ if period == "monthly":
60
+ return day.replace(day=1), day.replace(day=calendar.monthrange(day.year, day.month)[1])
61
+ return date(day.year, 1, 1), date(day.year, 12, 31)
62
+
63
+
49
64
  def _eligibility(
50
65
  units: Sequence[Unit], today: date,
51
66
  ) -> tuple[dict[str, set[object]], Callable[[date, str], str | None]]: