5

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

2 Answers 2

9

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.

3

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.