bdbackup 0.6.3__tar.gz → 0.7.1__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 (79) hide show
  1. bdbackup-0.7.1/PKG-INFO +461 -0
  2. bdbackup-0.7.1/README.md +427 -0
  3. {bdbackup-0.6.3 → bdbackup-0.7.1}/bdbackup/backends.py +0 -1
  4. bdbackup-0.7.1/bdbackup/cli.py +434 -0
  5. {bdbackup-0.6.3 → bdbackup-0.7.1}/bdbackup/config.py +17 -22
  6. {bdbackup-0.6.3 → bdbackup-0.7.1}/bdbackup/filebackup.py +6 -9
  7. {bdbackup-0.6.3 → bdbackup-0.7.1}/bdbackup/gfs/runner.py +10 -5
  8. {bdbackup-0.6.3 → bdbackup-0.7.1}/bdbackup/gfs/stages.py +3 -6
  9. bdbackup-0.7.1/bdbackup/gfs/structure.py +71 -0
  10. {bdbackup-0.6.3 → bdbackup-0.7.1}/bdbackup/mysql/mysqldump.py +8 -16
  11. {bdbackup-0.6.3 → bdbackup-0.7.1}/bdbackup/mysql/xtrabackup.py +13 -18
  12. {bdbackup-0.6.3 → bdbackup-0.7.1}/bdbackup/validation.py +19 -42
  13. {bdbackup-0.6.3 → bdbackup-0.7.1}/config.toml.example +30 -72
  14. bdbackup-0.7.1/contrib/systemd/bdbackup-incremental@.service +11 -0
  15. bdbackup-0.7.1/contrib/systemd/bdbackup-incremental@.timer +10 -0
  16. bdbackup-0.7.1/contrib/systemd/bdbackup@.service +11 -0
  17. bdbackup-0.7.1/contrib/systemd/bdbackup@.timer +10 -0
  18. bdbackup-0.7.1/docs/README_ENGINES.md +63 -0
  19. bdbackup-0.7.1/docs/README_FILE.md +95 -0
  20. bdbackup-0.7.1/docs/README_GFS.md +255 -0
  21. bdbackup-0.7.1/docs/README_MYSQLDUMP.md +38 -0
  22. bdbackup-0.7.1/docs/README_SYSTEMD.md +138 -0
  23. bdbackup-0.7.1/docs/README_XTRABACKUP.md +164 -0
  24. {bdbackup-0.6.3 → bdbackup-0.7.1}/pyproject.toml +14 -4
  25. {bdbackup-0.6.3 → bdbackup-0.7.1}/scripts/integration_mysql.py +5 -5
  26. {bdbackup-0.6.3 → bdbackup-0.7.1}/scripts/integration_physical.py +11 -2
  27. {bdbackup-0.6.3 → bdbackup-0.7.1}/scripts/smoke_install.py +9 -33
  28. bdbackup-0.7.1/tests/AGENTS.md +126 -0
  29. {bdbackup-0.6.3 → bdbackup-0.7.1}/tests/test_architecture.py +1 -21
  30. bdbackup-0.7.1/tests/test_cli_reshape.py +338 -0
  31. {bdbackup-0.6.3 → bdbackup-0.7.1}/tests/test_encryption.py +9 -12
  32. {bdbackup-0.6.3 → bdbackup-0.7.1}/tests/test_engine_conditions.py +6 -23
  33. {bdbackup-0.6.3 → bdbackup-0.7.1}/tests/test_engines.py +3 -3
  34. {bdbackup-0.6.3 → bdbackup-0.7.1}/tests/test_gfs_config.py +25 -24
  35. bdbackup-0.7.1/tests/test_gfs_init.py +188 -0
  36. {bdbackup-0.6.3 → bdbackup-0.7.1}/tests/test_gfs_run.py +9 -7
  37. {bdbackup-0.6.3 → bdbackup-0.7.1}/tests/test_helpers.py +20 -185
  38. {bdbackup-0.6.3 → bdbackup-0.7.1}/tests/test_history.py +35 -50
  39. {bdbackup-0.6.3 → bdbackup-0.7.1}/tests/test_ledger.py +14 -14
  40. {bdbackup-0.6.3 → bdbackup-0.7.1}/tests/test_release_fixes.py +17 -95
  41. {bdbackup-0.6.3 → bdbackup-0.7.1}/tests/test_run_selector.py +3 -4
  42. {bdbackup-0.6.3 → bdbackup-0.7.1}/tests/test_safety_nets.py +1 -1
  43. bdbackup-0.7.1/tests/test_systemd_units.py +111 -0
  44. {bdbackup-0.6.3 → bdbackup-0.7.1}/tests/test_templates.py +7 -86
  45. bdbackup-0.6.3/PKG-INFO +0 -1035
  46. bdbackup-0.6.3/README.md +0 -1004
  47. bdbackup-0.6.3/bdbackup/cli.py +0 -1137
  48. bdbackup-0.6.3/bdbackup/dboperations.py +0 -88
  49. bdbackup-0.6.3/bdbackup/retention.py +0 -636
  50. bdbackup-0.6.3/bdbackup/scheduling.py +0 -198
  51. bdbackup-0.6.3/tests/test_cli.py +0 -65
  52. bdbackup-0.6.3/tests/test_retention.py +0 -327
  53. {bdbackup-0.6.3 → bdbackup-0.7.1}/.gitignore +0 -0
  54. {bdbackup-0.6.3 → bdbackup-0.7.1}/LICENSE +0 -0
  55. {bdbackup-0.6.3 → bdbackup-0.7.1}/bdbackup/__init__.py +0 -0
  56. {bdbackup-0.6.3 → bdbackup-0.7.1}/bdbackup/engines.py +0 -0
  57. {bdbackup-0.6.3 → bdbackup-0.7.1}/bdbackup/gfs/__init__.py +0 -0
  58. {bdbackup-0.6.3 → bdbackup-0.7.1}/bdbackup/gfs/actions.py +0 -0
  59. {bdbackup-0.6.3 → bdbackup-0.7.1}/bdbackup/gfs/policy.py +0 -0
  60. {bdbackup-0.6.3 → bdbackup-0.7.1}/bdbackup/gfs/store.py +0 -0
  61. {bdbackup-0.6.3 → bdbackup-0.7.1}/bdbackup/history.py +0 -0
  62. {bdbackup-0.6.3 → bdbackup-0.7.1}/bdbackup/ledger.py +0 -0
  63. {bdbackup-0.6.3 → bdbackup-0.7.1}/bdbackup/mysql/__init__.py +0 -0
  64. {bdbackup-0.6.3 → bdbackup-0.7.1}/bdbackup/mysql/helpers.py +0 -0
  65. {bdbackup-0.6.3 → bdbackup-0.7.1}/bdbackup/recovery.py +0 -0
  66. {bdbackup-0.6.3 → bdbackup-0.7.1}/bdbackup/templates/__init__.py +0 -0
  67. {bdbackup-0.6.3 → bdbackup-0.7.1}/bdbackup/templates/_matching.py +0 -0
  68. {bdbackup-0.6.3 → bdbackup-0.7.1}/bdbackup/templates/python_dev.py +0 -0
  69. {bdbackup-0.6.3 → bdbackup-0.7.1}/bdbackup/utils.py +0 -0
  70. {bdbackup-0.6.3 → bdbackup-0.7.1}/scripts/check_release.py +0 -0
  71. {bdbackup-0.6.3 → bdbackup-0.7.1}/template.txt +0 -0
  72. {bdbackup-0.6.3 → bdbackup-0.7.1}/tests/__init__.py +0 -0
  73. {bdbackup-0.6.3 → bdbackup-0.7.1}/tests/conftest.py +0 -0
  74. {bdbackup-0.6.3 → bdbackup-0.7.1}/tests/test_correctness.py +0 -0
  75. {bdbackup-0.6.3 → bdbackup-0.7.1}/tests/test_gfs_policy.py +0 -0
  76. {bdbackup-0.6.3 → bdbackup-0.7.1}/tests/test_gfs_store.py +0 -0
  77. {bdbackup-0.6.3 → bdbackup-0.7.1}/tests/test_import.py +0 -0
  78. {bdbackup-0.6.3 → bdbackup-0.7.1}/tests/test_performance.py +0 -0
  79. {bdbackup-0.6.3 → bdbackup-0.7.1}/tests/test_security.py +0 -0
