An etcd Snapshot Rolls the Whole Cluster Back, So Restore Only When Re-Applying Can't Fix It

Kubernetes

etcd is the database behind the Kubernetes API: every object you kubectl apply (Deployments, Services, Secrets, ConfigMaps, Nodes, RBAC, CRDs and their objects) is a key under /registry/ in etcd. The API server is the only component that talks to it. An etcd snapshot is a copy of that whole database at one moment, so restoring it doesn't undo one mistake: it puts the entire cluster back to that moment.

What a Snapshot Is

  • One file, snapshot.db: etcd's own database format (bbolt), holding every key and value at one revision. etcd numbers every write with a cluster-wide revision, so a snapshot is "the state at revision N".
  • Taken from the running member with etcdctl snapshot save, over the client port with a client certificate. etcd streams a consistent copy while it keeps serving, so taking a snapshot needs no downtime.
  • Self-checking: etcd appends a hash to the file. etcdutl snapshot status reports its hash, revision, key count and size, and etcdutl snapshot restore refuses a file whose hash doesn't match.

What it holds and doesn't:

In the snapshot Not in the snapshot
Every API object, Secrets included (in clear unless encryption at rest is configured, which kubeadm doesn't do by default) Data inside volumes: files on NFS shares, local PVs, databases apps run
PersistentVolume and PVC definitions Container images, logs
Node objects, Leases, Events The cluster's keys in /etc/kubernetes/pki (see An etcd Snapshot Alone Can't Rebuild a kubeadm Control Plane, So Back Up the PKI with It)

Where Mine Are

Never as a loose file: each run packs snapshot.db into a bundle with the PKI and the static pod manifests (see A Backup Bundle Packs Everything One Restore Needs into a Single File). A systemd timer takes one every 6 hours, and each bundle is kept in three places, following the 3-2-1 rule: on the control plane node itself for quick restores (two days of history), on the NAS so that a dead node disk loses nothing (two weeks), and on a separate machine in case the NAS fails.

How a Restore Works

You don't open the file. etcdutl turns it back into an etcd data directory, and etcd starts from it:

  1. Unpack the bundle somewhere private (/root/restore) and read the member name and peer URLs from its etcd.yaml.
  2. Stop the API server and etcd: move their manifests out of /etc/kubernetes/manifests, and the kubelet stops the static pods.
  3. Move the current /var/lib/etcd aside. Never delete it: it's the fallback if the restore goes wrong.
  4. etcdutl snapshot restore snapshot.db --data-dir /var/lib/etcd --name … --initial-cluster … --initial-advertise-peer-urls … --bump-revision 1000000000 --mark-compacted. This writes a new data directory and starts a new one-member cluster history from the snapshot.
  5. Put the manifests back, check kubectl get nodes and kubectl get pods -A, then restart what caches cluster state (Cilium, CoreDNS, operators).

Why --bump-revision and --mark-compacted: every controller and kubectl get -w keeps a watch that remembers the last revision it saw. After a restore, the cluster's revision would go backwards, and those clients could think they're already up to date and keep acting on objects that no longer exist. Bumping the revision far ahead, and marking older revisions as compacted, makes their next watch fail with "compacted", which forces them to list everything again from the restored state.

On a rebuilt machine the PKI must go back into /etc/kubernetes/pki before kubeadm init, so the cluster keeps its CA (see A Certificate Authority Is the Key Everyone Trusts, So a New One Invalidates Every Certificate It Signed).

When to Restore, and When Not To

A restore costs everything written since the snapshot, cluster-wide. So the question is always: can I fix this by re-applying instead?

Situation Restore? Instead
etcd won't start: corrupt data after a power cut or a full disk Yes -
The control plane's disk died, or the node was reinstalled Yes, PKI first -
Mass deletion: a CRD deleted (which deletes every object of its kind), namespaces wiped, a script run against the wrong cluster Yes, if Git can't rebuild it Pick the newest snapshot older than the mistake
An upgrade left the data unreadable Yes Take a snapshot by hand right before every upgrade
One app broken or deleted No Re-apply its manifests or Helm release, or let GitOps restore it (see GitOps Agents Pull the Desired State from Git and Revert Changes Made Outside It)
Files lost inside a volume No, they aren't in it Snapshots of the storage itself (ZFS on TrueNAS)
A node NotReady, pods crash-looping No Fix the node; etcd is fine

A middle way for one lost object: restore the snapshot into a throwaway etcd on another port, as the restore drill does, read the object back with etcdctl get, and re-create it in the live cluster. Values are stored in Kubernetes' protobuf encoding, so reading them needs a decoder such as auger. The live cluster never rolls back.

RPO and RTO

  • RPO (recovery point objective): how much data you can lose. Here, the snapshot interval: at most about 6 h 15 min of changes (6 h plus the timer's random delay).
  • RTO (recovery time objective): how long recovery takes. A restore on the same node takes minutes; a rebuilt control plane node takes the OS install and playbooks first.

GitOps shrinks how much a restore must carry: with every manifest in Git, re-applying rebuilds most objects, and the snapshot is left for what Git doesn't hold (Secrets created by hand, objects controllers generate, the cluster's own identity).

References

Review cards

Flashcard What does restoring an etcd snapshot undo, besides the mistake you're fixing?

Every change made anywhere in the cluster since the snapshot: new or edited objects, Secrets, Leases. It rolls the whole cluster back to that moment.

Quiz A user deleted one Deployment by mistake. What's the best fix?
  • Restore the latest etcd snapshot
  • Re-apply its manifests or Helm release
  • Restart the API server
  • Restore the snapshot onto a second control plane

A restore would roll back the whole cluster for one object. Re-applying rebuilds just that Deployment.

Flashcard Why does an etcd restore use `--bump-revision` and `--mark-compacted`?

Watchers remember the last revision they saw, which can be newer than the snapshot. Moving revisions forward and marking older ones compacted makes them re-list from the restored state instead of trusting stale caches.

Flashcard Which data does an etcd snapshot never bring back?

Anything stored inside volumes, such as files on NFS shares or an app's database. It holds only API objects, including PV and PVC definitions.

Flashcard What sets the recovery point objective of a cluster backed up only by etcd snapshots?

The snapshot interval: everything written since the last snapshot is lost in a restore. Every 6 hours means up to about 6 hours of changes.