mirror of
https://github.com/cozystack/cozystack.git
synced 2026-11-21 12:13:55 +09:00
## What this PR does A RestoreJob that names a MariaDB `Backup` restored the newest dump of the application, not the dump of that `Backup`. The driver created the operator `Restore` with only `backupRef`, and mariadb-operator then restores the dump nearest to the moment the restore starts, from the prefix every run of the app shares. Restoring an older `Backup` brought back the latest data, and when its own dump was already gone it silently restored another one. The `Backup` now records the dump its operator `Backup` wrote, the file name in `k8s.mariadb.com/dump-file` and the timestamp from that name in `k8s.mariadb.com/dump-time`. They come from the ownership-proven match the size probe already makes, and nothing is recorded when ownership is not proven. A restore first checks with a bounded S3 listing of the operator `Backup`'s own storage that the dump still exists, then sets `targetRecoveryTime` on the operator `Restore` to the dump's own timestamp, which mariadb-operator matches exactly. If the dump is gone the RestoreJob fails and names it. If the check cannot be made it waits with `Ready=False/DumpCheckPending` until the restore deadline and then fails with the cause. `Backup`s taken before this stay restorable. The restore makes the same ownership-proven match against their operator `Backup` and pins the dump when it is provable, otherwise it restores the newest dump as before and a `BestEffortDump` warning event on the RestoreJob says so. One case is not covered: the `Backup`'s own dump is gone, a neighbour's dump from within the minute of slack is still there and its operator `Backup` was deleted, so that dump is taken as the match. Nothing in the platform deletes operator `Backup`s, it needs someone to delete one by hand. A `Backup` made of an operator `Backup` whose Job failed (`Complete` with reason `JobFailed`) has no dump, so its RestoreJob now fails instead of restoring another run's dump. Stacked on https://github.com/cozystack/cozystack/pull/5223 and targets its branch until that merges, only the last three commits belong here. Checked on a test cluster with mariadb-operator 25.10.2. An operator `Restore` of an older `Backup` with `targetRecoveryTime` set to its dump timestamp restored exactly that dump (`obtained target backup` names it and a row inserted after it is absent from the target), the same `Restore` without the target restored the newest one. Against the real bucket and operator `Backup`s the recording probe attributed to each `Backup` the dump its backup pod logged, the existence check passed for those dumps and refused a pruned one, legacy `Backup`s with a provable dump got pinned while back-to-back runs fell back with the warning, and the two failed runs on that cluster were refused. The controller itself was not run on the cluster, only its code driven by a test against the real bucket. Fixes https://github.com/cozystack/cozystack/issues/5196 ### Screenshots Not a UI change. ### Downstream repositories The diff is confined to the backup controller's Go code. It changes no CRD or API type (`driverMetadata` is an opaque map), no chart, values, package layout or `hack/` script, so no entry of the trigger map applies. - [x] No downstream repository is affected by this change - [ ] [cozystack/website](https://github.com/cozystack/website) - follow-up: - [ ] [cozystack/terraform-provider-cozystack](https://github.com/cozystack/terraform-provider-cozystack) - follow-up: - [ ] [cozystack/ansible-cozystack](https://github.com/cozystack/ansible-cozystack) - follow-up: - [ ] [cozystack/ccp](https://github.com/cozystack/ccp) - follow-up: - [ ] [cozystack/talm](https://github.com/cozystack/talm) - follow-up: - [ ] [cozystack/cozyhr](https://github.com/cozystack/cozyhr) - follow-up: - [ ] [cozystack/cozy-proxy](https://github.com/cozystack/cozy-proxy) - follow-up: - [ ] [cozystack/cozystack-telemetry-server](https://github.com/cozystack/cozystack-telemetry-server) - follow-up: - [ ] [cozystack/external-apps-example](https://github.com/cozystack/external-apps-example) - follow-up: - [ ] [cozystack/examples](https://github.com/cozystack/examples) - follow-up: - [ ] [cozystack/community](https://github.com/cozystack/community) - follow-up: ### Release note ```release-note fix(mariadb): a RestoreJob now restores the dump of the Backup it names instead of the newest dump of the application. It fails with a clear message when that dump no longer exists in storage, or when the Backup was made of a failed backup run. Backups taken before this release are restored by the one dump that can be matched to them, or else, as before, by the newest dump, with a BestEffortDump warning event on the RestoreJob. ``` <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **New Features** * MariaDB backups now record the selected dump’s filename and timestamp, allowing restores to target the corresponding recovery time. * For older backups without dump metadata, restores use a uniquely matched dump when possible or fall back to the latest dump with a warning. * Restore processing verifies recorded dumps, retries temporary storage checks, and reports failures for invalid or missing recorded dumps. * **Bug Fixes** * Deleting a MariaDB backup now removes its associated dump and operator backup when ownership is verified and no restore is active. Cleanup avoids deleting artifacts when it cannot safely identify them. <!-- end of auto-generated comment: release notes by coderabbit.ai -->