Denis
Denis

Reputation: 31

Exporting a Cassandra Keyspace with Data to a file

Am trying to export a Cassandra Keyspace plus Data to a file. Is there a cqlsh command that allows the export of all tables + Data at once.?

I used this code to export the keyspace. Now I would like to export all the Data from all the tables into the file.

$ cqlsh -e "DESCRIBE KEYSPACE somekeyspace" > /path/to/somekeyspace.cql 

Upvotes: 1

Views: 4732

Answers (2)

adramazany
adramazany

Reputation: 664

Based on Taking a snapshot article in the Datastax you can get an snapshot of all tables included in on keyspace with the below commands,

nodetool cleanup mykeyspace
nodetool -h localhost -p 7199 snapshot mykeyspace

you can find detailed description in here: https://docs.datastax.com/en/cassandra-oss/3.0/cassandra/operations/opsBackupTakesSnapshot.html

Upvotes: 0

Rigerta
Rigerta

Reputation: 4039

Looking at the DataStax documentation, you should be able to do that using the COPY command as follows (for a single table):

COPY someKeySpace.someTable (someCol1, someCol2) 
TO '/path/to/someTable_Col1Col2.csv' WITH HEADER = TRUE;

For all tables, probably you will need to write this code multiple times OR iterate through the tables. You might find this article also useful.

ps. I also found this GitHub repo that seems interesting, but I haven't used it yet myself, so I am suggesting it here for you to maybe give it a try :)

https://github.com/masumsoft/cassandra-exporter

Upvotes: 2

Related Questions