Sub topic 4
Verifying a snapshot with etcdutl
A snapshot file that was never read back is only a guess. This chapter shows how to check a snapshot with etcdutl before you rely on it. It assumes you can already take a snapshot with etcdctl and have shell access to the control plane node.
Why verify
etcdctl snapshot save can exit successfully and still leave you with a bad file. Common causes are a full disk, a truncated copy to remote storage, or a corrupted transfer. You only find out at restore time, which is the worst moment to learn it. A quick status check catches most of these problems right after the backup.
etcdctl and etcdutl
Recent etcd releases split the tools by purpose:
| Tool | Works with | Needs a running etcd |
|---|---|---|
| `etcdctl` | A live etcd server over the network | Yes |
| `etcdutl` | Files on disk, such as snapshots and data directories | No |
Verification reads a file, so it uses etcdutl. It needs no certificates and no endpoint. You can run it on a laptop or a recovery host, not only on the control plane node.
Check the snapshot
Run snapshot status against the file:
etcdutl snapshot status /var/backups/etcd-snapshot.db --write-out=tableThe command prints a table like this one. Your values will differ.
+----------+----------+------------+------------+
| HASH | REVISION | TOTAL KEYS | TOTAL SIZE |
+----------+----------+------------+------------+
| 3f1a9c2e | 184213 | 1342 | 6.1 MB |
+----------+----------+------------+------------+Each column tells you something:
- HASH is a checksum of the snapshot contents. The command computes it while reading the file, so a damaged file fails here or shows an error.
- REVISION is the etcd revision at the time of the snapshot. A higher number means a newer snapshot, which helps you compare two files.
- TOTAL KEYS is the number of keys stored. A cluster with real workloads has well over a thousand. A value near zero means the snapshot is nearly empty.
- TOTAL SIZE is the size of the stored data. Compare it with earlier snapshots. A sudden large drop deserves an explanation.
A simple verification routine
Run the check immediately after saving, and fail loudly if it does not pass. This script is complete and can be adapted for a scheduled job:
#!/usr/bin/env bash
set -euo pipefail
SNAP=/var/backups/etcd-snapshot.db
etcdutl snapshot status "$SNAP" --write-out=table
sha256sum "$SNAP" > "$SNAP.sha256"
echo "Snapshot verified: $SNAP"set -e stops the script if etcdutl reports an error, so a bad file never reaches the "verified" message. The sha256sum line records a checksum of the whole file. Later, sha256sum -c against that file tells you whether the copy in your off-node storage matches the original.
What verification does not prove
A passing status check shows that the file is a readable etcd snapshot. It does not prove that a restore will produce a healthy cluster. Only an actual restore proves that, and later chapters cover it.
Common errors
- File not found or permission denied. The snapshot was written by root. Run
etcdutlwithsudoor fix the file mode. - Error reading the file. The file is truncated or not a snapshot. Take a new snapshot and check free disk space.
- Command not found. Install
etcdutlfrom the etcd release archive that matches your etcd version.
Exercise
A teammate says a snapshot is good because etcdctl snapshot save finished without errors. Which command would you run to check the file, which values would you look at, and what does a passing result still not prove?
Show answer
Run etcdutl snapshot status <file> --write-out=table. Check that it reads the file without error, that TOTAL KEYS and TOTAL SIZE are plausible compared with earlier snapshots, and that REVISION is newer than the previous snapshot. A pass does not prove that a restore will give a working cluster. Only a test restore proves that.