Snapshot the Chainstate

Intended audience: Solo Stackers, Stacking pool operators, and node operators who need to create reliable chainstate backups.

Regular snapshots of your Stacks chainstate help you recover quickly when things go wrong. This guide shows you how to create and manage chainstate snapshots properly.

Shutdown Procedure

To produce a valid chainstate backup, the node should be stopped gracefully before making a copy. The following steps will correctly shutdown the Stacks node:

1

Check node status before shutdown

# Verify if the node is responsive
curl http://localhost:20443/v2/info
2

Initiate graceful shutdown

  • For Docker: docker stop stacks-node (allows at least 10 seconds for graceful shutdown)

  • For systemd: systemctl stop stacks-node

  • For manual processes:

kill $(ps aux | grep stacks-node | grep -v grep | awk '{print $2}')
3

Verify complete shutdown

# Ensure no stacks-node processes are running
ps aux | grep stacks-node

Overview of Snapshot Methods

There are two primary approaches for creating Stacks chainstate snapshots:

  1. File-based snapshots - compress up the chainstate folder

  2. Volume snapshots - snapshot the entire disk/volume

Each method has its advantages depending on your infrastructure setup and recovery requirements.

File-Based Snapshots

This method involves compressing the chainstate directory and storing it locally, or uploading to a cloud storage service.

  1. Stop the Stacks node gracefully

  2. Create compressed archive

  3. Upload to cloud storage or save it locally

  4. Restart the Stacks node

Volume-Based Snapshots

This method creates block-level snapshots of the entire storage volume containing the chainstate. Different filesystems have different tools:

You can also use cloud provider snapshot tools (AWS EBS, Azure Disk, GCP Persistent Disk).

Steps

  1. Stop the Stacks node gracefully

  2. Create volume snapshot using ZFS or cloud provider tools

  3. Restart the Stacks node

How to Restore

After restoring the chainstate, you can check for corruption by waiting for a few blocks to download and ensuring the node syncs correctly.

From File Snapshots

  1. Stop the Stacks node

  2. Download and extract the snapshot

  3. Replace the chainstate directory

  4. Restart the node

From Volume Snapshots

  1. Stop the Stacks node

  2. Create a new volume from the snapshot

  3. Attach the volume to your instance

  4. Update mount points if necessary

  5. Restart the node

Example Automation Code

Here's a simple script that handles both file and volume snapshots on AWS.

How to Use

  1. Edit the variables at the top of the script for your setup

  2. Make it executable: chmod +x snapshot.sh

  3. Run it: ./snapshot.sh

  4. Schedule it with cron for daily backups:

What You Need

  • AWS CLI set up with the right permissions

  • pzstd installed (comes with the zstd package)

Last updated

Was this helpful?