bdbackup 0.6.2__tar.gz → 0.6.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {bdbackup-0.6.2 → bdbackup-0.6.3}/PKG-INFO +242 -8
- {bdbackup-0.6.2 → bdbackup-0.6.3}/README.md +241 -7
- {bdbackup-0.6.2 → bdbackup-0.6.3}/bdbackup/cli.py +87 -18
- {bdbackup-0.6.2 → bdbackup-0.6.3}/bdbackup/config.py +15 -1
- {bdbackup-0.6.2 → bdbackup-0.6.3}/bdbackup/filebackup.py +15 -3
- bdbackup-0.6.3/bdbackup/gfs/__init__.py +0 -0
- bdbackup-0.6.3/bdbackup/gfs/actions.py +196 -0
- bdbackup-0.6.3/bdbackup/gfs/policy.py +134 -0
- bdbackup-0.6.3/bdbackup/gfs/runner.py +398 -0
- bdbackup-0.6.3/bdbackup/gfs/stages.py +174 -0
- bdbackup-0.6.3/bdbackup/gfs/store.py +346 -0
- {bdbackup-0.6.2 → bdbackup-0.6.3}/bdbackup/history.py +118 -3
- bdbackup-0.6.3/bdbackup/ledger.py +74 -0
- {bdbackup-0.6.2 → bdbackup-0.6.3}/bdbackup/mysql/xtrabackup.py +16 -3
- bdbackup-0.6.3/bdbackup/recovery.py +155 -0
- {bdbackup-0.6.2 → bdbackup-0.6.3}/bdbackup/scheduling.py +3 -1
- {bdbackup-0.6.2 → bdbackup-0.6.3}/bdbackup/validation.py +24 -2
- {bdbackup-0.6.2 → bdbackup-0.6.3}/config.toml.example +50 -0
- {bdbackup-0.6.2 → bdbackup-0.6.3}/pyproject.toml +1 -1
- {bdbackup-0.6.2 → bdbackup-0.6.3}/scripts/integration_mysql.py +57 -0
- {bdbackup-0.6.2 → bdbackup-0.6.3}/scripts/integration_physical.py +97 -5
- {bdbackup-0.6.2 → bdbackup-0.6.3}/tests/test_encryption.py +5 -2
- bdbackup-0.6.3/tests/test_engine_conditions.py +132 -0
- {bdbackup-0.6.2 → bdbackup-0.6.3}/tests/test_engines.py +1 -1
- bdbackup-0.6.3/tests/test_gfs_config.py +165 -0
- bdbackup-0.6.3/tests/test_gfs_policy.py +143 -0
- bdbackup-0.6.3/tests/test_gfs_run.py +941 -0
- bdbackup-0.6.3/tests/test_gfs_store.py +103 -0
- bdbackup-0.6.3/tests/test_ledger.py +244 -0
- bdbackup-0.6.2/bdbackup/recovery.py +0 -80
- {bdbackup-0.6.2 → bdbackup-0.6.3}/.gitignore +0 -0
- {bdbackup-0.6.2 → bdbackup-0.6.3}/LICENSE +0 -0
- {bdbackup-0.6.2 → bdbackup-0.6.3}/bdbackup/__init__.py +0 -0
- {bdbackup-0.6.2 → bdbackup-0.6.3}/bdbackup/backends.py +0 -0
- {bdbackup-0.6.2 → bdbackup-0.6.3}/bdbackup/dboperations.py +0 -0
- {bdbackup-0.6.2 → bdbackup-0.6.3}/bdbackup/engines.py +0 -0
- {bdbackup-0.6.2 → bdbackup-0.6.3}/bdbackup/mysql/__init__.py +0 -0
- {bdbackup-0.6.2 → bdbackup-0.6.3}/bdbackup/mysql/helpers.py +0 -0
- {bdbackup-0.6.2 → bdbackup-0.6.3}/bdbackup/mysql/mysqldump.py +0 -0
- {bdbackup-0.6.2 → bdbackup-0.6.3}/bdbackup/retention.py +0 -0
- {bdbackup-0.6.2 → bdbackup-0.6.3}/bdbackup/templates/__init__.py +0 -0
- {bdbackup-0.6.2 → bdbackup-0.6.3}/bdbackup/templates/_matching.py +0 -0
- {bdbackup-0.6.2 → bdbackup-0.6.3}/bdbackup/templates/python_dev.py +0 -0
- {bdbackup-0.6.2 → bdbackup-0.6.3}/bdbackup/utils.py +0 -0
- {bdbackup-0.6.2 → bdbackup-0.6.3}/scripts/check_release.py +0 -0
- {bdbackup-0.6.2 → bdbackup-0.6.3}/scripts/smoke_install.py +0 -0
- {bdbackup-0.6.2 → bdbackup-0.6.3}/template.txt +0 -0
- {bdbackup-0.6.2 → bdbackup-0.6.3}/tests/__init__.py +0 -0
- {bdbackup-0.6.2 → bdbackup-0.6.3}/tests/conftest.py +0 -0
- {bdbackup-0.6.2 → bdbackup-0.6.3}/tests/test_architecture.py +0 -0
- {bdbackup-0.6.2 → bdbackup-0.6.3}/tests/test_cli.py +0 -0
- {bdbackup-0.6.2 → bdbackup-0.6.3}/tests/test_correctness.py +0 -0
- {bdbackup-0.6.2 → bdbackup-0.6.3}/tests/test_helpers.py +0 -0
- {bdbackup-0.6.2 → bdbackup-0.6.3}/tests/test_history.py +0 -0
- {bdbackup-0.6.2 → bdbackup-0.6.3}/tests/test_import.py +0 -0
- {bdbackup-0.6.2 → bdbackup-0.6.3}/tests/test_performance.py +0 -0
- {bdbackup-0.6.2 → bdbackup-0.6.3}/tests/test_release_fixes.py +0 -0
- {bdbackup-0.6.2 → bdbackup-0.6.3}/tests/test_retention.py +0 -0
- {bdbackup-0.6.2 → bdbackup-0.6.3}/tests/test_run_selector.py +0 -0
- {bdbackup-0.6.2 → bdbackup-0.6.3}/tests/test_safety_nets.py +0 -0
- {bdbackup-0.6.2 → bdbackup-0.6.3}/tests/test_security.py +0 -0
- {bdbackup-0.6.2 → bdbackup-0.6.3}/tests/test_templates.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: bdbackup
|
|
3
|
-
Version: 0.6.
|
|
3
|
+
Version: 0.6.3
|
|
4
4
|
Summary: File and MySQL/MariaDB backups with verification, retention, and guided recovery
|
|
5
5
|
Project-URL: Homepage, https://github.com/ayder/bdbackup
|
|
6
6
|
Project-URL: Repository, https://github.com/ayder/bdbackup
|
|
@@ -145,10 +145,16 @@ Options:
|
|
|
145
145
|
| `--exclude-pattern` | Glob pattern to exclude (repeatable) |
|
|
146
146
|
| `--exclude-template` | Named exclusion template, e.g. `python-dev` (repeatable, comma-separated allowed) |
|
|
147
147
|
| `--follow-symlinks` | Follow symbolic links when archiving |
|
|
148
|
+
| `--timestamp / --no-timestamp` | Write `<dst>-<UTC YYYY-MM-DD-HHMMSS><ext>` instead of replacing one archive; an existing name is never overwritten (default: off) |
|
|
148
149
|
| `--dry-run` | List what would be archived without writing anything |
|
|
149
150
|
| `--verify / --no-verify` | Verify the archive after creation (default: on) |
|
|
150
151
|
| `--logging` | Log level: `DEBUG`, `INFO`, `WARNING`, `ERROR` |
|
|
151
152
|
|
|
153
|
+
Without `--timestamp`, every run replaces the same archive, so only the newest
|
|
154
|
+
run stays restorable. With it, each run writes a new archive such as
|
|
155
|
+
`daily-2026-09-29-020000.tar.gz`, and a run that would reuse an existing name
|
|
156
|
+
fails instead. Config jobs set `timestamp = true`.
|
|
157
|
+
|
|
152
158
|
Restore a file archive:
|
|
153
159
|
|
|
154
160
|
```bash
|
|
@@ -349,7 +355,7 @@ Options:
|
|
|
349
355
|
| `--encrypt-key-file` | Required 32-byte key file when encrypting; also used by `prepare` |
|
|
350
356
|
| `--parallel` | Number of copy threads (default: 1) |
|
|
351
357
|
| `--throttle` | Limit I/O to this many IOPS |
|
|
352
|
-
| `--retention` | Days of backups to keep (default: 5) |
|
|
358
|
+
| `--retention` | Days of backups to keep (default: 5); `0` disables engine deletion |
|
|
353
359
|
| `--verify / --no-verify` | Verify the backup after creation (default: on) |
|
|
354
360
|
|
|
355
361
|
A process lock prevents two backup runs from corrupting the same backup root.
|
|
@@ -415,7 +421,11 @@ it. Original backups remain encrypted; the recovery directory contains plaintext
|
|
|
415
421
|
For manual `xtrabackup prepare`, supply `--encrypt-key-file` as well.
|
|
416
422
|
See [Percona's encryption documentation](https://docs.percona.com/percona-xtrabackup/8.4/encrypt-backups.html).
|
|
417
423
|
|
|
418
|
-
## Retention
|
|
424
|
+
## Retention of flat files (`type = "retention"`)
|
|
425
|
+
|
|
426
|
+
This section handles flat backup files written by other tools. For bdbackup's
|
|
427
|
+
own backups, use `type = "gfs"` (see [Ledger and GFS](#ledger-and-gfs)), which
|
|
428
|
+
moves backups between storage tiers using the history ledger.
|
|
419
429
|
|
|
420
430
|
The `bdbackup retention` command applies a grandfather-father-son policy to
|
|
421
431
|
a backup tree: keep **every** backup for the last N days, then **one per ISO
|
|
@@ -556,7 +566,9 @@ For example, schedule a weekly full on Sunday and incrementals on the other days
|
|
|
556
566
|
|
|
557
567
|
Pruning after each full deletes whole dated chains older than `retention_days`.
|
|
558
568
|
Set `retention_days` longer than the interval between fulls to preserve the previous
|
|
559
|
-
full's incrementals.
|
|
569
|
+
full's incrementals. `retention_days = 0` disables engine deletion for the job,
|
|
570
|
+
both the automatic pruning after a full and `bdbackup xtrabackup prune`; use it
|
|
571
|
+
when another tool rotates the backups. History now records configured physical backups as
|
|
560
572
|
`xtrabackup-full` / `xtrabackup-incremental` (previously `xtrabackup`); update filters
|
|
561
573
|
that use the old type. Existing history rows are unchanged.
|
|
562
574
|
|
|
@@ -696,6 +708,38 @@ exception class. Retention, restore operations, and file dry runs are not backup
|
|
|
696
708
|
attempts and do not create rows. Direct Python backend calls are not automatically
|
|
697
709
|
recorded; applications can wrap them with `History.run`.
|
|
698
710
|
|
|
711
|
+
Every successful backup also records its unit and a SHA-256 checksum taken right
|
|
712
|
+
after the backup, which costs one extra read of the backup. A file's checksum is
|
|
713
|
+
the SHA-256 of its content. A directory's checksum is the SHA-256 of a manifest
|
|
714
|
+
with one line per regular file, `<sha256> <relative path>`, sorted by path; a
|
|
715
|
+
symlink or special file inside a physical backup fails the backup. The unit is
|
|
716
|
+
what a rotation tool moves as one piece: the archive or dump file itself, or for
|
|
717
|
+
xtrabackup the dated directory that holds the full and all of its incrementals.
|
|
718
|
+
`bdbackup history` shows it as `unit <path>`, or `unit -` for records without one.
|
|
719
|
+
For units that GFS manages, the line continues with `| stage <stage path> |
|
|
720
|
+
locations <path>, …`, or `| deleted <time>` once GFS has removed the unit.
|
|
721
|
+
Reproduce a directory checksum on Linux (use `shasum -a 256` on macOS):
|
|
722
|
+
|
|
723
|
+
```bash
|
|
724
|
+
cd /backup/mysql/production/2026-09-29/Full_<id> && find . -type f -print0 \
|
|
725
|
+
| LC_ALL=C sort -z | xargs -0 sha256sum | sed 's| \./| |' | sha256sum
|
|
726
|
+
```
|
|
727
|
+
|
|
728
|
+
Records taken before this release have no checksum. Record them explicitly:
|
|
729
|
+
|
|
730
|
+
```bash
|
|
731
|
+
bdbackup history checksum --config config.toml
|
|
732
|
+
bdbackup history checksum --config config.toml --job mysql-prod
|
|
733
|
+
```
|
|
734
|
+
|
|
735
|
+
It prints `<id>: recorded`, `<id>: skipped: unavailable` for an artifact that is
|
|
736
|
+
missing or was replaced, or `<id>: skipped: unexpected unit` for a physical backup
|
|
737
|
+
outside its dated layout, and then exits 1. A checksum already recorded is never
|
|
738
|
+
changed. The checksum lives in the `checksum` column of the `backup_runs` table.
|
|
739
|
+
|
|
740
|
+
History uses schema version 5. An existing database upgrades on the next write;
|
|
741
|
+
older bdbackup versions refuse a version-5 database.
|
|
742
|
+
|
|
699
743
|
History is written before work starts, and success only after the backup and its
|
|
700
744
|
requested verification finish. If history cannot be written, the command fails;
|
|
701
745
|
an artifact already created is preserved. A forcibly killed process may leave a
|
|
@@ -743,10 +787,200 @@ bdbackup restore --config config.toml --backup-id 12 --dst /restore/job-12 --yes
|
|
|
743
787
|
|
|
744
788
|
Deleted artifacts remain in history as unavailable. File identity, size, and
|
|
745
789
|
modification time detect replaced archives, so older rows for a reused filename
|
|
746
|
-
are not offered as older recovery points.
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
790
|
+
are not offered as older recovery points. Availability uses these file checks.
|
|
791
|
+
Restore checks the recorded checksum of every file it uses for backups that GFS
|
|
792
|
+
manages (see [Ledger and GFS](#ledger-and-gfs)); for other backups it
|
|
793
|
+
validates the actual archive or physical dependency chain. History stores
|
|
794
|
+
references to artifacts and does not preserve an archive that a later backup
|
|
795
|
+
replaces.
|
|
796
|
+
|
|
797
|
+
## Ledger and GFS
|
|
798
|
+
|
|
799
|
+
GFS moves bdbackup's own backups through a chain of storage tiers, called stages,
|
|
800
|
+
using only the history ledger: it never guesses from what lies on disk. A typical
|
|
801
|
+
chain keeps everything for 5 days on a fast local disk, everything for 15 more
|
|
802
|
+
days on cheap NFS storage (point-in-time recovery from incrementals), then one
|
|
803
|
+
backup per week, per month and per year.
|
|
804
|
+
|
|
805
|
+
```toml
|
|
806
|
+
[gfs-main]
|
|
807
|
+
type = "gfs"
|
|
808
|
+
apply = false # dry run unless true
|
|
809
|
+
# schedule = "0 4 * * *"
|
|
810
|
+
|
|
811
|
+
[[gfs-main.stage]]
|
|
812
|
+
paths = ["/BACKUP"] # engines write here
|
|
813
|
+
period = "daily"
|
|
814
|
+
keep = "5d"
|
|
815
|
+
|
|
816
|
+
[[gfs-main.stage]]
|
|
817
|
+
paths = ["/NFS/daily"]
|
|
818
|
+
period = "daily"
|
|
819
|
+
keep = "20d" # 5 days hot + 15 days on NFS
|
|
820
|
+
|
|
821
|
+
[[gfs-main.stage]]
|
|
822
|
+
paths = ["/NFS/weekly"]
|
|
823
|
+
period = "weekly"
|
|
824
|
+
keep = "8w"
|
|
825
|
+
|
|
826
|
+
[[gfs-main.stage]]
|
|
827
|
+
paths = ["/NFS/monthly"]
|
|
828
|
+
period = "monthly"
|
|
829
|
+
keep = "12m"
|
|
830
|
+
|
|
831
|
+
[[gfs-main.stage]]
|
|
832
|
+
paths = ["/NFS/yearly", "/DD/yearly"] # every path receives a copy
|
|
833
|
+
period = "yearly"
|
|
834
|
+
keep = "7y"
|
|
835
|
+
```
|
|
836
|
+
|
|
837
|
+
Run it with `bdbackup run --config config.toml gfs-main`. `--cron` schedules GFS
|
|
838
|
+
jobs with retention at 04:00, after backups.
|
|
839
|
+
|
|
840
|
+
**Stages and ages.** `keep` is an age counted from the backup day: `Nd` days,
|
|
841
|
+
`Nw` weeks, `Nm` calendar months, `Ny` years. A backup belongs to the first stage
|
|
842
|
+
whose `keep` it is still within; past the last stage it is deleted. Each `keep`
|
|
843
|
+
must be longer than the previous one on every calendar (a month counts as 28–31
|
|
844
|
+
days), and periods never go backwards along the chain. The first stage has
|
|
845
|
+
exactly one path and is where backup jobs write.
|
|
846
|
+
|
|
847
|
+
**Periods.** A daily stage keeps every backup. A weekly stage keeps the newest
|
|
848
|
+
backup of each ISO week; a monthly stage, of those, the newest dated in each
|
|
849
|
+
month; a yearly stage, of those, the newest dated in each year. Selection is per
|
|
850
|
+
job, so a tar job and a MySQL job never compete for one slot. A week is decided
|
|
851
|
+
only once it has ended, and a month or year only once the ISO week holding its
|
|
852
|
+
last day has ended, so a choice never changes later; until then the backup is
|
|
853
|
+
reported `held: <bucket> not complete` and stays where it is.
|
|
854
|
+
|
|
855
|
+
With the configuration above on Tuesday 2026-09-29 and one backup per day:
|
|
856
|
+
|
|
857
|
+
| Backup | Result | Why |
|
|
858
|
+
|---|---|---|
|
|
859
|
+
| 2026-09-24 | `/NFS/daily` | within 20d |
|
|
860
|
+
| 2026-09-09 | deleted | its week's newest backup is 09-13 |
|
|
861
|
+
| 2026-09-06 (Sun) | `/NFS/weekly` | newest of ISO week 36 |
|
|
862
|
+
| 2026-08-30 (Sun) | `/NFS/weekly` | newest of week 35; also August's monthly backup |
|
|
863
|
+
| 2026-08-02 (Sun) | deleted | newest of its week, not of August |
|
|
864
|
+
| 2026-07-26 (Sun) | `/NFS/monthly` | July's newest weekly backup |
|
|
865
|
+
| 2025-12-28 (Sun) | `/NFS/monthly` | also 2025's yearly backup |
|
|
866
|
+
| 2024-12-29 (Sun) | `/NFS/yearly` | 2024's yearly backup |
|
|
867
|
+
|
|
868
|
+
**Units and paths.** GFS moves a unit as one piece: an archive or dump file, or
|
|
869
|
+
an xtrabackup dated directory with its full and every incremental (and its
|
|
870
|
+
`Full_Latest` and `.full_success` markers). A unit keeps its path relative to
|
|
871
|
+
the first stage, so `/BACKUP/mysql/prod/2026-09-29` becomes
|
|
872
|
+
`/NFS/daily/mysql/prod/2026-09-29`. The newest unit of each job always stays in
|
|
873
|
+
the first stage, so the next incremental finds its full.
|
|
874
|
+
|
|
875
|
+
**Safety.** Each later stage path must contain an empty file named
|
|
876
|
+
`.bdbackup-destination`; an unmounted mount point is an empty local directory
|
|
877
|
+
without it, and GFS writes nothing there (`--validate` reports it). GFS copies to
|
|
878
|
+
a temporary name, checks every checksum while reading the source, and removes
|
|
879
|
+
the original only after every copy is in place and recorded; a failed copy
|
|
880
|
+
removes its temporary copies and the next run retries. Before a move,
|
|
881
|
+
every copy of the unit is checked, not only the one copied, and
|
|
882
|
+
copies keep the permission bits of every file and directory. If the
|
|
883
|
+
ledger lists a unit in two stages (left by an earlier version or a hand edit),
|
|
884
|
+
the next run removes the earlier copy only after the later copies verify.
|
|
885
|
+
Copies hold no backup lock,
|
|
886
|
+
so a slow NFS copy never blocks a backup; if an xtrabackup root is locked when
|
|
887
|
+
GFS commits, the unit is reported `deferred: locked` and retried next run. GFS
|
|
888
|
+
only touches backups recorded in the ledger. It refuses, and reports:
|
|
889
|
+
|
|
890
|
+
- `refused: checksum mismatch`: the backup changed since it was recorded. To
|
|
891
|
+
accept the change, set the `checksum` column of its `backup_runs` rows to the
|
|
892
|
+
new value with `sqlite3`; the next run acts on it. A backup that changed
|
|
893
|
+
before GFS first saw it is never managed.
|
|
894
|
+
- `refused: unexpected entry …`: a unit holds something that is not one of its
|
|
895
|
+
recorded backups or engine markers, such as a leftover `.tmp` directory, or a
|
|
896
|
+
symlink or special file inside a backup.
|
|
897
|
+
- `refused: stage not configured`: the unit lives under a stage no longer in the
|
|
898
|
+
configuration. Removing a stage never deletes its backups; restore the stage
|
|
899
|
+
or remove them yourself. Changing the first stage's path keeps managing units
|
|
900
|
+
already moved to later stages; units left under the
|
|
901
|
+
old first-stage path are no longer managed.
|
|
902
|
+
- `refused: destination not ready …`: a stage path lacks its marker.
|
|
903
|
+
|
|
904
|
+
Backup jobs writing into the first stage must not delete or overwrite on their
|
|
905
|
+
own: xtrabackup jobs set `retention_days = 0` and file jobs set
|
|
906
|
+
`timestamp = true`. Configuration validation enforces both, rejects stage paths
|
|
907
|
+
that overlap, and keeps the live history database out of stage paths.
|
|
908
|
+
|
|
909
|
+
`apply = false` (the default) prints what would move or be deleted and changes
|
|
910
|
+
nothing. Exit codes: 0 done, 1 a refusal or failure, 2 configuration error, 3
|
|
911
|
+
another run of the same job is in progress, or the only unfinished units were
|
|
912
|
+
deferred.
|
|
913
|
+
|
|
914
|
+
**Unmanaged backups.** A backup that was unavailable when GFS first saw it (for
|
|
915
|
+
example an older run of a file job without `timestamp`, whose archive a later
|
|
916
|
+
run replaced) stays unmanaged on every later run: GFS never moves or deletes it,
|
|
917
|
+
and the report counts it in `unmanaged`.
|
|
918
|
+
|
|
919
|
+
**Report.** Each run lists every unit it acted on, held, deferred or refused,
|
|
920
|
+
then a `Summary:` line with counts and bytes per action. One line per stage
|
|
921
|
+
follows, such as `Stage /NFS/daily: 15 units (3200000000 bytes)`, counting where
|
|
922
|
+
the units are when the run ends (where they would be, in a dry run), and then
|
|
923
|
+
the ledger copies written.
|
|
924
|
+
|
|
925
|
+
**Step log.** Every step is also recorded in the `gfs_steps` table of the history
|
|
926
|
+
database, one row per path, with its source, destination, outcome
|
|
927
|
+
and reason. A failed step keeps the error message.
|
|
928
|
+
|
|
929
|
+
**Run log.** Every applying run records one row in the `gfs_runs` table:
|
|
930
|
+
the GFS job, start and finish time, status, exit code and the Summary counts.
|
|
931
|
+
The status is `running` while the run works, `completed` once it reaches its report
|
|
932
|
+
(whatever the exit code), and `failed` if the run itself crashed. A row left
|
|
933
|
+
`running` shows a run that was cut off; check that run's steps for leftovers
|
|
934
|
+
(Known limits below). Each `gfs_steps` row names its run in `run_id`. A dry run
|
|
935
|
+
records nothing.
|
|
936
|
+
|
|
937
|
+
**Running backups.** While a job has a backup in state `running` in the
|
|
938
|
+
ledger, GFS leaves every backup of that job where it is, whatever its age, and
|
|
939
|
+
reports each one as
|
|
940
|
+
`deferred: backup running (record <id>, started <time>)`.
|
|
941
|
+
Other jobs proceed as usual, and a run whose only unfinished work is these
|
|
942
|
+
deferrals exits 3. A backup killed before it finished (`kill -9`, a power loss)
|
|
943
|
+
leaves its row `running`, and that job stays deferred until you fix the row. After
|
|
944
|
+
checking that no backup of that job is running, mark it failed:
|
|
945
|
+
`sqlite3 <history database> "UPDATE backup_runs SET status = 'failed' WHERE id = <id>"`.
|
|
946
|
+
|
|
947
|
+
**Restoring moved backups.** `bdbackup restore` and `bdbackup history` find a
|
|
948
|
+
backup where GFS put it. `history` shows a copy that was removed or replaced as
|
|
949
|
+
`unavailable`. Before restoring, every backup file used is checked against its
|
|
950
|
+
ledger checksum; with several paths in a stage, the first path that verifies is
|
|
951
|
+
used, and the `Backup:` line names it. An xtrabackup chain is prepared from the
|
|
952
|
+
stage directory holding it, which keeps the layout of the first stage.
|
|
953
|
+
|
|
954
|
+
**Ledger copies.** After every applying run, each path of every stage after the
|
|
955
|
+
first holds `<gfs job>.ledger.sqlite3`, a consistent copy of the whole history
|
|
956
|
+
database, written under a temporary name and renamed into place. A path without
|
|
957
|
+
its marker gets none, and the run exits 1. To restore with only a stage left,
|
|
958
|
+
copy that file somewhere outside the stages, point `[history] database` at the
|
|
959
|
+
copy, and run `bdbackup restore`. Paths in the ledger are absolute, so the
|
|
960
|
+
stages must be mounted at the same paths as when the copy was written.
|
|
961
|
+
|
|
962
|
+
**Known limits.** GFS does not yet keep a journal of a move or delete while it
|
|
963
|
+
runs, so a few failures leave work for the operator. The report and the step log
|
|
964
|
+
name the paths involved, and each leftover is
|
|
965
|
+
removed by hand:
|
|
966
|
+
|
|
967
|
+
- A move was recorded, but removing the old copy failed. The old copy stays on
|
|
968
|
+
disk, no longer in the ledger, and GFS never touches it again. Delete it.
|
|
969
|
+
- A move failed, or the process stopped, after some new copies were renamed into
|
|
970
|
+
place but before the move was recorded. The next run reports
|
|
971
|
+
`refused: final name exists: <path>`. Delete that copy; the next run moves the
|
|
972
|
+
unit again.
|
|
973
|
+
- A delete failed part way. The next run reports `refused: missing location …`
|
|
974
|
+
for a copy already removed. Delete its row with
|
|
975
|
+
`sqlite3 <history database> "DELETE FROM gfs_locations WHERE path = '<path>'"`.
|
|
976
|
+
If that was the unit's last row, also mark the unit deleted, or later runs
|
|
977
|
+
report `refused: stage not configured`:
|
|
978
|
+
`sqlite3 <history database> "UPDATE gfs_units SET deleted_at = datetime('now') WHERE id = <unit_id>"`
|
|
979
|
+
(the `unit_id` of the row you deleted).
|
|
980
|
+
- A restore stops when the xtrabackup copy at the first path of a stage has
|
|
981
|
+
damaged checkpoints or chain metadata; it does not move on to the next path.
|
|
982
|
+
Prepare the copy at another path of that stage with
|
|
983
|
+
`bdbackup xtrabackup prepare -r <directory holding the copy> -d <new dir> <backup>`.
|
|
750
984
|
|
|
751
985
|
## Development
|
|
752
986
|
|
|
@@ -114,10 +114,16 @@ Options:
|
|
|
114
114
|
| `--exclude-pattern` | Glob pattern to exclude (repeatable) |
|
|
115
115
|
| `--exclude-template` | Named exclusion template, e.g. `python-dev` (repeatable, comma-separated allowed) |
|
|
116
116
|
| `--follow-symlinks` | Follow symbolic links when archiving |
|
|
117
|
+
| `--timestamp / --no-timestamp` | Write `<dst>-<UTC YYYY-MM-DD-HHMMSS><ext>` instead of replacing one archive; an existing name is never overwritten (default: off) |
|
|
117
118
|
| `--dry-run` | List what would be archived without writing anything |
|
|
118
119
|
| `--verify / --no-verify` | Verify the archive after creation (default: on) |
|
|
119
120
|
| `--logging` | Log level: `DEBUG`, `INFO`, `WARNING`, `ERROR` |
|
|
120
121
|
|
|
122
|
+
Without `--timestamp`, every run replaces the same archive, so only the newest
|
|
123
|
+
run stays restorable. With it, each run writes a new archive such as
|
|
124
|
+
`daily-2026-09-29-020000.tar.gz`, and a run that would reuse an existing name
|
|
125
|
+
fails instead. Config jobs set `timestamp = true`.
|
|
126
|
+
|
|
121
127
|
Restore a file archive:
|
|
122
128
|
|
|
123
129
|
```bash
|
|
@@ -318,7 +324,7 @@ Options:
|
|
|
318
324
|
| `--encrypt-key-file` | Required 32-byte key file when encrypting; also used by `prepare` |
|
|
319
325
|
| `--parallel` | Number of copy threads (default: 1) |
|
|
320
326
|
| `--throttle` | Limit I/O to this many IOPS |
|
|
321
|
-
| `--retention` | Days of backups to keep (default: 5) |
|
|
327
|
+
| `--retention` | Days of backups to keep (default: 5); `0` disables engine deletion |
|
|
322
328
|
| `--verify / --no-verify` | Verify the backup after creation (default: on) |
|
|
323
329
|
|
|
324
330
|
A process lock prevents two backup runs from corrupting the same backup root.
|
|
@@ -384,7 +390,11 @@ it. Original backups remain encrypted; the recovery directory contains plaintext
|
|
|
384
390
|
For manual `xtrabackup prepare`, supply `--encrypt-key-file` as well.
|
|
385
391
|
See [Percona's encryption documentation](https://docs.percona.com/percona-xtrabackup/8.4/encrypt-backups.html).
|
|
386
392
|
|
|
387
|
-
## Retention
|
|
393
|
+
## Retention of flat files (`type = "retention"`)
|
|
394
|
+
|
|
395
|
+
This section handles flat backup files written by other tools. For bdbackup's
|
|
396
|
+
own backups, use `type = "gfs"` (see [Ledger and GFS](#ledger-and-gfs)), which
|
|
397
|
+
moves backups between storage tiers using the history ledger.
|
|
388
398
|
|
|
389
399
|
The `bdbackup retention` command applies a grandfather-father-son policy to
|
|
390
400
|
a backup tree: keep **every** backup for the last N days, then **one per ISO
|
|
@@ -525,7 +535,9 @@ For example, schedule a weekly full on Sunday and incrementals on the other days
|
|
|
525
535
|
|
|
526
536
|
Pruning after each full deletes whole dated chains older than `retention_days`.
|
|
527
537
|
Set `retention_days` longer than the interval between fulls to preserve the previous
|
|
528
|
-
full's incrementals.
|
|
538
|
+
full's incrementals. `retention_days = 0` disables engine deletion for the job,
|
|
539
|
+
both the automatic pruning after a full and `bdbackup xtrabackup prune`; use it
|
|
540
|
+
when another tool rotates the backups. History now records configured physical backups as
|
|
529
541
|
`xtrabackup-full` / `xtrabackup-incremental` (previously `xtrabackup`); update filters
|
|
530
542
|
that use the old type. Existing history rows are unchanged.
|
|
531
543
|
|
|
@@ -665,6 +677,38 @@ exception class. Retention, restore operations, and file dry runs are not backup
|
|
|
665
677
|
attempts and do not create rows. Direct Python backend calls are not automatically
|
|
666
678
|
recorded; applications can wrap them with `History.run`.
|
|
667
679
|
|
|
680
|
+
Every successful backup also records its unit and a SHA-256 checksum taken right
|
|
681
|
+
after the backup, which costs one extra read of the backup. A file's checksum is
|
|
682
|
+
the SHA-256 of its content. A directory's checksum is the SHA-256 of a manifest
|
|
683
|
+
with one line per regular file, `<sha256> <relative path>`, sorted by path; a
|
|
684
|
+
symlink or special file inside a physical backup fails the backup. The unit is
|
|
685
|
+
what a rotation tool moves as one piece: the archive or dump file itself, or for
|
|
686
|
+
xtrabackup the dated directory that holds the full and all of its incrementals.
|
|
687
|
+
`bdbackup history` shows it as `unit <path>`, or `unit -` for records without one.
|
|
688
|
+
For units that GFS manages, the line continues with `| stage <stage path> |
|
|
689
|
+
locations <path>, …`, or `| deleted <time>` once GFS has removed the unit.
|
|
690
|
+
Reproduce a directory checksum on Linux (use `shasum -a 256` on macOS):
|
|
691
|
+
|
|
692
|
+
```bash
|
|
693
|
+
cd /backup/mysql/production/2026-09-29/Full_<id> && find . -type f -print0 \
|
|
694
|
+
| LC_ALL=C sort -z | xargs -0 sha256sum | sed 's| \./| |' | sha256sum
|
|
695
|
+
```
|
|
696
|
+
|
|
697
|
+
Records taken before this release have no checksum. Record them explicitly:
|
|
698
|
+
|
|
699
|
+
```bash
|
|
700
|
+
bdbackup history checksum --config config.toml
|
|
701
|
+
bdbackup history checksum --config config.toml --job mysql-prod
|
|
702
|
+
```
|
|
703
|
+
|
|
704
|
+
It prints `<id>: recorded`, `<id>: skipped: unavailable` for an artifact that is
|
|
705
|
+
missing or was replaced, or `<id>: skipped: unexpected unit` for a physical backup
|
|
706
|
+
outside its dated layout, and then exits 1. A checksum already recorded is never
|
|
707
|
+
changed. The checksum lives in the `checksum` column of the `backup_runs` table.
|
|
708
|
+
|
|
709
|
+
History uses schema version 5. An existing database upgrades on the next write;
|
|
710
|
+
older bdbackup versions refuse a version-5 database.
|
|
711
|
+
|
|
668
712
|
History is written before work starts, and success only after the backup and its
|
|
669
713
|
requested verification finish. If history cannot be written, the command fails;
|
|
670
714
|
an artifact already created is preserved. A forcibly killed process may leave a
|
|
@@ -712,10 +756,200 @@ bdbackup restore --config config.toml --backup-id 12 --dst /restore/job-12 --yes
|
|
|
712
756
|
|
|
713
757
|
Deleted artifacts remain in history as unavailable. File identity, size, and
|
|
714
758
|
modification time detect replaced archives, so older rows for a reused filename
|
|
715
|
-
are not offered as older recovery points.
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
759
|
+
are not offered as older recovery points. Availability uses these file checks.
|
|
760
|
+
Restore checks the recorded checksum of every file it uses for backups that GFS
|
|
761
|
+
manages (see [Ledger and GFS](#ledger-and-gfs)); for other backups it
|
|
762
|
+
validates the actual archive or physical dependency chain. History stores
|
|
763
|
+
references to artifacts and does not preserve an archive that a later backup
|
|
764
|
+
replaces.
|
|
765
|
+
|
|
766
|
+
## Ledger and GFS
|
|
767
|
+
|
|
768
|
+
GFS moves bdbackup's own backups through a chain of storage tiers, called stages,
|
|
769
|
+
using only the history ledger: it never guesses from what lies on disk. A typical
|
|
770
|
+
chain keeps everything for 5 days on a fast local disk, everything for 15 more
|
|
771
|
+
days on cheap NFS storage (point-in-time recovery from incrementals), then one
|
|
772
|
+
backup per week, per month and per year.
|
|
773
|
+
|
|
774
|
+
```toml
|
|
775
|
+
[gfs-main]
|
|
776
|
+
type = "gfs"
|
|
777
|
+
apply = false # dry run unless true
|
|
778
|
+
# schedule = "0 4 * * *"
|
|
779
|
+
|
|
780
|
+
[[gfs-main.stage]]
|
|
781
|
+
paths = ["/BACKUP"] # engines write here
|
|
782
|
+
period = "daily"
|
|
783
|
+
keep = "5d"
|
|
784
|
+
|
|
785
|
+
[[gfs-main.stage]]
|
|
786
|
+
paths = ["/NFS/daily"]
|
|
787
|
+
period = "daily"
|
|
788
|
+
keep = "20d" # 5 days hot + 15 days on NFS
|
|
789
|
+
|
|
790
|
+
[[gfs-main.stage]]
|
|
791
|
+
paths = ["/NFS/weekly"]
|
|
792
|
+
period = "weekly"
|
|
793
|
+
keep = "8w"
|
|
794
|
+
|
|
795
|
+
[[gfs-main.stage]]
|
|
796
|
+
paths = ["/NFS/monthly"]
|
|
797
|
+
period = "monthly"
|
|
798
|
+
keep = "12m"
|
|
799
|
+
|
|
800
|
+
[[gfs-main.stage]]
|
|
801
|
+
paths = ["/NFS/yearly", "/DD/yearly"] # every path receives a copy
|
|
802
|
+
period = "yearly"
|
|
803
|
+
keep = "7y"
|
|
804
|
+
```
|
|
805
|
+
|
|
806
|
+
Run it with `bdbackup run --config config.toml gfs-main`. `--cron` schedules GFS
|
|
807
|
+
jobs with retention at 04:00, after backups.
|
|
808
|
+
|
|
809
|
+
**Stages and ages.** `keep` is an age counted from the backup day: `Nd` days,
|
|
810
|
+
`Nw` weeks, `Nm` calendar months, `Ny` years. A backup belongs to the first stage
|
|
811
|
+
whose `keep` it is still within; past the last stage it is deleted. Each `keep`
|
|
812
|
+
must be longer than the previous one on every calendar (a month counts as 28–31
|
|
813
|
+
days), and periods never go backwards along the chain. The first stage has
|
|
814
|
+
exactly one path and is where backup jobs write.
|
|
815
|
+
|
|
816
|
+
**Periods.** A daily stage keeps every backup. A weekly stage keeps the newest
|
|
817
|
+
backup of each ISO week; a monthly stage, of those, the newest dated in each
|
|
818
|
+
month; a yearly stage, of those, the newest dated in each year. Selection is per
|
|
819
|
+
job, so a tar job and a MySQL job never compete for one slot. A week is decided
|
|
820
|
+
only once it has ended, and a month or year only once the ISO week holding its
|
|
821
|
+
last day has ended, so a choice never changes later; until then the backup is
|
|
822
|
+
reported `held: <bucket> not complete` and stays where it is.
|
|
823
|
+
|
|
824
|
+
With the configuration above on Tuesday 2026-09-29 and one backup per day:
|
|
825
|
+
|
|
826
|
+
| Backup | Result | Why |
|
|
827
|
+
|---|---|---|
|
|
828
|
+
| 2026-09-24 | `/NFS/daily` | within 20d |
|
|
829
|
+
| 2026-09-09 | deleted | its week's newest backup is 09-13 |
|
|
830
|
+
| 2026-09-06 (Sun) | `/NFS/weekly` | newest of ISO week 36 |
|
|
831
|
+
| 2026-08-30 (Sun) | `/NFS/weekly` | newest of week 35; also August's monthly backup |
|
|
832
|
+
| 2026-08-02 (Sun) | deleted | newest of its week, not of August |
|
|
833
|
+
| 2026-07-26 (Sun) | `/NFS/monthly` | July's newest weekly backup |
|
|
834
|
+
| 2025-12-28 (Sun) | `/NFS/monthly` | also 2025's yearly backup |
|
|
835
|
+
| 2024-12-29 (Sun) | `/NFS/yearly` | 2024's yearly backup |
|
|
836
|
+
|
|
837
|
+
**Units and paths.** GFS moves a unit as one piece: an archive or dump file, or
|
|
838
|
+
an xtrabackup dated directory with its full and every incremental (and its
|
|
839
|
+
`Full_Latest` and `.full_success` markers). A unit keeps its path relative to
|
|
840
|
+
the first stage, so `/BACKUP/mysql/prod/2026-09-29` becomes
|
|
841
|
+
`/NFS/daily/mysql/prod/2026-09-29`. The newest unit of each job always stays in
|
|
842
|
+
the first stage, so the next incremental finds its full.
|
|
843
|
+
|
|
844
|
+
**Safety.** Each later stage path must contain an empty file named
|
|
845
|
+
`.bdbackup-destination`; an unmounted mount point is an empty local directory
|
|
846
|
+
without it, and GFS writes nothing there (`--validate` reports it). GFS copies to
|
|
847
|
+
a temporary name, checks every checksum while reading the source, and removes
|
|
848
|
+
the original only after every copy is in place and recorded; a failed copy
|
|
849
|
+
removes its temporary copies and the next run retries. Before a move,
|
|
850
|
+
every copy of the unit is checked, not only the one copied, and
|
|
851
|
+
copies keep the permission bits of every file and directory. If the
|
|
852
|
+
ledger lists a unit in two stages (left by an earlier version or a hand edit),
|
|
853
|
+
the next run removes the earlier copy only after the later copies verify.
|
|
854
|
+
Copies hold no backup lock,
|
|
855
|
+
so a slow NFS copy never blocks a backup; if an xtrabackup root is locked when
|
|
856
|
+
GFS commits, the unit is reported `deferred: locked` and retried next run. GFS
|
|
857
|
+
only touches backups recorded in the ledger. It refuses, and reports:
|
|
858
|
+
|
|
859
|
+
- `refused: checksum mismatch`: the backup changed since it was recorded. To
|
|
860
|
+
accept the change, set the `checksum` column of its `backup_runs` rows to the
|
|
861
|
+
new value with `sqlite3`; the next run acts on it. A backup that changed
|
|
862
|
+
before GFS first saw it is never managed.
|
|
863
|
+
- `refused: unexpected entry …`: a unit holds something that is not one of its
|
|
864
|
+
recorded backups or engine markers, such as a leftover `.tmp` directory, or a
|
|
865
|
+
symlink or special file inside a backup.
|
|
866
|
+
- `refused: stage not configured`: the unit lives under a stage no longer in the
|
|
867
|
+
configuration. Removing a stage never deletes its backups; restore the stage
|
|
868
|
+
or remove them yourself. Changing the first stage's path keeps managing units
|
|
869
|
+
already moved to later stages; units left under the
|
|
870
|
+
old first-stage path are no longer managed.
|
|
871
|
+
- `refused: destination not ready …`: a stage path lacks its marker.
|
|
872
|
+
|
|
873
|
+
Backup jobs writing into the first stage must not delete or overwrite on their
|
|
874
|
+
own: xtrabackup jobs set `retention_days = 0` and file jobs set
|
|
875
|
+
`timestamp = true`. Configuration validation enforces both, rejects stage paths
|
|
876
|
+
that overlap, and keeps the live history database out of stage paths.
|
|
877
|
+
|
|
878
|
+
`apply = false` (the default) prints what would move or be deleted and changes
|
|
879
|
+
nothing. Exit codes: 0 done, 1 a refusal or failure, 2 configuration error, 3
|
|
880
|
+
another run of the same job is in progress, or the only unfinished units were
|
|
881
|
+
deferred.
|
|
882
|
+
|
|
883
|
+
**Unmanaged backups.** A backup that was unavailable when GFS first saw it (for
|
|
884
|
+
example an older run of a file job without `timestamp`, whose archive a later
|
|
885
|
+
run replaced) stays unmanaged on every later run: GFS never moves or deletes it,
|
|
886
|
+
and the report counts it in `unmanaged`.
|
|
887
|
+
|
|
888
|
+
**Report.** Each run lists every unit it acted on, held, deferred or refused,
|
|
889
|
+
then a `Summary:` line with counts and bytes per action. One line per stage
|
|
890
|
+
follows, such as `Stage /NFS/daily: 15 units (3200000000 bytes)`, counting where
|
|
891
|
+
the units are when the run ends (where they would be, in a dry run), and then
|
|
892
|
+
the ledger copies written.
|
|
893
|
+
|
|
894
|
+
**Step log.** Every step is also recorded in the `gfs_steps` table of the history
|
|
895
|
+
database, one row per path, with its source, destination, outcome
|
|
896
|
+
and reason. A failed step keeps the error message.
|
|
897
|
+
|
|
898
|
+
**Run log.** Every applying run records one row in the `gfs_runs` table:
|
|
899
|
+
the GFS job, start and finish time, status, exit code and the Summary counts.
|
|
900
|
+
The status is `running` while the run works, `completed` once it reaches its report
|
|
901
|
+
(whatever the exit code), and `failed` if the run itself crashed. A row left
|
|
902
|
+
`running` shows a run that was cut off; check that run's steps for leftovers
|
|
903
|
+
(Known limits below). Each `gfs_steps` row names its run in `run_id`. A dry run
|
|
904
|
+
records nothing.
|
|
905
|
+
|
|
906
|
+
**Running backups.** While a job has a backup in state `running` in the
|
|
907
|
+
ledger, GFS leaves every backup of that job where it is, whatever its age, and
|
|
908
|
+
reports each one as
|
|
909
|
+
`deferred: backup running (record <id>, started <time>)`.
|
|
910
|
+
Other jobs proceed as usual, and a run whose only unfinished work is these
|
|
911
|
+
deferrals exits 3. A backup killed before it finished (`kill -9`, a power loss)
|
|
912
|
+
leaves its row `running`, and that job stays deferred until you fix the row. After
|
|
913
|
+
checking that no backup of that job is running, mark it failed:
|
|
914
|
+
`sqlite3 <history database> "UPDATE backup_runs SET status = 'failed' WHERE id = <id>"`.
|
|
915
|
+
|
|
916
|
+
**Restoring moved backups.** `bdbackup restore` and `bdbackup history` find a
|
|
917
|
+
backup where GFS put it. `history` shows a copy that was removed or replaced as
|
|
918
|
+
`unavailable`. Before restoring, every backup file used is checked against its
|
|
919
|
+
ledger checksum; with several paths in a stage, the first path that verifies is
|
|
920
|
+
used, and the `Backup:` line names it. An xtrabackup chain is prepared from the
|
|
921
|
+
stage directory holding it, which keeps the layout of the first stage.
|
|
922
|
+
|
|
923
|
+
**Ledger copies.** After every applying run, each path of every stage after the
|
|
924
|
+
first holds `<gfs job>.ledger.sqlite3`, a consistent copy of the whole history
|
|
925
|
+
database, written under a temporary name and renamed into place. A path without
|
|
926
|
+
its marker gets none, and the run exits 1. To restore with only a stage left,
|
|
927
|
+
copy that file somewhere outside the stages, point `[history] database` at the
|
|
928
|
+
copy, and run `bdbackup restore`. Paths in the ledger are absolute, so the
|
|
929
|
+
stages must be mounted at the same paths as when the copy was written.
|
|
930
|
+
|
|
931
|
+
**Known limits.** GFS does not yet keep a journal of a move or delete while it
|
|
932
|
+
runs, so a few failures leave work for the operator. The report and the step log
|
|
933
|
+
name the paths involved, and each leftover is
|
|
934
|
+
removed by hand:
|
|
935
|
+
|
|
936
|
+
- A move was recorded, but removing the old copy failed. The old copy stays on
|
|
937
|
+
disk, no longer in the ledger, and GFS never touches it again. Delete it.
|
|
938
|
+
- A move failed, or the process stopped, after some new copies were renamed into
|
|
939
|
+
place but before the move was recorded. The next run reports
|
|
940
|
+
`refused: final name exists: <path>`. Delete that copy; the next run moves the
|
|
941
|
+
unit again.
|
|
942
|
+
- A delete failed part way. The next run reports `refused: missing location …`
|
|
943
|
+
for a copy already removed. Delete its row with
|
|
944
|
+
`sqlite3 <history database> "DELETE FROM gfs_locations WHERE path = '<path>'"`.
|
|
945
|
+
If that was the unit's last row, also mark the unit deleted, or later runs
|
|
946
|
+
report `refused: stage not configured`:
|
|
947
|
+
`sqlite3 <history database> "UPDATE gfs_units SET deleted_at = datetime('now') WHERE id = <unit_id>"`
|
|
948
|
+
(the `unit_id` of the row you deleted).
|
|
949
|
+
- A restore stops when the xtrabackup copy at the first path of a stage has
|
|
950
|
+
damaged checkpoints or chain metadata; it does not move on to the next path.
|
|
951
|
+
Prepare the copy at another path of that stage with
|
|
952
|
+
`bdbackup xtrabackup prepare -r <directory holding the copy> -d <new dir> <backup>`.
|
|
719
953
|
|
|
720
954
|
## Development
|
|
721
955
|
|