A snapshot first flushes all in-memory writes to the disk, then makes a hard link of the SSTable files for each keyspace. You must have enough free disk space on the node to accommodate making snapshots of your data files. A single snapshot requires little disk space, but snapshots can cause your disk usage to grow more quickly over time because a snapshot prevents old, obsolete data files from being deleted. After the snapshot is complete, you can move the backup files to another location if needed, or you can leave them in place.Note: Cassandra can only restore data from a snapshot when the table schema exists. It is recommended that you also backup the schema.
Run the nodetool snapshot command, specifying the hostname, JMX port, and keyspace. For example:
$ nodetool -h localhost -p 7199 snapshot mykeyspace
The snapshot is created in the data_directory_location/keyspace_name/table_name–UUID/snapshots/snapshot_name directory. Each snapshot directory contains numerous .db files that contain the data at the time of the snapshot. Such as:
Taking a Global Snapshot
As stated earlier, a global snapshot can be taken using the pssh tool. So let us configure this tool first.
The steps for configuring the pssh are:
- Install the pssh tool using the following command
sudo apt-get install python-pip sudo pip install pssh
- Create a hosts file that contains all the ip’s of the nodes present in that cluster and name it something like
It should look something like this:
192.168.2.123 192.168.2.125 192.168.2.120
- Now run the following command so that the snapshots get created on each and every node:
pssh -h pssh-hosts -P "/root/cassandra/bin/nodetool -h localhost -p 7199 snapshot "
Now you've taken the dump of data on each node. You can download it using secure copy and restore it accordingly. I am still working on automating the process of downloading the dump, but I will update you all as soon as it is done!
I hope youve enjoyed this article! If you have any queries, ping me here or on Twitter, and I'll be happy to help you out.