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