Skip to content

Restoring Postgres, MongoDB and RabbitMQ to the same moment on Kubernetes: one restore time, not one backup moment

Independently scheduled per-database backups on Kubernetes can restore each store to a different moment, so a full-site restore comes back inconsistent. How to get one restore time across CloudNativePG and MongoDB with point-in-time recovery, why RabbitMQ messages are usually better rebuilt from the databases than restored, if the application can do that, where this still leaves gaps, and the quiet-window fallback for small sites.

By Nishant Gauraw, NG-NeXTPublished Updated 8 min read

A question on r/kubernetes on 26 November describes a common problem. A manufacturer runs several k3s clusters in its factories, one or three nodes each, on VMs. The in-house production app uses CloudNativePG (CNPG) for PostgreSQL, MongoDB, and RabbitMQ as an event bus. Kasten K10 handles backups and works for a single database failure. After a total failure, though, they cannot bring everything back to the same point in time, "because each backup is taken at a different moment, so the system comes back inconsistent." The poster considered VM snapshots but read that they are a bad idea for databases, and asks whether this is the classic "would be nice, but impossible."

The replies split two ways: use point-in-time recovery (PITR) and the outbox pattern, or accept that it is impossible unless the application was designed for it. Both are partly right. Here is how I would think about it.

Change the question: one restore time, not one backup moment#

Independent backups of three different systems do not give you one coordinated, application-consistent snapshot. You do not always need one, but matching restore targets alone do not make the application consistent either; that also depends on how the services hand work to each other (more on that below). If two of the stores support point-in-time recovery, you pick one timestamp T after the failure and restore each of them to T. The backups can be taken at different times; what has to match is the target.

PostgreSQL with CloudNativePG#

CNPG does PITR from a base backup plus the WAL archive. Per the CNPG recovery documentation:

  • Recovery is not done in place. It bootstraps a new cluster from a physical backup.
  • "A valid WAL archive is required to perform PITR."
  • You set a target with bootstrap.recovery.recoveryTarget.targetTime. If you do not name a base backup, the operator "selects the closest backup that was completed before that target."
  • Timestamps without a time zone "are interpreted as UTC," and the docs advise always giving one explicitly.

A minimal example in the shape the docs use (object store via the Barman Cloud plugin):

apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
  name: app-db-restore
spec:
  instances: 1
  storage:
    size: 20Gi
  bootstrap:
    recovery:
      source: origin
      recoveryTarget:
        targetTime: "2026-11-26T09:30:00Z"
  externalClusters:
    - name: origin
      plugin:
        name: barman-cloud.cloudnative-pg.io
        parameters:
          barmanObjectName: app-db-backup
          serverName: app-db

Two details matter here, plus a prerequisite: the example assumes the Barman Cloud plugin is installed and an ObjectStore resource named in barmanObjectName exists. First, the native Barman Cloud integration in CNPG is deprecated since 1.26 in favour of the plugin, and the docs say 1.31 is the last minor release with native support; native support is scheduled to be removed starting from 1.32.0, which the release table expects around March 2027 (the docs say future dates may change). If your clusters still use the old in-tree configuration, plan that move. Second, CNPG sets archive_timeout to 5 minutes by default (WAL archiving), so on a quiet database the last few minutes before a disaster may not be in the archive yet. Your newest usable T is bounded by what has actually been archived.

If Kasten takes the Postgres backup today as a volume snapshot, check whether a WAL archive also exists. A snapshot on its own gives you the moment of the snapshot, not an arbitrary T.

MongoDB with Percona Backup for MongoDB#

MongoDB PITR needs a base backup plus continuous oplog. Percona Backup for MongoDB (PBM) does this when pitr.enabled is set: the agent saves oplog slices, by default each covering a 10-minute span (pitr.oplogSpanMin changes it). A logical PITR restore starts with:

pbm list
pbm restore --time="2026-11-26T09:30:00"

From PBM 2.14.0, pbm restore asks for confirmation; in a script with no terminal, add -y (PBM commands). The command only starts the restore, so follow it with pbm status and the restore progress checks until it finishes. A physical backup restore has extra steps, including restarting mongod and the pbm-agents; follow the physical PITR guide for that case.

Per the PBM PITR restore guide, the time must fall inside one of the PITR ranges pbm list shows, and PBM picks the most recent base backup before it. Stop writes to the database during the restore (for a sharded cluster, also stop the balancer and mongos). Afterwards, make a fresh backup and re-enable PITR, because, per the guide, a restore changes the oplog timeline and the slices made after the restore timestamp and before the last backup become invalid.

So T has to fall inside the recoverable range of both systems: after a usable base backup, before the end of the archived WAL, and within a PITR range that pbm list shows with no gap. The newest T is at most the earlier of "last archived WAL" and "end of the last saved oplog slice." The CNPG docs also warn that PostgreSQL recovery stops at the first transaction after the target time, and "if no such transaction exists after the target time, the recovery process will fail." Check both sides before you choose.

