“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:
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:
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:
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:
Output:
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:
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!!