Skip to content

AxonOps — AI-Native Control Plane for Open Source Data Platforms

nodetool snapshot

Creates a snapshot (hard-link backup) of one or more tables.


Terminal window
nodetool [connection_options] snapshot [options] [--] [keyspace ...]

See connection options for connection options.

nodetool snapshot creates a point-in-time copy of SSTable files using filesystem hard links. Snapshots are instantaneous, require minimal additional disk space initially, and serve as the foundation for Cassandra backups.

Cassandra continuously modifies data through compaction, which merges and deletes SSTable files. Without snapshots, there is no way to recover data from a specific point in time. Snapshots freeze a consistent view of the data that can be:

  • Restored locally if data is accidentally deleted or corrupted
  • Copied off-node for disaster recovery
  • Used for cloning to create test environments from production data
CapturedNot Captured
All committed SSTable dataUncommitted data in memtables (unless flushed first)
Secondary index dataCommit log files
Materialized view dataConfiguration files
Schema file (schema.cql) per tableSystem keyspace data (unless explicitly included)

Schema in Snapshots

Each snapshot directory includes a schema.cql file with the table definition at snapshot time. However, this is limited to individual table schema—not full keyspace or cluster schema. To capture complete schema, export separately using DESCRIBE KEYSPACE or snapshot the system schema keyspaces.


ArgumentDescription
keyspaceKeyspace(s) to snapshot. If omitted, snapshots all keyspaces

OptionDescription
-t, --tagName/tag for the snapshot
-cf, --column-familySingle table name to snapshot (requires exactly one keyspace argument)
-sf, --skip-flushSkip flushing memtables before snapshot
-kt, --kt-listComma-separated list of keyspace.table pairs to snapshot multiple tables
--ttlTime-to-live for snapshot (auto-deletion)

-cf vs -kt

  • Use -cf when snapshotting a single table from a single keyspace
  • Use -kt when snapshotting multiple tables (can span keyspaces)
Terminal window
# Single table (use -cf)
nodetool snapshot -t backup -cf users my_keyspace
# Multiple tables (use -kt)
nodetool snapshot -t backup -kt my_keyspace.users,my_keyspace.orders

Terminal window
nodetool snapshot -t full_backup_20240115

Creates snapshot of all user keyspaces.

Terminal window
nodetool snapshot -t my_backup my_keyspace
Terminal window
# -cf requires exactly one keyspace and one table name
nodetool snapshot -t users_backup -cf users my_keyspace
Terminal window
# Use -kt for multiple tables (comma-separated keyspace.table pairs)
nodetool snapshot -t tables_backup -kt my_keyspace.users,my_keyspace.orders
Terminal window
nodetool snapshot -t temp_backup --ttl 24h my_keyspace

Snapshot TTL

Available in Cassandra 4.0+. The snapshot automatically deletes after the specified duration.

Format: <number><unit> where unit is s (seconds), m (minutes), h (hours), d (days).


Snapshots are stored within each table's data directory:

/var/lib/cassandra/data/<keyspace>/<table>-<uuid>/snapshots/<tag>/

Example:

/var/lib/cassandra/data/my_keyspace/users-a1b2c3d4/snapshots/my_backup/
├── nb-1-big-Data.db
├── nb-1-big-Index.db
├── nb-1-big-Filter.db
├── nb-1-big-CompressionInfo.db
├── nb-1-big-Statistics.db
├── nb-1-big-Digest.crc32
├── nb-1-big-TOC.txt
└── manifest.json

Always Snapshot First

Take snapshots before:

  • Schema changes (ALTER TABLE, DROP)
  • Bulk deletes
  • Major compaction
  • Version upgrades
  • Data migrations
Terminal window
# Before dropping a column
nodetool snapshot -t before_schema_change my_keyspace
ALTER TABLE my_keyspace.users DROP old_column;
Terminal window
# Daily backup with date tag
nodetool snapshot -t daily_$(date +%Y%m%d) my_keyspace
Terminal window
nodetool snapshot -t pre_upgrade_4.1

Flush Before Snapshot

By default, nodetool snapshot flushes memtables first. If using -sf (skip flush), recent writes will NOT be included:

Terminal window
# WRONG - May miss recent data
nodetool snapshot -sf -t my_backup
# CORRECT - Ensures all data is captured
nodetool flush my_keyspace
nodetool snapshot -t my_backup my_keyspace

Snapshots Are Not Complete Backups

Snapshots alone are insufficient:

  • Only exist on local node
  • Lost if disk fails
  • Don't include commit logs

Use snapshots as part of a complete backup strategy that copies data off-node.


A hard link is a filesystem feature that allows multiple directory entries to point to the same physical data on disk. Unlike a copy, a hard link does not duplicate the data—it creates another reference to the existing data blocks.

