After hours of research I found a way to migrate keypsaces from cassandra to cassandra, its very simple actually without any need to backup snapshots of keyspaces or tables of existing data.
Usecase Scenario : Assume a company wants to migrate its data from development environment to production. You have a cassandra database which you want to migrate to production environment there is one way where you take snapshots of each keyspace and then restore them one by one which for me make my work more complicated.
I have come up with a solution which make migration very easy and fast. Below are the steps to migrate cassandra database to other different cassandra database :
- Cassandra should be installed but not running on the system
- If you have already started Cassandra then stop it and clear it log files from
Step 1 : Copy Cassandra data directory from old Cassandra database
Usually data directory is located at
tar -zcvf cassandra.tar.gz /var/lib/cassandra
Step 2 : Move and extract tar file to production environment
scp cassandra.tar.gz email@example.com:~ sudo tar -xzvf cassandra.tar.gz
Step 3 : Clear the commit log from
sudo rm -rf cassandra/commitlog/*
Step 4 : Copy and replace the
/var/lib/cassandra directory with the one copied from old environment
sudo mv /var/lib/cassandra /var/lib/cassandra_backup sudo cp -R cassandra /var/lib/cassandra
Step 5 : Change the ownership of all the files in
sudo chown root:root -R /var/lib/cassandra/*
Step 6 : Start the cassandra services and check for the log files for any error
sudo service cassandra start
Check that cassandra is listening to the port 9160 :
sudo netstat -tulpn
Look for any possible errors if not in cassandra startup log file :
sudo nano /var/log/cassandra.log
Step 7: Login into cassandra terminal and check for the keyspaces
If everything is normal and cassandra is running with no error’s then login in cassandra
cqlsh 10.0.1.102 9160 cqlsh> show keyspaces;
At this moment you should be able to see all the data exported. If not then make sure you have followed all the above steps as each of them is important including clearing log files, making sure that the cassandra is not working, if working in background then just kill the process then restart it.
Step 8 (Optional): If you have multinode installation then repair the keyspaces using nodetool
Using nodetool command will sync and repair your database keyspaces on other nodes.
This how you easily migrate keyspaces from cassandra to cassandra.
Hope that helped, if any problem feel free to drop in you queries in comments section below or you can write it to me.