Snapshot the Chainstate
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.
Critical: Always shut down your Stacks node properly before creating a snapshot. Creating snapshots while the node is running will result in corrupted chainstate data.
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:
Overview of Snapshot Methods
There are two primary approaches for creating Stacks chainstate snapshots:
File-based snapshots - compress up the chainstate folder
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.
Steps (see Example Automation Code section below)
Stop the Stacks node gracefully
Create compressed archive
Upload to cloud storage or save it locally
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:
ZFS: Use
zfs snapshot- OpenZFS documentationXFS: Use
xfsdump- XFS documentationext4: Use LVM snapshots - LVM guide
You can also use cloud provider snapshot tools (AWS EBS, Azure Disk, GCP Persistent Disk).
Steps
Stop the Stacks node gracefully
Create volume snapshot using ZFS or cloud provider tools
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
Stop the Stacks node
Download and extract the snapshot
Replace the chainstate directory
Restart the node
From Volume Snapshots
Stop the Stacks node
Create a new volume from the snapshot
Attach the volume to your instance
Update mount points if necessary
Restart the node
Example Automation Code
Here's a simple script that handles both file and volume snapshots on AWS.
How to Use
Edit the variables at the top of the script for your setup
Make it executable:
chmod +x snapshot.shRun it:
./snapshot.shSchedule it with cron for daily backups:
What You Need
AWS CLI set up with the right permissions
pzstdinstalled (comes with the zstd package)
Last updated
Was this helpful?
