mirror of
https://github.com/cozystack/cozystack.git
synced 2026-11-21 20:23:39 +09:00
The spotahome RedisFailover operator ships no backup CRD, so add a dedicated strategy.backups.cozystack.io/Redis driver that runs a one-shot Job: it dumps an RDB snapshot from the current master (discovered via the operator's sentinel Service) to the system bucket over S3, and on restore replays it (RDB -> RESP via redis-cli --pipe) into the target's master. Structurally a specialisation of the Job/Altinity script-Job pattern with a Redis applicationRef gate and an app-readiness precondition. Backup parameters round-trip through the Backup's DriverMetadata (no underlyingResources snapshot); restore drives from .Backup.ApplicationRef so a to-copy restore reads the source's object-storage prefix while writing into a differently-named target. Both in-place and to-copy are supported; PITR is not (RDB is a discrete snapshot). - api: Redis/RedisList strategy type + generated CRD and deepcopy - driver: reconcileRedis / reconcileRedisRestore + pure helpers, wired into both dispatch switches, supportedBackupStrategyKinds and the no-op restore cleanup case - default: gated cozy-default-redis strategy (system-bucket coords via cozy-backups-creds env secretKeyRef, https:// scheme + optional CA) and the Redis route in the cozy-default BackupClass - image: images/redis-backup bundling redis-cli + curl + an RDB->RESP converter, wired via backupStrategyController.redisBackupClientImage - tests: driver unit tests (gate, precondition, render, param round-trip, both reconcile paths) and the helm rendering-gate coverage - example: examples/backups/redis honest marker round-trip for both restore flows Signed-off-by: Andrey Kolkov <androndo@gmail.com> Assisted-By: LLM
2.7 KiB
2.7 KiB
Redis backup / restore demo
Proves an honest data round-trip for a Cozystack-managed Redis (spotahome RedisFailover) through the platform system bucket: a sentinel marker key is written, backed up, and asserted to return byte-for-byte after both restore flows.
The spotahome operator ships no backup CRD, so the strategy.backups.cozystack.io/Redis driver runs a one-shot Job that dumps an RDB snapshot to S3 and replays it on restore (RDB → RESP via redis-cli --pipe). This is the cozy-default-redis strategy the cozy-default BackupClass binds Redis to.
Prerequisites
- A Cozystack cluster with the
backupstrategy-controllerrunning and its system bucket provisioned, socozy-default(and thecozy-default-redisstrategy) are present and the controller can projectcozy-backups-credsinto the app namespace. kubectlpointed at the cluster; the tenant namespace defaults totenant-test(override withNAMESPACE).
Run
./run-all.sh # steps 01-04: provision, back up, restore in-place, restore to-copy
SKIP_RESTORE=1 ./run-all.sh # stop after a successful backup
./cleanup.sh # remove everything the demo created
Or step through them:
| Step | Script | What it does |
|---|---|---|
| 01 | 01-create-redis.sh |
Provision Redis, seed the marker on the master |
| 02 | 02-create-backupjob.sh |
BackupJob (backupClassName: cozy-default) → RDB dump to S3 |
| 03 | 03-restore-in-place.sh |
Corrupt the marker, RestoreJob back into the source, assert it returns |
| 04 | 04-restore-to-copy.sh |
RestoreJob with targetApplicationRef into a fresh copy, assert the marker landed |
Notes
- Master discovery goes through the operator's sentinel Service
rfs-redis-<name>(master namemymaster), so writes and the dump/replay always target the current master even after a failover. - Faithful restore. The restore loads the RDB into a throwaway local redis and replays what a real engine emits, so all logical databases (
SELECTper db), stream last-ids and consumer groups survive — a merge onto db0 does not happen. - Endpoint TLS. The projected
endpointincozy-backups-credsis always scheme-stripped, so the strategy prependshttps://and the transport is always TLS (there is nohttp://path). It verifies against the image's system CA store by default — the platform bucket's ACME cert needs nothing more — honours a private CA frombackupStorage.endpointCASecretNamewhen set, and skips verification only whenbackupStorage.insecureSkipTLSVerify: trueis set explicitly. - No PITR. RDB is a discrete snapshot; the engine ships no continuous log to replay to an arbitrary time, so
spec.options.recoveryTimeis not supported (the etcd-like case).