Hard Link Snapshot — Disk LayoutHard Link Snapshot — Disk LayoutDisk StorageFilesystem ReferencesActual Data Blocks(100 MB)[SSTable file contents]data/ks/tbl/nb-1-big-Data.db(original file)data/ks/tbl/snapshots/backup/nb-1-big-Data.db(hard link)Total disk usage: 100 MB (not 200 MB)Both paths reference the same physical data blocksReference 1Reference 2

Key properties of hard links:

PropertyBehavior
Creation speedInstantaneous (just adds a directory entry)
Initial spaceZero additional space (same data blocks)
Data persistenceData remains until ALL references are deleted
IndependenceEach link is equal; there is no "original" vs "copy"

This is why snapshots are fast and space-efficient: creating a snapshot of 500 GB of data takes seconds and uses no additional disk space at the moment of creation.

The space efficiency of hard links has a time dimension. When compaction runs, Cassandra deletes the original SSTable files—but the snapshot's hard links keep the data alive:

TimeEventDisk StateSpace Impact
T=0Snapshot createdBoth original and snapshot reference same blocks+0 MB
T+1Compaction merges SSTablesOriginal files deleted, snapshot links remain+0 MB
T+2Data blocks now only referenced by snapshotSnapshot "owns" the data exclusivelyFull size now attributed to snapshot

Example timeline:

Day 1: Take snapshot of 100 GB table
- Snapshot size shown: ~0 (hard links to active SSTables)
Day 3: Compaction runs, creates new SSTables, deletes old ones
- Snapshot size shown: 100 GB (now holds exclusive references)
- Active table size: 95 GB (new compacted SSTables)
- Total disk usage: 195 GB

Snapshot Space Growth

Old snapshots accumulate disk space as compaction removes the original SSTables they reference. A week-old snapshot may consume as much space as the original data. Monitor with nodetool listsnapshots and clean up regularly.


Terminal window
nodetool listsnapshots

Output:

Snapshot name Keyspace name Column family name True size Size on disk
my_backup my_keyspace users 1.5 GB 1.5 GB
my_backup my_keyspace orders 2.3 GB 2.3 GB
old_backup my_keyspace users 1.2 GB 1.2 GB
Terminal window
nodetool tablestats my_keyspace.users | grep "Space used by snapshots"
Terminal window
du -sh /var/lib/cassandra/data/*/*/snapshots/*

Terminal window
nodetool flush my_keyspace
Terminal window
nodetool snapshot -t backup_$(date +%Y%m%d_%H%M%S) my_keyspace
Terminal window
# Find snapshot files
find /var/lib/cassandra/data/my_keyspace -path "*/snapshots/backup_*" -type f
# Copy to backup location
rsync -av /var/lib/cassandra/data/my_keyspace/*/snapshots/backup_*/ /backup/location/
Terminal window
nodetool clearsnapshot -t backup_20240115_120000 my_keyspace

Snapshots include schema.cql file containing the table definition:

Terminal window
cat /var/lib/cassandra/data/my_keyspace/users-*/snapshots/my_backup/schema.cql

ERROR: Snapshot my_backup already exists

Solutions:

  • Use a different tag name
  • Clear existing snapshot: nodetool clearsnapshot -t my_backup

If snapshot is slow, it's likely waiting for flush:

Terminal window
# Check flush activity
nodetool tpstats | grep -i flush
# Use skip-flush if memtables already flushed
nodetool flush my_keyspace
nodetool snapshot -sf -t my_backup my_keyspace

Snapshots may prevent space reclamation after compaction:

Terminal window
# Check snapshot sizes
nodetool listsnapshots
# Clear old snapshots
nodetool clearsnapshot -t old_backup

Snapshot Guidelines

  1. Use meaningful tags - Include date and purpose
  2. Flush first - Unless using skip-flush intentionally
  3. Copy off-node - Snapshots don't protect against disk failure
  4. Clean up regularly - Remove old snapshots to reclaim space
  5. Document retention - Define how long to keep snapshots
  6. Automate - Script snapshot creation and cleanup
Terminal window
# Include date, time, and purpose
nodetool snapshot -t pre_upgrade_20240115_1430
nodetool snapshot -t daily_backup_20240115
nodetool snapshot -t before_schema_change_users_20240115

Snapshots can be restored in two ways:

Copy snapshot files back to the table's data directory and refresh:

Terminal window
# 1. Stop writes to the table (optional but recommended)
# 2. Copy snapshot files to table directory
cp /var/lib/cassandra/data/my_keyspace/users-*/snapshots/my_backup/*.db \
/var/lib/cassandra/data/my_keyspace/users-*/
# 3. Refresh to load the restored files
nodetool refresh my_keyspace users

Use sstableloader to stream snapshot data to any cluster:

Terminal window
sstableloader -d node1,node2,node3 \
/backup/my_keyspace/users-*/snapshots/my_backup/

For complete restore procedures, see Backup and Restore.


CommandRelationship
clearsnapshotRemove snapshots
listsnapshotsList existing snapshots
flushFlush memtables before snapshot
tablestatsCheck snapshot space usage
refreshLoad restored SSTable files