Create and restore Cassandra backups
Backup
To back up the database, create a dump file using the nodetool command. These steps show you how to create a snapshot. Follow these instructions if you want to enable incremental backups in Cassandra.
NOTE: This tutorial assume that you have created at least one keyspace in your database.
-
Check the status of the keyspace. Remember to replace KEYSPACE with the right value.
$ nodetool status KEYSPACE datacenter: datacenter1 ======================== Status=Up/Down |/ State=Normal/Leaving/Joining/Moving -- Address Load Tokens Owns (effective) Host ID Rack UN 10.0.6.66 335.61 KiB 256 39.6% 73d7741f-40a8-4f8f-8f49-073ce37e2c23 rack1 UN 10.0.4.215 199.95 KiB 256 41.2% 0fa77708-f5a7-4160-93ac-09944fd4c66c rack1 UN 10.0.7.42 227.53 KiB 256 41.7% cd6c98b5-1551-4dff-8fa6-feeb11da32ed rack1
-
Execute the command below to create the snapshot:
$ nodetool snapshot KEYSPACE
This operation could take some time depending on the database size. You should get an output similar like this:
Requested creating snapshot(s) for [KEYSPACE] with snapshot name [1483626087852] and options {skipFlush=false} Snapshot directory: 1483626087852
-
It creates one snapshot per table you have in your keyspace. Find the snapshot at /opt/bitnami/cassandra/data/data/KEYSPACE/TABLENAME-UUID/snapshots/SNAPSHOTNAME. (The UUID is randomly generated. This number depends on your own installation).
Restore
To restore the database from a snapshot, follow the steps below.
NOTE: Remember that you can find the snapshot file at /opt/bitnami/cassandra/data/data/KEYSPACE/TABLENAME-UUID/snapshots/SNAPSHOTNAME. (The UUID is randomly generated. This number depends on your own installation).
-
Drain the node (this is especially important if only a single table is restored). Run the following command:
$ nodetool drain
-
Shut down the node:
$ sudo service bitnami stop
-
Clear all files from the /opt/bitnami/cassandra/data/commitlog directory:
$ sudo rm /opt/bitnami/cassandra/data/commitlog/*
-
Delete all .db files from the /opt/bitnami/cassandra/data/data/system/local-UUID/ directory. (The UUID is randomly generated. This number depends on your own installation):
NOTE: Don’t delete the backup and snapshots subdirectories.
$ sudo find . -name "/opt/bitnami/cassandra/data/data/system/local-UUID/*/*.db" -type f -delete
-
Copy the content of the last snapshot folder into this directory /opt/bitnami/cassandra/data/data/KEYSPACE/TABLENAME-UUID/:
$ sudo cp /opt/bitnami/cassandra/data/data/KEYSPACE/TABLENAME-UUID/snapshots/SNAPSHOTNAME /opt/bitnami/cassandra/data/data/KEYSPACE/TABLENAME-UUID/
Remember to replace KEYSPACE in the previous commands with the name of your keyspace and TABLENAME with the name of the table you have created. The UUID and the SNAPSHOTNAME are randomly generated. They depend on your installation.
-
Restart the node:
$ sudo service bitnami restart
-
Check the status of the node:
$ nodetool status KEYSPACE
-
Run nodetool repair to repair one or more tables (to repair more than one table you need to repeat the steps above per each table. However if no tables are listed, the tool operates on all tables):
$ nodetool repair KEYSPACE
This command must show you an output like this:
Repair completed successfully
Repair command #1 finished in 2 seconds