Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keyspace schema import and export in Cassandra

Tags:

java

cassandra

I have a Cassandra 1.1.2 installation on my system as a single node cluster and have three keyspaces: hotel, student and employee. I want to dump the keyspace schema of hotel along with its column family data if possible and restore the dump on other Cassandra cluster. Can any one suggest me in detail that how should I do this?

like image 696
Sunil Kumar Avatar asked Jul 27 '12 05:07

Sunil Kumar


People also ask

What is the use of Keyspace in Cassandra?

In a Cassandra cluster, a keyspace is an outermost object that determines how data replicates on nodes. Keyspaces consist of core objects called column families (which are like tables in RDBMS), rows indexed by keys, data types, data center awareness, replication factor, and keyspace strategy.

How do I get to Keyspace in Cassandra?

Go to data tab > there you will see all keyspcaces created by you and some system keyspaces. You can see all tables under individual keyspaces and also replicator factor for keyspace.

How do I import data into Cassandra?

After executing above cqlsh query the line prompt changes to [copy] let's have a look. Starting copy of cluster1. Data with columns [id, firstname, lastname]. Now, insert the row value of table which you want to import.

How do I export Cassandra data to CSV?

Right click on the output and select "Copy All as CSV" to paste the output in CSV.


1 Answers

You can use sstable2json and json2sstable cassandra tools

Check out Datastax documentation on the same and this too

Usage: sstable2json [-f outfile] <sstable> [-k key [-k key [...]]]
Usage: json2sstable -K keyspace -c column_family <json> <sstable>

You can always execute cassandra-cli commands in file

cassandra-cli -h HOST -p PORT -f fileName

You can load all your create statements in to a file and execute this command

To get cli scripts to create keyspaces and column families use following command in cassandra-cli interface

show schema

But incase you wanna create a cluster of two nodes. You don't need to do all the above. Just starting the other node with different token range and same cluster name would do. Cassandra internally will manage to stream the data and schema informations

like image 190
Tamil Avatar answered Oct 12 '22 23:10

Tamil