Skip to content

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

nodetool clearsnapshot

Removes one or more snapshots from the node to reclaim disk space.


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

See connection options for connection options.

nodetool clearsnapshot deletes snapshot files from the local node. Since snapshots are hard links to SSTable files, they consume disk space when the original SSTables are compacted away. Regular cleanup of old snapshots is essential for disk space management.


ArgumentDescription
keyspaceKeyspace(s) to clear snapshots from. If omitted, clears from all keyspaces

OptionDescription
-t, --tagSnapshot tag to clear. Required unless using --all
--allClear all snapshots

Terminal window
nodetool clearsnapshot -t my_backup

Removes the snapshot tagged my_backup from all keyspaces.

Terminal window
nodetool clearsnapshot -t my_backup my_keyspace
Terminal window
nodetool clearsnapshot --all

Use with Caution

--all removes every snapshot on the node. Verify no critical backups exist before running.

Terminal window
nodetool clearsnapshot --all my_keyspace

Once backup files have been copied off-node:

Terminal window
# After copying snapshot files to backup storage
nodetool clearsnapshot -t backup_20240115

When disk usage is high due to old snapshots:

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

Remove snapshots created during testing:

Terminal window
nodetool clearsnapshot -t test_snapshot

Scheduled cleanup of aged snapshots:

Terminal window
# Find snapshots older than 7 days and clear them
# (Requires scripting based on listsnapshots output)
nodetool clearsnapshot -t weekly_backup_$(date -d "7 days ago" +%Y%m%d)

Verify Before Clearing

Never clear snapshots until backup files are:

  • Copied to remote storage
  • Verified for integrity
  • Tested for recoverability

Don't clear snapshots that are currently being copied or used.

Always list snapshots before clearing:

Terminal window
nodetool listsnapshots

Terminal window
nodetool listsnapshots

Output:

Snapshot name Keyspace name Column family name True size Size on disk
backup_20240115 my_keyspace users 1.5 GB 1.5 GB
backup_20240115 my_keyspace orders 2.3 GB 2.3 GB
backup_20240108 my_keyspace users 1.2 GB 0 bytes
Terminal window
nodetool listsnapshots | grep backup_20240115
Terminal window
# Check total snapshot space
du -sh /var/lib/cassandra/data/*/*/snapshots/
# Check specific snapshot
du -sh /var/lib/cassandra/data/*/*/snapshots/backup_20240115/

StateSSTableSnapshotDisk Usage
Before clearsnapshotActive (new)Hard link existsSpace shared via inode
After clearsnapshotActive (new)DeletedSpace freed if no other references

Space Reclamation

  • Hard links are removed by clearsnapshot
  • Disk blocks are freed only if no other references exist
  • Space reclamation may not be immediate depending on filesystem
Terminal window
# Before
df -h /var/lib/cassandra
# Clear snapshot
nodetool clearsnapshot -t old_backup
# After
df -h /var/lib/cassandra

#!/bin/bash
# Clear snapshots older than specified days
DAYS_OLD=7
KEYSPACE="my_keyspace"
# List snapshots and filter by age
nodetool listsnapshots | while read line; do
# Parse snapshot name and check date
# Implementation depends on naming convention
done

Instead of manual cleanup, create snapshots with TTL:

Terminal window
# Snapshot auto-deletes after 24 hours
nodetool snapshot -t temp_backup --ttl 24h my_keyspace

ERROR: Snapshot 'my_backup' does not exist

The snapshot tag wasn't found:

Terminal window
# List actual snapshot names
nodetool listsnapshots

If disk space doesn't decrease after clearing:

  1. Check if files were actually removed:

    Terminal window
    ls /var/lib/cassandra/data/*/*/snapshots/
  2. Hard links may still exist (original SSTable not yet compacted)

  3. Filesystem may not report freed space immediately

Permission issues:

Terminal window
# Check ownership
ls -la /var/lib/cassandra/data/my_keyspace/users-*/snapshots/
# Cassandra user should own files
sudo chown -R cassandra:cassandra /var/lib/cassandra/data/

Snapshot Cleanup Guidelines

  1. List before clearing - Verify which snapshots exist
  2. Use specific tags - Avoid --all in production
  3. Verify backups first - Ensure data is safely stored elsewhere
  4. Automate cleanup - Use TTL or scheduled scripts
  5. Monitor disk usage - Track snapshot growth over time
  6. Document retention - Define snapshot retention policies
Snapshot TypeRetention
Pre-maintenance24 hours after maintenance
Daily backup7 days
Weekly backup30 days
Monthly backup1 year

CommandRelationship
snapshotCreate snapshots
listsnapshotsList existing snapshots
tablestatsCheck snapshot space per table