nodetool clearsnapshot
Removes one or more snapshots from the node to reclaim disk space.
Synopsis
Section titled “Synopsis”nodetool [connection_options] clearsnapshot [options] [--] [keyspace ...]See connection options for connection options.
Description
Section titled “Description”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.
Arguments
Section titled “Arguments”| Argument | Description |
|---|---|
keyspace | Keyspace(s) to clear snapshots from. If omitted, clears from all keyspaces |
Options
Section titled “Options”| Option | Description |
|---|---|
-t, --tag | Snapshot tag to clear. Required unless using --all |
--all | Clear all snapshots |
Examples
Section titled “Examples”Clear Specific Snapshot
Section titled “Clear Specific Snapshot”nodetool clearsnapshot -t my_backupRemoves the snapshot tagged my_backup from all keyspaces.
Clear Snapshot from Specific Keyspace
Section titled “Clear Snapshot from Specific Keyspace”nodetool clearsnapshot -t my_backup my_keyspaceClear All Snapshots
Section titled “Clear All Snapshots”nodetool clearsnapshot --allUse with Caution
--all removes every snapshot on the node. Verify no critical backups exist before running.
Clear All Snapshots from Keyspace
Section titled “Clear All Snapshots from Keyspace”nodetool clearsnapshot --all my_keyspaceWhen to Use
Section titled “When to Use”After Successful Backup
Section titled “After Successful Backup”Once backup files have been copied off-node:
# After copying snapshot files to backup storagenodetool clearsnapshot -t backup_20240115Reclaim Disk Space
Section titled “Reclaim Disk Space”When disk usage is high due to old snapshots:
# Check snapshot sizes firstnodetool listsnapshots
# Remove old snapshotsnodetool clearsnapshot -t old_backupClean Up After Testing
Section titled “Clean Up After Testing”Remove snapshots created during testing:
nodetool clearsnapshot -t test_snapshotRegular Maintenance
Section titled “Regular Maintenance”Scheduled cleanup of aged snapshots:
# 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)When NOT to Use
Section titled “When NOT to Use”Before Verifying Backup
Section titled “Before Verifying Backup”Verify Before Clearing
Never clear snapshots until backup files are:
- Copied to remote storage
- Verified for integrity
- Tested for recoverability
On Active Snapshots
Section titled “On Active Snapshots”Don't clear snapshots that are currently being copied or used.
Without Checking First
Section titled “Without Checking First”Always list snapshots before clearing:
nodetool listsnapshotsVerification Before Clearing
Section titled “Verification Before Clearing”List All Snapshots
Section titled “List All Snapshots”nodetool listsnapshotsOutput:
Snapshot name Keyspace name Column family name True size Size on diskbackup_20240115 my_keyspace users 1.5 GB 1.5 GBbackup_20240115 my_keyspace orders 2.3 GB 2.3 GBbackup_20240108 my_keyspace users 1.2 GB 0 bytesCheck Specific Snapshot
Section titled “Check Specific Snapshot”nodetool listsnapshots | grep backup_20240115Verify Disk Usage
Section titled “Verify Disk Usage”# Check total snapshot spacedu -sh /var/lib/cassandra/data/*/*/snapshots/
# Check specific snapshotdu -sh /var/lib/cassandra/data/*/*/snapshots/backup_20240115/Space Reclamation
Section titled “Space Reclamation”How Space is Freed
Section titled “How Space is Freed”| State | SSTable | Snapshot | Disk Usage |
|---|---|---|---|
| Before clearsnapshot | Active (new) | Hard link exists | Space shared via inode |
| After clearsnapshot | Active (new) | Deleted | Space 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
Verifying Space Freed
Section titled “Verifying Space Freed”# Beforedf -h /var/lib/cassandra
# Clear snapshotnodetool clearsnapshot -t old_backup
# Afterdf -h /var/lib/cassandraAutomated Cleanup
Section titled “Automated Cleanup”Script for Aged Snapshots
Section titled “Script for Aged Snapshots”#!/bin/bash# Clear snapshots older than specified days
DAYS_OLD=7KEYSPACE="my_keyspace"
# List snapshots and filter by agenodetool listsnapshots | while read line; do # Parse snapshot name and check date # Implementation depends on naming conventiondoneUsing TTL Snapshots (4.0+)
Section titled “Using TTL Snapshots (4.0+)”Instead of manual cleanup, create snapshots with TTL:
# Snapshot auto-deletes after 24 hoursnodetool snapshot -t temp_backup --ttl 24h my_keyspaceCommon Issues
Section titled “Common Issues”"Snapshot does not exist"
Section titled “"Snapshot does not exist"”ERROR: Snapshot 'my_backup' does not existThe snapshot tag wasn't found:
# List actual snapshot namesnodetool listsnapshotsSpace Not Freed
Section titled “Space Not Freed”If disk space doesn't decrease after clearing:
-
Check if files were actually removed:
Terminal window ls /var/lib/cassandra/data/*/*/snapshots/ -
Hard links may still exist (original SSTable not yet compacted)
-
Filesystem may not report freed space immediately
Cannot Delete Snapshot Directory
Section titled “Cannot Delete Snapshot Directory”Permission issues:
# Check ownershipls -la /var/lib/cassandra/data/my_keyspace/users-*/snapshots/
# Cassandra user should own filessudo chown -R cassandra:cassandra /var/lib/cassandra/data/Best Practices
Section titled “Best Practices”Snapshot Cleanup Guidelines
- List before clearing - Verify which snapshots exist
- Use specific tags - Avoid
--allin production - Verify backups first - Ensure data is safely stored elsewhere
- Automate cleanup - Use TTL or scheduled scripts
- Monitor disk usage - Track snapshot growth over time
- Document retention - Define snapshot retention policies
Retention Policy Example
Section titled “Retention Policy Example”| Snapshot Type | Retention |
|---|---|
| Pre-maintenance | 24 hours after maintenance |
| Daily backup | 7 days |
| Weekly backup | 30 days |
| Monthly backup | 1 year |
Related Commands
Section titled “Related Commands”| Command | Relationship |
|---|---|
| snapshot | Create snapshots |
| listsnapshots | List existing snapshots |
| tablestats | Check snapshot space per table |