user1284795
user1284795

Reputation: 2371

How to do data migration of Cassandra from one keyspace to another keyspace?

I created an old keyspace in Cassandra cluster but found the definition of its "comparator" is wrong, so I have to recreate a new keyspace and do data migration. Is there any tool to do data migration? or I have to program with Thrift client read all data from old keyspace and write them to new keyspace? Any suggestions or code snippets is welcome!

Upvotes: 7

Views: 12856

Answers (2)

Visruth
Visruth

Reputation: 3450

We can do it using COPY command in cql. Using COPY command we can save table data to .csv file and back to a table from .csv file. But, the better approach will be to write a program to read from table and write it to another table because importing from csv may fail if the table contains collection column types like list<text>, map<text, text>, set<text>.

Eg :- To copy table data from table to .csv file :-

COPY keyspace1.table1 (column1, column2) TO 'path/to/file/keyspace1_table1.csv';

To copy csv data from file to a table :-

COPY keyspace2.table1 (column1, column2) FROM 'path/to/file/keyspace1_table1.csv';

Refer Cassandra migration tool

Upvotes: 2

hjarraya
hjarraya

Reputation: 326

This is a commun question, and I think it has been asked before here. You can use the COPY command in C*. You will find more details here http://www.datastax.com/dev/blog/ways-to-move-data-tofrom-datastax-enterprise-and-cassandra

Upvotes: 2

Related Questions