nodetool snapshot

Take a snapshot of one or more keyspaces, or of a table, to backup data.

Take a snapshot of one or more keyspaces, or of a table, to backup data.

Synopsis

nodetool <options> snapshot
  ( -cf <table> | --column-family <table> )
  (-kc <ktlist> | --kc.list <ktlist> | -kt <ktlist> | --kt-list <ktlist>)
  ( -t <tag> | --tag <tag> )
-- ( <keyspace>  |  <keyspace> ... )
Table 1. Options
Short Long Description
-h --host Hostname or IP address
-p --port Port number
-pwf --password-file Password file path
-pw --password Password
-u --username User name
-- Separates an option from an argument that could be mistaken for a option.
Other options are:
  • -cf, or --column-family, followed by the name of the table to be backed up.
  • -kc, --kc.list, -kt, or --kt-list, followed by a list of keyspace.table names to be back up, ktlist.
  • -t or --tag, followed by the snapshot name.
  • keyspace is a single keyspace name that is required when using the -cf option
  • keyspace_list is one or more optional keyspace names, separated by a space.

Description

Use this command to backup and restore using a snapshot. See the examples below for various options.

Cassandra flushes the node before taking a snapshot, takes the snapshot, and stores the data in the snapshots directory of each keyspace in the data directory. If you do not specify the name of a snapshot directory using the -t option, Cassandra names the directory using the timestamp of the snapshot, for example 1391460334889. Follow the procedure for taking a snapshot before upgrading Cassandra. When upgrading, backup all keyspaces.

Example: All keyspaces

Take a snapshot of all keyspaces on the node. On Linux, in the Cassandra bin directory, for example:

bin/nodetool snapshot

The following message appears:

Requested creating snapshot(s) for [all keyspaces] with snapshot name [1391464041163]
Snapshot directory: 1391464041163

Because you did not specify a snapshot name, Cassandra names snapshot directories using the timestamp of the snapshot.

Example: Single keyspace snapshot

Assuming you created the keyspace and tables in the music service example, take a snapshot of the music keyspace and name the snapshot 2014.06.24.

bin/nodetool snapshot -t 2014.06.24 music

The following message appears:

Requested creating snapshot(s) for [music] with snapshot name [2014.06.24]
Snapshot directory: 2014.06.24
Assuming the music keyspace contains two tables, songs and playlists, taking a snapshot of the keyspace creates multiple snapshot directories named 2014.06.24. A number of .db files containing the data are located in these directories. For example, from the installation directory:
cd data/data/music/playlists-bf8118508cfd11e3972273ded3cb6170/snapshots/1404936753154
$ ls
music-playlists-ka-1-CompressionInfo.db  music-playlists-ka-1-Index.db       music-playlists-ka-1-TOC.txt
music-playlists-ka-1-Data.db             music-playlists-ka-1-Statistics.db
music-playlists-ka-1-Filter.db           music-playlists-ka-1-Summary.db
cd data/data/music/songs-b8e385a08cfd11e3972273ded3cb6170/2014.06.24/snapshots/1404936753154
music-songs-ka-1-CompressionInfo.db	music-songs-ka-1-Index.db		music-songs-ka-1-TOC.txt
music-songs-ka-1-Data.db		music-songs-ka-1-Statistics.db
music-songs-ka-1-Filter.db		music-songs-ka-1-Summary.db

Example: Multiple keyspaces snapshot

Assuming you created a keyspace named mykeyspace in addition to the music keyspace, take a snapshot of both keyspaces.

bin/nodetool snapshot mykeyspace music

The following message appears:

Requested creating snapshot(s) for [mykeyspace, music] with snapshot name [1391460334889]
Snapshot directory: 1391460334889

Example: Single table snapshot

Take a snapshot of only the playlists table in the music keyspace.

bin/nodetool snapshot -cf playlists music
Requested creating snapshot(s) for [music] with snapshot name [1391461910600]
Snapshot directory: 1391461910600
Cassandra creates the snapshot directory named 1391461910600 that contains the backup data of playlists table in data/data/music/playlists-bf8118508cfd11e3972273ded3cb6170/snapshots, for example.

Example: List of different keyspace.tables snapshot

Take a snapshot of several tables in different keyspaces, such as the playlists table in the music keyspace and the users table in the test keyspace. The keyspace.table list should be comma-delimited with no spaces.

bin/nodetool snapshot -kt music.playlists,test.users
Requested creating snapshot(s) for [music.playlists,test.users] with snapshot name [1431045288401]
Snapshot directory: 1431045288401