Apache Cassandra

Cassandra Clear Snapshots

“Databases are some of the most critical infrastructures in modern web applications. It is, therefore, a good practice to ensure they are always running at optimum capacity and able to handle any amount of data.

Cleaning up old and unused data is one way to ensure that your databases run at the best performance. Removing old database files allows the database to write new files without possibly overwriting.

This tutorial will discuss how to evict old snapshot files from your Apache Cassandra cluster.”

Taking a Snapshot in Cassandra

We will start by creating sample snapshots to illustrate how to remove old snapshots from your cluster.

NOTE: This section does not cover the various backups or how to take specific snapshots. Check our tutorial on creating Cassandra snapshots to learn more.

Cassandra Create Snapshot for All Keyspaces

To create a snapshot for all keyspaces in the cluster, we can run the command:

$ nodetool snapshot -t server_backup

 
The command above creates a snapshot of all the keyspaces in the cluster and saves them under the server_backup directory.

An example list of snapshots is as shown:

Cassandra Show Available Snapshots

Before deleting any snapshots, you can view the available snapshots in the cluster by running the command:

$ nodetool listsnapshots

 
The query provided above displays all the snapshots in the cluster.

Deleting Snapshots

Cassandra will not remove any old snapshots even when taking new snapshots. Therefore, it is up to you to manually clean up old snapshots.

To delete all the snapshots within your cluster, you can use the clearsnapshot command as:

$ nodetool clearsnapshot --all

 
The command will remove all the snapshots in that node and return a message as shown:


You can verify all the snapshots are cleaned using the listsnapshot command:

$ nodetool listsnapshots

 
Output:

Snapshot Details:
There are no snapshots

 
You can use the -t option followed by the snapshot name to delete a single snapshot. The command syntax is as shown:

$ nodetool clearsnapshot -t <snapshot_name>

 
For example:


The command will remove the snapshot with the name server_backup.

Conclusion

In this article, you learned how to create a snapshot, view the available snapshots, and delete old snapshots from a Cassandra cluster.

Thanks for reading!!

About the author

John Otieno

My name is John and am a fellow geek like you. I am passionate about all things computers from Hardware, Operating systems to Programming. My dream is to share my knowledge with the world and help out fellow geeks. Follow my content by subscribing to LinuxHint mailing list