@@ -0,0 +1,461 @@
1
+ Metadata-Version: 2.5
2
+ Name: bdbackup
3
+ Version: 0.7.1
4
+ Summary: MySQL, MariaDB and file backups with mysqldump, Percona XtraBackup, MariaDB Backup and tar: verification, GFS rotation and guided restore
5
+ Project-URL: Homepage, https://github.com/ayder/bdbackup
6
+ Project-URL: Repository, https://github.com/ayder/bdbackup
7
+ Project-URL: Documentation, https://github.com/ayder/bdbackup/blob/master/README.md
8
+ Project-URL: Issues, https://github.com/ayder/bdbackup/issues
9
+ Author-email: Sinan Alyuruk <sinan@dbsmedya.com>
10
+ License-Expression: MIT
11
+ License-File: LICENSE
12
+ Keywords: backup,backup-rotation,cli,gfs,grandfather-father-son,incremental-backup,mariabackup,mariadb,mariadb-backup,mysql,mysqldump,percona,restore,tar,xtrabackup
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Environment :: Console
15
+ Classifier: Intended Audience :: System Administrators
16
+ Classifier: Operating System :: MacOS
17
+ Classifier: Operating System :: POSIX
18
+ Classifier: Operating System :: POSIX :: Linux
19
+ Classifier: Programming Language :: Python :: 3
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Programming Language :: Python :: 3.14
23
+ Classifier: Topic :: Database
24
+ Classifier: Topic :: System :: Archiving :: Backup
25
+ Requires-Python: >=3.12
26
+ Requires-Dist: click>=8.0
27
+ Provides-Extra: dev
28
+ Requires-Dist: build; extra == 'dev'
29
+ Requires-Dist: pytest-cov; extra == 'dev'
30
+ Requires-Dist: pytest>=7.0; extra == 'dev'
31
+ Requires-Dist: ruff; extra == 'dev'
32
+ Requires-Dist: twine; extra == 'dev'
33
+ Description-Content-Type: text/markdown
34
+
35
+ # bdbackup
36
+
37
+ **Backups by design.**
38
+
39
+ bdbackup is a command-line backup tool and Python library for MySQL, MariaDB and
40
+ files on Linux and macOS. It takes MySQL and MariaDB backups with mysqldump,
41
+ Percona XtraBackup and MariaDB Backup (full and incremental physical backups,
42
+ compressed and optionally encrypted), archives files and directories as tar,
43
+ tar.gz or tar.zst, and rotates the results across storage stages with GFS
44
+ (grandfather-father-son) retention. Every backup is verified before it is
45
+ published and recorded with a SHA-256 checksum in an SQLite backup history, from
46
+ which a guided restore prepares a recovery copy. Jobs live in one TOML file and
47
+ run from cron.
48
+
49
+ ## Features
50
+
51
+ - [MySQL and MariaDB physical backups](https://github.com/ayder/bdbackup/blob/master/docs/README_XTRABACKUP.md) with Percona
52
+ XtraBackup and MariaDB Backup: full and incremental, compressed, AES-256
53
+ encrypted with Percona, prepared for recovery with `restore --backup`.
54
+ - [MySQL and MariaDB logical backups](https://github.com/ayder/bdbackup/blob/master/docs/README_MYSQLDUMP.md) with mysqldump,
55
+ gzip-compressed, one database or all.
56
+ - [File and directory backups](https://github.com/ayder/bdbackup/blob/master/docs/README_FILE.md) as tar archives, with
57
+ gitignore-style exclusion templates.
58
+ - [GFS (grandfather-father-son) backup rotation](https://github.com/ayder/bdbackup/blob/master/docs/README_GFS.md): daily,
59
+ weekly, monthly and yearly stages on local disks and NFS mounts, driven by a
60
+ checksummed backup ledger.
61
+ - [Backup history and guided restore](#backup-history-and-guided-restore) with
62
+ SHA-256 checksums in SQLite.
63
+ - [Configuration validation](#validate-configuration-and-permissions) of
64
+ settings, filesystem permissions and MySQL grants, without running a backup.
65
+ - [Custom backup engines](https://github.com/ayder/bdbackup/blob/master/docs/README_ENGINES.md) as plugins.
66
+
67
+ ## Documentation
68
+
69
+ | Document | Covers |
70
+ |---|---|
71
+ | [File and directory backups with tar](https://github.com/ayder/bdbackup/blob/master/docs/README_FILE.md) | file jobs, template files, exclusion templates, restoring an archive |
72
+ | [MySQL and MariaDB logical backups with mysqldump](https://github.com/ayder/bdbackup/blob/master/docs/README_MYSQLDUMP.md) | mysqldump jobs, credentials, default options |
73
+ | [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 |
74
+ | [GFS (grandfather-father-son) backup rotation](https://github.com/ayder/bdbackup/blob/master/docs/README_GFS.md) | stages, preparing stage directories, safety rules, run and step logs, ledger copies |
75
+ | [Custom backup engines (plugins)](https://github.com/ayder/bdbackup/blob/master/docs/README_ENGINES.md) | the engine registry and writing your own engine |
76
+ | [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 |
77
+ | [Annotated configuration](https://github.com/ayder/bdbackup/blob/master/config.toml.example) | every config key with a comment |
78
+
79
+ ## Support and safety
80
+
81
+ Python 3.12+ on POSIX systems (Linux/macOS); Windows is not supported.
82
+ `tar` and `tar.gz` work on every supported Python; `tar.zst` requires Python 3.14
83
+ with Zstandard support. Database binaries are separate system dependencies.
84
+
85
+ Every built-in backend verifies staging output before publishing it. A missing
86
+ or unreadable file fails the backup and preserves the previous archive. A process
87
+ lock prevents concurrent writers to the same file destination or physical root.
88
+ `--no-verify` skips only the additional verification pass after publication.
89
+ Verification checks archive readability or physical checkpoints; it does not
90
+ replace testing a restore. File backups are not filesystem snapshots: quiesce
91
+ applications or back up snapshots when files can change during a run.
92
+
93
+ Safe relative symlinks, hardlinks, empty directories and ordinary directory
94
+ permissions/timestamps round-trip. Restore rejects escaping paths/links and
95
+ special files on all supported Python versions. Ownership and privileged
96
+ permission bits are intentionally not restored. Use a destination that is not
97
+ being modified by another process during extraction.
98
+
99
+ ## Installation
100
+
101
+ Install the current code from the original GitHub repository:
102
+
103
+ ```bash
104
+ pip install "git+https://github.com/ayder/bdbackup.git"
105
+ ```
106
+
107
+ From PyPI:
108
+
109
+ ```bash
110
+ pip install bdbackup
111
+ ```
112
+
113
+ For development:
114
+
115
+ ```bash
116
+ git clone https://github.com/ayder/bdbackup.git
117
+ cd bdbackup
118
+ pip install -e ".[dev]"
119
+ ```
120
+
121
+ ## Commands
122
+
123
+ `bdbackup` has three commands; everything else is an option:
124
+
125
+ ```bash
126
+ bdbackup run -c CONFIG -j JOB [--full | --incremental] [--no-verify] [--dry-run]
127
+ bdbackup run -c CONFIG --validate [-j JOB]
128
+ bdbackup run -c CONFIG -j GFS_JOB --initialize-structure
129
+ bdbackup restore -c CONFIG [--backup-id N] [--job JOB] [-y] [-d DIR] [--encrypt-key-file KEY]
130
+ bdbackup restore --archive ARCHIVE -d DIR
131
+ bdbackup restore --backup BACKUP --root ROOT -d DIR [--binary BINARY] [--encrypt-key-file KEY]
132
+ bdbackup history -c CONFIG [--job JOB] [--successful | --create-checksum]
133
+ ```
134
+
135
+ `-c` is `--config` on every command; `-j` is the short form of `--job` on `run`
136
+ only (`restore` and `history` take `--job`). `bdbackup` itself takes only
137
+ `--version`, `--help` and `--logging LEVEL`, placed before the command:
138
+ `bdbackup --logging DEBUG run -c config.toml -j files-daily`. Levels: `DEBUG`,
139
+ `INFO`, `WARNING`, `ERROR`.
140
+
141
+ The CLI uses these exit codes:
142
+
143
+ | Code | Meaning |
144
+ |------|---------|
145
+ | 0 | Success |
146
+ | 1 | Backup/verify failure (including a job whose backend rejects its settings in a real run), or validation checks failed/incomplete |
147
+ | 2 | Usage error, an inactive job, or a configuration error found when the config loads or by `--dry-run` |
148
+ | 3 | Lock held; for GFS, another run of the job is in progress or only deferred work remains |
149
+
150
+ ## Config-driven jobs
151
+
152
+ Every backup is a job in a TOML config file. Convention: keep all bdbackup
153
+ settings under `~/.config/bdbackup/` (honours `$XDG_CONFIG_HOME` /
154
+ `$BDBACKUP_CONFIG_DIR`) — `config.toml`, the `files.template` path lists,
155
+ `templates/*.py` exclusion presets, and `engines/*.py` database engines.
156
+
157
+ ```toml
158
+ # ~/.config/bdbackup/config.toml
159
+ [files-daily]
160
+ type = "file"
161
+ template_filename = "~/.config/bdbackup/files.template"
162
+ backup_dst = "/backup/files/daily"
163
+ chdir = "/srv/www" # source path: template/exclude entries resolve against it
164
+ format = "tar.gz" # tar.zst requires Python 3.14+
165
+ exclude_pattern = ["*.log", "node_modules"]
166
+ exclude_templates = ["python-dev"]
167
+
168
+ [mysql-prod]
169
+ type = "xtrabackup"
170
+ backup_root = "/backup/mysql/production"
171
+ user = "xtrabackup"
172
+ retention_days = 7
173
+ parallel = 2
174
+
175
+ [mysqldump-all]
176
+ type = "mysqldump"
177
+ out_dir = "/backup/mysql/dumps"
178
+ user = "backup"
179
+ options = ["--single-transaction", "--all-databases"]
180
+ ```
181
+
182
+ Configuration paths expand `~`; relative config paths resolve against the
183
+ config file's directory. Template entries and `exclude` entries resolve against
184
+ `chdir` (or the process working directory if omitted). For a single-database
185
+ mysqldump job, set `database = "mydatabase"`; for all databases include
186
+ `--all-databases` in `options`.
187
+
188
+ Except for the optional `[history]` settings, each top-level table is one job;
189
+ its keys (except `type`, `active` and `restore_root`) are passed
190
+ to the backend constructor, so they use Python-style underscores
191
+ (`exclude_templates`). See [config.toml.example](https://github.com/ayder/bdbackup/blob/master/config.toml.example)
192
+ for a fully annotated config with every option explained.
193
+
194
+ Run one job:
195
+
196
+ ```bash
197
+ bdbackup run -c ~/.config/bdbackup/config.toml -j mysql-prod
198
+ ```
199
+
200
+ An xtrabackup job also takes `--incremental`; see
201
+ [MySQL and MariaDB physical backups](https://github.com/ayder/bdbackup/blob/master/docs/README_XTRABACKUP.md#full-and-incremental-backups).
202
+
203
+ ### Dry run
204
+
205
+ `--dry-run` reports what a job would do: it runs no backup tool, writes no
206
+ backup and records no history; a GFS dry run creates only its job's lock file
207
+ beside the history database. What each job type reports is described with it:
208
+ [file jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_FILE.md#dry-run),
209
+ [mysqldump jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_MYSQLDUMP.md#dry-run),
210
+ [xtrabackup jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_XTRABACKUP.md#dry-run) and
211
+ [GFS jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_GFS.md#dry-run).
212
+
213
+ A dry run exits 1 where the real run would fail before writing anything (an
214
+ incremental without a full, a file job that selects nothing). `--dry-run` cannot
215
+ be combined with `--verify` or `--no-verify`.
216
+
217
+ ### Pausing a job
218
+
219
+ Set `active = false` in a job's table to pause it. Every
220
+ `run -j` of that job, including `--dry-run` and `--validate -j`, then exits 2 with
221
+ `Job '<name>' is inactive (active = false)`, and a full `--validate` names it as
222
+ not checked. `active` defaults to `true`. Configuration rules still apply to an
223
+ inactive job, and GFS still rotates its backups.
224
+
225
+ ### Scheduling with cron
226
+
227
+ bdbackup does not install schedules. Add crontab lines yourself,
228
+ run as the OS account the backups belong to. For example, a weekly full on
229
+ Sunday, incrementals on the other days, a nightly file backup, and GFS after
230
+ the backups:
231
+
232
+ ```cron
233
+ 0 2 * * 0 bdbackup run -c /opt/dbs/config.toml -j mysql-prod
234
+ 0 2 * * 1-6 bdbackup run -c /opt/dbs/config.toml -j mysql-prod --incremental
235
+ 30 2 * * * bdbackup run -c /opt/dbs/config.toml -j files-daily
236
+ 0 4 * * * bdbackup run -c /opt/dbs/config.toml -j gfs-main
237
+ ```
238
+
239
+ Times use the cron daemon's timezone, and separate lines do not wait for each
240
+ other: leave enough time for backups before GFS. Add `--dry-run` to the GFS line
241
+ until its report looks right.
242
+
243
+ xtrabackup jobs can run from systemd timers instead, which also stop the backup
244
+ tool if bdbackup dies and add per-job limits: see
245
+ [Running xtrabackup jobs with systemd timers](https://github.com/ayder/bdbackup/blob/master/docs/README_SYSTEMD.md).
246
+
247
+ ### Validate configuration and permissions
248
+
249
+ Check all configured jobs without creating a backup or running retention:
250
+
251
+ ```bash
252
+ bdbackup run -c /opt/dbs/config.toml --validate
253
+ # Or validate only one job:
254
+ bdbackup run -c /opt/dbs/config.toml --validate -j mysql-prod
255
+ ```
256
+
257
+ `--validate` cannot be combined with `--full`, `--incremental`, `--verify`,
258
+ `--no-verify` or `--dry-run`. Run validation as the OS account that will run your cron jobs. It checks backend
259
+ settings, required executables, destination access, SQLite/recovery directories,
260
+ file-template sources, and encryption key requirements. Missing directories are
261
+ reported with `mkdir -p` guidance and the required OS-user permissions. A missing
262
+ directory that the backend can create under a writable parent is reported as
263
+ creatable; validation does not create it.
264
+
265
+ For MySQL jobs, the installed `mysql`/`mariadb` client authenticates using the job's
266
+ credentials and reads `CURRENT_USER()`, server version, datadir and `SHOW GRANTS`.
267
+ Passwords are passed through a temporary mode-0600 options file, removed afterward.
268
+ No `CREATE USER` or `GRANT` is executed. Missing privileges produce SQL for an
269
+ administrator, for example:
270
+
271
+ ```sql
272
+ GRANT RELOAD, BACKUP_ADMIN, REPLICATION CLIENT, PROCESS, LOCK TABLES
273
+ ON *.* TO 'xtrabackup_user'@'localhost';
274
+ GRANT SELECT ON `performance_schema`.`log_status`
275
+ TO 'xtrabackup_user'@'localhost';
276
+ ```
277
+
278
+ The helper also checks the performance-schema tables used by current Percona
279
+ XtraBackup and prints `CREATE TABLESPACE` separately as an optional privilege for
280
+ importing individual tables. MariaDB Backup gets its own privilege recommendations.
281
+ See [Percona privileges](https://docs.percona.com/percona-xtrabackup/8.4/privileges.html)
282
+ and [MariaDB Backup privileges](https://mariadb.com/docs/server/server-usage/backup-and-restore/mariadb-backup/mariadb-backup-overview).
283
+
284
+ Checks cover direct grants; role-derived privileges and partial revokes may need
285
+ manual review. Physical datadir checks cover root-directory access, not every data
286
+ file or external tablespace. Custom mysqldump options, routine visibility, GTID
287
+ settings and exact server/binary version compatibility still need review.
288
+ For a GFS job, every stage path after the first must exist and be writable, and
289
+ its `.bdbackup-destination` marker must be present and writable; a missing
290
+ marker's line names the `--initialize-structure` command that creates it.
291
+ An unreachable database or missing client is a failed/incomplete check, not a pass.
292
+ Validation does not add SQLite history rows. It exits 0 when its checks pass, 1
293
+ for failed or incomplete checks, and 2 for invalid command or configuration syntax.
294
+
295
+ ## Backup history and guided restore
296
+
297
+ Enable SQLite history in your TOML configuration. No extra Python dependency
298
+ or database server is required:
299
+
300
+ ```toml
301
+ [history]
302
+ database = "state/history.sqlite3"
303
+ restore_root = "/restore/bdbackup"
304
+ ```
305
+
306
+ Both paths expand `~`; relative paths resolve against the configuration file.
307
+ `restore_root` defaults to `restores` beside that file. Omitting `[history]`
308
+ disables history. File jobs automatically exclude this live database and its
309
+ SQLite journal files; keep it outside backup inputs when possible. New history
310
+ databases are created with permissions `0600`.
311
+
312
+ `run` records every backup attempt of a configured job:
313
+
314
+ ```bash
315
+ bdbackup run -c config.toml -j files-daily
316
+ bdbackup history -c config.toml
317
+ bdbackup history -c config.toml --job files-daily --successful
318
+ ```
319
+
320
+ Each record contains an ID, job name, backup type, UTC start/completion times,
321
+ status (`running`, `success`, or `failed`), and the successful artifact's absolute
322
+ path and size. Physical full and incremental runs record their respective types
323
+ and the root/binary needed for preparation.
324
+ Credentials and raw error messages are not stored; failed rows contain only the
325
+ exception class. Restores, validation, GFS runs and dry runs are not backup
326
+ attempts and create no backup-attempt rows. Direct Python backend calls are not automatically
327
+ recorded; applications can wrap them with `History.run`.
328
+
329
+ Every successful backup also records its unit and a SHA-256 checksum taken right
330
+ after the backup, which costs one extra read of the backup. A file's checksum is
331
+ the SHA-256 of its content. A directory's checksum is the SHA-256 of a manifest
332
+ with one line per regular file, `<sha256> <relative path>`, sorted by path; a
333
+ symlink or special file inside a physical backup fails the backup. The unit is
334
+ what a rotation tool moves as one piece: the archive or dump file itself, or for
335
+ xtrabackup the dated directory that holds the full and all of its incrementals.
336
+ `bdbackup history` shows it as `unit <path>`, or `unit -` for records without one.
337
+ For units that GFS manages, the line continues with `| stage <stage path> |
338
+ locations <path>, …`, or `| deleted <time>` once GFS has removed the unit.
339
+ Reproduce a directory checksum on Linux (use `shasum -a 256` on macOS):
340
+
341
+ ```bash
342
+ cd /backup/mysql/production/2026-09-29/Full_<id> && find . -type f -print0 \
343
+ | LC_ALL=C sort -z | xargs -0 sha256sum | sed 's| \./| |' | sha256sum
344
+ ```
345
+
346
+ Records written by bdbackup 0.6.2 or earlier have no checksum. Record them explicitly:
347
+
348
+ ```bash
349
+ bdbackup history -c config.toml --create-checksum
350
+ bdbackup history -c config.toml --create-checksum --job mysql-prod
351
+ ```
352
+
353
+ It prints `<id>: recorded`, `<id>: skipped: unavailable` for an artifact that is
354
+ missing or was replaced, or `<id>: skipped: unexpected unit` for a physical backup
355
+ outside its dated layout, and then exits 1. A checksum already recorded is never
356
+ changed. `--create-checksum` cannot be combined with `--successful`. The checksum lives in the `checksum` column of the `backup_runs` table.
357
+
358
+ History uses schema version 5. A database at an older schema upgrades on the next
359
+ write; bdbackup 0.6.2 or earlier refuses a version-5 database.
360
+
361
+ History is written before work starts, and success only after the backup and its
362
+ requested verification finish. If history cannot be written, the command fails;
363
+ an artifact already created is preserved. A forcibly killed process may leave a
364
+ `running` row, which is never offered for restore. Existing backups are not
365
+ imported automatically.
366
+
367
+ Select a successful backup interactively:
368
+
369
+ ```bash
370
+ bdbackup restore -c config.toml
371
+ bdbackup restore -c config.toml --job files-daily
372
+ ```
373
+
374
+ Each backup job may set `restore_root = "/restore/mysql-prod"` to override
375
+ `[history] restore_root` for its guided-restore suggestions. It must be a nonempty
376
+ path string; `~` expands and relative paths resolve against the config file.
377
+ Job-level `restore_root` requires `[history]`.
378
+ Validation checks that each job's root is writable or can be created.
379
+ Physical jobs usually need a separate root with room for the full and its
380
+ incrementals, staged near the database datadir.
381
+
382
+ The current config's job is matched by the history record's job name. If that job
383
+ has no `restore_root`, or is no longer configured, the history root is used.
384
+ An explicit `--dst` always wins.
385
+
386
+ Restore lists successful, available artifacts, asks for the backup ID, suggests
387
+ `<restore_root>/<job>-<id>`, and asks for confirmation. You can edit the suggested
388
+ path. Repeated restores suggest a numbered alternative; history-based restore
389
+ requires a new directory even when `--dst` is supplied. For automation, specify
390
+ the exact backup ID and use `--yes`:
391
+
392
+ ```bash
393
+ bdbackup restore -c config.toml --backup-id 12 --dst /restore/job-12 --yes
394
+ ```
395
+
396
+ What a restore produces depends on the job type; see
397
+ [file jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_FILE.md#history-restore),
398
+ [mysqldump jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_MYSQLDUMP.md#history-restore),
399
+ [xtrabackup jobs](https://github.com/ayder/bdbackup/blob/master/docs/README_XTRABACKUP.md#history-restore) and
400
+ [custom engines](https://github.com/ayder/bdbackup/blob/master/docs/README_ENGINES.md#history-restore).
401
+
402
+ Deleted artifacts remain in history as unavailable. File identity, size, and
403
+ modification time detect replaced archives, so older rows for a reused filename
404
+ are not offered as older recovery points. Availability uses these file checks.
405
+ Restore checks the recorded checksum of every file it uses for backups that GFS
406
+ manages (see [GFS backup rotation](https://github.com/ayder/bdbackup/blob/master/docs/README_GFS.md)); for other backups it
407
+ validates the actual archive or physical dependency chain. History stores
408
+ references to artifacts and does not preserve an archive that a later backup
409
+ replaces.
410
+
411
+ ## Development
412
+
413
+ Run tests and linting:
414
+
415
+ ```bash
416
+ pytest
417
+ ruff check bdbackup tests scripts
418
+ ```
419
+
420
+ Optional database integration tests use disposable, network-isolated Docker
421
+ containers with synthetic data. They remove only the containers and volumes
422
+ created for that run. Pull the matching images before running:
423
+
424
+ ```bash
425
+ python scripts/integration_mysql.py # mysql:8.4
426
+ python scripts/integration_physical.py percona # percona-server/xtrabackup:8.4
427
+ python scripts/integration_physical.py percona-encrypted # AES256 + zstd recovery
428
+ python scripts/integration_physical.py mariadb # mariadb:11.4
429
+ ```
430
+
431
+ Physical recovery returns a prepared data directory; copying it into a server's
432
+ data directory, assigning ownership to the server user, and starting that server
433
+ are separate administrator actions. Use the same database version and
434
+ filesystem case-sensitivity as the source.
435
+
436
+ `pyproject.toml` (`project.version`) is the sole version source. The package's
437
+ `__version__` and CLI read installed distribution metadata generated from it.
438
+ After changing the version, run `uv lock` to refresh the generated lockfile and
439
+ reinstall with `pip install -e '.[dev]'` to refresh local metadata. Source
440
+ development requires this editable installation.
441
+
442
+ Build and validate a release:
443
+
444
+ ```bash
445
+ python -m build
446
+ twine check dist/*
447
+ python scripts/smoke_install.py dist
448
+ ```
449
+
450
+ Commit the validated changes and create an annotated tag named
451
+ `v<project.version>`. The publishing workflow accepts only that matching tag. It
452
+ runs the reusable CI workflow on that commit (tests on Python 3.12–3.14, lint,
453
+ real MySQL/Percona/MariaDB recovery tests, source/wheel build, Twine, and an
454
+ installed-wheel recovery smoke test), then
455
+ uploads those exact artifacts. Configure the PyPI trusted publisher for
456
+ `ayder/bdbackup`, `publish.yml`, environment `pypi` before releasing. Account
457
+ configuration and actual database recovery evidence are release prerequisites.
458
+
459
+ ## License
460
+
461
+ MIT License. See [LICENSE](https://github.com/ayder/bdbackup/blob/master/LICENSE).