Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Export/Import entire cassandra database

Tags:

cassandra

Is a there a command line tool or a simple script that can export/copy entire Cassandra database (tables and data) and then import somewhere else

like image 226
lch Avatar asked Jan 25 '18 22:01

lch


2 Answers

To get the schema, you can use this:

cqlsh -e "DESCRIBE SCHEMA" > schema.cql

Regarding the data export, if you are just playing around, you might test the GitHub project that Mandraenke posted. But if you are doing this in a non-safe environment (production), I recommend AGAINST using that project. It's not safe, and they even wrote that on the project's page:

Disclaimer: most of the times, you really shouldn't be using this. It's fragile, non-scalable, inefficient and verbose.

The safest way is to write a script to output the data using the COPY command, and iterating over the tables. Check this article which might be of help: https://www.datastax.com/dev/blog/simple-data-importing-and-exporting-with-cassandra

This article also explains how to import the data using the same command.

Alternatively, you can just copy the SSTable files to the new place where you want to set up the database and then use sstableloader: http://docs.datastax.com/en/cassandra/2.1/cassandra/tools/toolsBulkloader_t.html

Don't forget you will still need the schema, even if you go for the SSTable files solution.

like image 60
Pedro Gordo Avatar answered Oct 11 '22 15:10

Pedro Gordo


Cassandra offers COPY and DESCRIBE KEYSPACES build in you can use for this. Also there are several projects on GitHub who are more user friendly, for example https://github.com/gianlucaborello/cassandradump - which is inspired by mysqldump.

But if you have a huge dataset this will take a really long time.

like image 37
Mandraenke Avatar answered Oct 11 '22 14:10

Mandraenke