HashiCorp Certified: Consul Associate Certification

Back up and Restore

Demo Consul Snapshots

In this guide, you’ll learn how to back up and restore your Consul service state using snapshot commands. We’ll cover:

  • Creating a snapshot file
  • Inspecting snapshot metadata
  • Restoring a cluster from a snapshot

These steps are critical for disaster recovery and cluster portability.


Prerequisites

  • A running Consul server (open source) cluster
  • Consul CLI installed and in your $PATH
  • Permissions to read/write snapshot files

Note

Ensure you have sufficient disk space in your working directory before creating large snapshots.


1. Taking a Snapshot

  1. SSH into one of your Consul server nodes.
  2. Change to a writable directory (e.g., /tmp):
    cd /tmp
    
  3. Run the save subcommand to generate a snapshot file:
    consul snapshot save consul.snap
    
  4. Confirm the operation:
    ==> Consul snapshot saved: consul.snap
    
  5. Verify the file exists:
    ls -lh
    # -rw-r--r-- 1 consul consul  13K Jul  5 12:34 consul.snap
    

2. Inspecting a Snapshot

To view metadata about an existing snapshot file, use the inspect subcommand:

consul snapshot inspect consul.snap

Sample output:

ID:            17-3678-1613078754824
Size:          13367
Index:         3678
Term:          17
Version:       1

Type                   Count     Size
----                   -----     ----
Register               14        9KB
License                1         1.2KB
KVS                    7         837B
...
Total                  —         13.1KB

Note

  • The Version field refers to the snapshot format, not the Consul binary version.
  • Index and Term reflect the Raft state at snapshot creation.

3. Restoring a Snapshot

When recovering a failed cluster or migrating state, restore from your snapshot:

consul snapshot restore consul.snap

After the restore completes:

  1. Restart all Consul agents or services to load the restored data.
  2. Check cluster status:
    consul operator raft list-peers
    consul members
    

Warning

Do not restore a snapshot into an active cluster without first stopping agents—this can lead to data corruption.


Snapshot Commands Reference

CommandDescriptionExample Usage
consul snapshot saveCreate a new snapshot fileconsul snapshot save backup.snap
consul snapshot inspectShow metadata for a snapshotconsul snapshot inspect backup.snap
consul snapshot restoreRestore state from a snapshot fileconsul snapshot restore backup.snap


By following these steps, you can efficiently manage Consul snapshots, ensuring reliable backups and quick recovery for your service cluster.

Watch Video

Watch video content

Previous
Introduction to Consul Snapshots