Prometheus TSDB snapshot restore: no built-in way to confirm recovered samples match the original
0 reputation · 11 Mar 2021, 17:30 UTC
0 reputation · 11 Mar 2021, 17:30 UTC
We run Prometheus 2.x and back up TSDB snapshots plus archived WAL segments for disaster recovery. The documented snapshot and WAL replay mechanisms let us restore a point-in-time data directory, but I cannot find any supported way to verify that the restored data actually matches what was in the original instance.
The specific uncertainty: after replaying a snapshot (and optionally WAL segments on top), Prometheus starts and serves queries, but there is no native checksum, sample count, or integrity report confirming completeness. My concern is silent gaps — for example WAL segments that were archived mid-write, or out-of-order/duplicated samples introduced during replay — that would only surface later as subtly wrong query results.
Constraints: the restore target is a fresh instance on the same Prometheus version, and remote write replay to a second backend is also in scope, so duplicates there are a separate worry since remote write has no deduplication sequence numbers.
Is comparing identical PromQL query results and per-metric sample counts between a pre-restore baseline and the restored instance the accepted verification approach, or is there a more rigorous documented method? Should promtool tsdb analyze output be compared before and after, and which of its metrics actually indicate corruption versus normal variance? How do others detect silent WAL replay gaps without a known-good reference instance?
35775 reputation · 11 Mar 2021, 18:27 UTC
Prometheus does not provide a native checksum, manifest, or built-in integrity report to confirm that a restored TSDB directory exactly matches the original source. Because the snapshot API creates hard links to block files and the WAL replay is a deterministic but silent process, there is no internal mechanism to detect "silent gaps" caused by partial WAL writes or missing segments during restoration.
The accepted industry approach for verifying a restore is comparative auditing. Since there is no pre-calculated hash for the entire database, you must establish a baseline from the source and compare it against the restored instance.
Before checking for data gaps, verify that the on-disk files are not corrupted. Use promtool to validate the structural integrity of the blocks (index/chunk cross-references and magic bytes).
promtool tsdb check /path/to/restored/data
A non-zero exit code indicates structural corruption, meaning the restore failed at the filesystem or block level.
To detect missing samples or WAL gaps, run identical PromQL queries against both the original (if available) and the restored instance. Focus on aggregate counts and time ranges:
count({__name__=~".+"})count_over_time({__name__=~"your_critical_metric".}[24h])sum() of critical counters over the restoration window.You can use promtool tsdb analyze to get a high-level overview of the database. However, do not expect exact equality in sample counts if compaction has run on one instance but not the other. To get a meaningful comparison:
--storage.tsdb.retention.time=0 and --storage.tsdb.min-block-duration=0) to freeze the state.promtool tsdb analyze on both directories.If you lack a reference instance, the only way to detect non-deterministic WAL replay is to perform the restore twice into two separate fresh instances. If the resulting query outputs diverge, your WAL archive contains corruption or torn writes.
Regarding Remote Write: Because Prometheus remote write lacks per-sample sequence IDs, replaying data to a second backend will inevitably create duplicates. This is a known limitation; deduplication must be handled by the receiving backend (e.g., Thanos Compactor) using last-write-wins semantics.
To refine this recommendation: Are you archiving WAL segments via the Prometheus snapshot API, or via manual filesystem copies of the wal/ directory? Manual copies are prone to "torn writes" (partial records), which promtool tsdb check may not detect but will cause sample gaps.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.