Table of Contents

Backup

Backup in Cassandra is done on either:

  1. Server Level
  2. Keyspace(Schema/Database) Level
  3. Column Family(Table) Level

Cassandra also provides incremental backups, which will discuss later. Furthermore, restore depends if you are restoring the table to a single node or a cluster.

Server Backup

[root@lparacassandra newsnap]# nodetool snapshot
Requested creating snapshot(s) for [all keyspaces] with snapshot name [1526571477560] and options {skipFlush=false}
Snapshot directory: 1526571477560
[root@lparacassandra newsnap]#

Keyspace - Schema/Database - Backup

[root@lparacassandra ~]# nodetool -h localhost -p 7199 snapshot testkeyspace
Requested creating snapshot(s) for [testkeyspace] with snapshot name [1526547378058] and options {skipFlush=false}
Snapshot directory: 1526547378058

Keyfamily - Table - Backup

[root@lparacassandra newsnap]# nodetool snapshot --table testtable testkeyspace
Requested creating snapshot(s) for [testkeyspace] with snapshot name [1526571643515] and options {skipFlush=false}
Snapshot directory: 1526571643515
[root@lparacassandra newsnap]#

Restore

Table Restore

Restore is done pretty simple in Cassandra, although it can be pain sometimes:

  1. Create the schema if not created already.
  2. Truncate the table,if necessary.
  3. Locate the snapshot folder(/var/lib/keyspace_name/table_name UUID/snapshots/snapshot_name) and copy the snapshot SSTable directory to the /var/lib/keyspace/table_name-UUID directory.
  4. Run nodetool refresh.

cqlsh:testkeyspace> select * from testTable;

 id | name
----+--------
  1 | Julien

(1 rows)
cqlsh:testkeyspace> truncate table testTable;
cqlsh:testkeyspace>
cqlsh:testkeyspace>
[root@lparacassandra testtable-d1d2aa6059e411e8a087c7aceeb1b122]# cp snapshots/newsnap/* .
[root@lparacassandra testtable-d1d2aa6059e411e8a087c7aceeb1b122]# ls -lart
total 44
drwxr-xr-x 2 cassandra cassandra    6 May 17 11:13 backups
drwxr-xr-x 4 cassandra cassandra  106 May 17 11:13 ..
drwxr-xr-x 4 cassandra cassandra   62 May 17 11:15 snapshots
-rw-r--r-- 1 root      root       836 May 17 11:16 schema.cql
-rw-r--r-- 1 root      root        92 May 17 11:16 mc-1-big-TOC.txt
-rw-r--r-- 1 root      root        56 May 17 11:16 mc-1-big-Summary.db
-rw-r--r-- 1 root      root      4606 May 17 11:16 mc-1-big-Statistics.db
-rw-r--r-- 1 root      root         8 May 17 11:16 mc-1-big-Index.db
-rw-r--r-- 1 root      root        16 May 17 11:16 mc-1-big-Filter.db
-rw-r--r-- 1 root      root        10 May 17 11:16 mc-1-big-Digest.crc32
-rw-r--r-- 1 root      root        37 May 17 11:16 mc-1-big-Data.db
-rw-r--r-- 1 root      root        43 May 17 11:16 mc-1-big-CompressionInfo.db
-rw-r--r-- 1 root      root        31 May 17 11:16 manifest.json
drwxr-xr-x 4 cassandra cassandra  297 May 17 11:16 .
[root@lparacassandra testtable-d1d2aa6059e411e8a087c7aceeb1b122]# chown -R cassandra:cassandra *
[root@lparacassandra testtable-d1d2aa6059e411e8a087c7aceeb1b122]# ls -lart
total 44
drwxr-xr-x 2 cassandra cassandra    6 May 17 11:13 backups
drwxr-xr-x 4 cassandra cassandra  106 May 17 11:13 ..
drwxr-xr-x 4 cassandra cassandra   62 May 17 11:15 snapshots
-rw-r--r-- 1 cassandra cassandra  836 May 17 11:16 schema.cql
-rw-r--r-- 1 cassandra cassandra   92 May 17 11:16 mc-1-big-TOC.txt
-rw-r--r-- 1 cassandra cassandra   56 May 17 11:16 mc-1-big-Summary.db
-rw-r--r-- 1 cassandra cassandra 4606 May 17 11:16 mc-1-big-Statistics.db
-rw-r--r-- 1 cassandra cassandra    8 May 17 11:16 mc-1-big-Index.db
-rw-r--r-- 1 cassandra cassandra   16 May 17 11:16 mc-1-big-Filter.db
-rw-r--r-- 1 cassandra cassandra   10 May 17 11:16 mc-1-big-Digest.crc32
-rw-r--r-- 1 cassandra cassandra   37 May 17 11:16 mc-1-big-Data.db
-rw-r--r-- 1 cassandra cassandra   43 May 17 11:16 mc-1-big-CompressionInfo.db
-rw-r--r-- 1 cassandra cassandra   31 May 17 11:16 manifest.json
[root@lparacassandra newsnap]# nodetool refresh testkeyspace testtable
[root@lparacassandra newsnap]# cqlsh
Connected to Test Cluster at 127.0.0.1:9042.
[cqlsh 5.0.1 | Cassandra 3.11.2 | CQL spec 3.4.4 | Native protocol v4]
Use HELP for help.
cqlsh> use testkeyspace
   ... ;
cqlsh:testkeyspace> select * from testtable;

 id | name
----+--------
  1 | Julien