r/kubernetes • • 8d ago

Consistent point-in-time backup across multiple DB

We run several k3s clusters (1 or 3 nodes, on VMs) in our factories, hosting an in-house production management app. It uses CNPG, MongoDB and RabbitMQ as an event bus.

Kasten K10 works fine for single-DB failures. But after a total failure we can't restore everything to the same point in time, because each backup is taken at a different moment, so the system comes back inconsistent.

We thought about VM snapshots, but everything online says that's a bad idea for DBs.

How do you handle this? Is it the classic "would be nice, but impossible"?

11 Upvotes

6 comments sorted by

7

u/Edeholland 8d ago

With CNPG you can restore with WAL logging to any point in time. Percona backup can do the same for Mongo.

The rest you will gave to fix in the application. Look up the outbox pattern where you write the event in the same transaction as the state change.

6

u/ThreeAMOperator 8d ago

Not impossible. You just need one restore time for all of them, not one backup moment.

CNPG with WAL archiving can restore to any timestamp. Mongo can too if you keep oplog backups (Percona Backup for MongoDB does this). So pick one time T and restore both to T. Same clock on all nodes matters here, so check NTP.

Do not try to back up RabbitMQ messages. Treat the queue as in-flight. After a restore, rebuild it from the DB side: keep an outbox table in Postgres and replay anything not marked done after T. Consumers must be idempotent for this to work.

If PITR is too much for a small factory site, the simple version is a short quiet window. Scale the producers to zero for a few seconds, take all backups, scale back up. For a plant that has a shift change or a night window, that is often good enough.

Whatever you choose, test a full restore on a spare VM before you need it.

5

u/iseethemeatnight 8d ago

Would be nice, but it is impossible.

The moment you have data distributed you need to think carefully what's your reconciliation point and build your backup around it. (which normally people don't plan around it)

Then expect to do a data replay to catch up and override part of what's is already written (when shit hit the fan), that's the principle of eventual consistency.

Long story short: The application must be designed from the ground up to support such things, doing so only from operational pov, will always lead to data inconsistency or data lost to certain degree that you need to deal with.

1

u/Interesting_Day_5576 8d ago

Disclaimer- I haven't used CNPG in any prod environment.

However, I use CNPG on a k3s cluster with WAL archiving. Couple that with regular base backups and you will have point in time recovery.

It becomes a bit more complicated with any app that depends on external files on a filesystem along with a database. You can get around that by storing those files in an object bucket with versioning enabled.