Time zones and clocks#

Write T in UTC on both sides. CNPG takes an explicit zone (...Z). PBM's documented examples for --time use no zone suffix, and Percona's FAQ says "pbm-agents use UTC time zone by design," so give PBM the UTC time: 2026-11-26T09:30:00Z for CNPG should match 2026-11-26T09:30:00 for PBM. Check this on your PBM version with a test restore, and if you think in IST, subtract 5:30 first.

Both tools also work from timestamps recorded by the database servers. If the Postgres and MongoDB nodes disagree on the time, "the same T" is not the same instant in both. Run NTP (chrony or systemd-timesyncd) on every node and monitor the offset. On a factory network with no internet, that means a local time source.

RabbitMQ: rebuild the messages rather than restore them#

The RabbitMQ backup guide is clear about this. It splits node data into definitions (users, vhosts, queues, exchanges, bindings, runtime parameters) and messages. Definitions "can be exported to a JSON file," and that is the recommended way to back them up. For messages, it says that because they "are often short-lived and possibly transient, backing them up from under a running node is highly discouraged and can lead to an inconsistent snapshot of the data." To back up messages, the node must be stopped. Restoring from disk also only works onto a node with exactly the same node name (RabbitMQ 3.8.0 and later).

The backup guide also offers no point-in-time recovery for messages: there is no documented way to roll a classic or quorum queue back to T. So, if the application can reconstruct its pending work, treat the broker as in-flight state:

  1. Back up the definitions regularly (export to JSON) and restore those.
  2. Start with empty queues, but only once you have a proven way to rebuild every piece of outstanding work. Otherwise empty queues silently drop it.
  3. Regenerate the messages that should exist at T from the databases.

The transactional outbox pattern is the usual building block for step 3. The service writes the business change and an "outbox" row describing the event in the same database transaction, and a relay publishes outbox rows to the broker, recording that they were sent (or deleting them, depending on the implementation). The outbox alone does not tell you what was still waiting in a queue when the broker died. A row can be marked sent before T while its message was never consumed, or was consumed after T by a consumer whose own database you just rolled back. So after a restore to T, do not republish only the unsent rows. Keep outbox rows for a while, republish a look-back window that covers every event a consumer may not have finished as of the restored state (a single "last processed event" is not enough if consumers can finish work out of order), and make consumers idempotent, with an inbox or dedup table, so repeats are harmless. The pattern's own description notes that the relay "might publish a message more than once."

If the app does not have an outbox today, this is the part that mostly needs developer time. Operations can add the relay (for example change data capture), but the application still has to write the outbox rows and handle duplicates.

Where "impossible" is right#

The sceptical reply in the thread has a point. If one business action writes to Postgres and then to MongoDB as two separate operations, restoring both to T can catch it half-done: the Postgres write is before T, the MongoDB write a few milliseconds after. PITR across two databases gives you the same clock time, not a shared transaction boundary. Three ways to deal with it:

  • Make one store the source of truth for each workflow, and let the other be derived and rebuildable (by replaying events or re-running a job).
  • Reconcile after restore. A script that checks the known cross-store invariants (for example, every order in Postgres has its production record in MongoDB) and repairs or flags gaps.
  • Pick T at a known quiet boundary if the failure allows it, such as the end of a batch or a moment you can show had no workflow in flight. Low traffic alone is not proof.

The small-site fallback: a short quiet window#

For a one-node k3s cluster in a plant, full PITR on two databases plus an outbox may be more than the team can run. The simpler option is a quiet window: stop every write source (producers, scheduled jobs, anything else that writes), let in-flight work finish and the queues drain, including unacknowledged messages, take the Postgres and MongoDB backups (and the RabbitMQ definitions), then start everything again. If nothing was half-done across stores at that moment (no unfinished workflows, delayed or dead-lettered messages, or pending calls to outside systems), each restore point is then a consistent set. An empty queue alone does not prove that, so check it for your application. The cost is a short write freeze whose length depends on data size and backup method. A plant with a nightly maintenance slot may well have room for it.

The catch is recovery point. If you only do this once a night, a disaster can cost you roughly a day of production data, and more if a nightly backup failed or turns out to be unusable. A sensible path is a nightly quiet-window backup as the simple baseline, with PITR added later for the database that matters most.

Test it end to end#

Whatever you choose, prove it with a full restore of the whole site to a spare VM or cluster: both databases to the same T, definitions imported, outbox replayed, consumers running, and the reconciliation check passing. A restore you have never run is a hope, not a plan.

The know-how here stays free. If you want the backup and restore design for a Kubernetes estate, on your own hardware or at the edge, planned or built with you, NG-NeXT does consulting and turnkey builds. Reach us through the contact page.

— Nishant Gauraw, Founder and CEO, NG-NeXT Tech

Talk to us directly.

We reply within one business day. The site assistant answers when it is available.