1

For example, how I can take snapshots programmatically and also restore them. Please help me if you have any solution or workaround it.

Erick Ramirez
  • 13,964
  • 1
  • 18
  • 23
Mayank Raghav
  • 640
  • 1
  • 7
  • 17
  • 1
    Possible duplicate of [cassandra snapshot without nodetool but by java api only](http://stackoverflow.com/questions/12403292/cassandra-snapshot-without-nodetool-but-by-java-api-only) – Rafael Emshoff Nov 30 '15 at 12:50
  • @Rafael right now my use case is taking/restoring snapshots only, but I may need to run other nodetool commands pro-grammatically in future. – Mayank Raghav Dec 01 '15 at 09:11

2 Answers2

2

You could use cassandra's source code as a library (nodetool utility is part of that source code). There are classes called NodeProbe and Status that you can use.

Apoorv
  • 2,525
  • 2
  • 14
  • 18
  • Can you provide some details about how to this exacly with some example – Manish Kumar Jan 31 '18 at 07:22
  • Once you add a dependency on cassandra's jar, here's how you can remove a node from your cluster: new NodeProbe("ip-address-of-an-endpoint-in-cluster").removeNode("host-id-of-node-running-cassandra") Once you have an instance of NodeProbe class, browse its methods to see what all you can do. – Apoorv Jan 31 '18 at 18:28
1

Use JMX, I like jmxsh for this kind of thing. You can call it from cron.

If you're looking for a more complete solution, OpsCenter does backup and restore (point and click). Check out Mani's post. I mention this since you have datastax-enterprise in the question. The backup service is disabled if you're running open source cassandra.

Here's some sample shell scripting I've used to change concurrent compactors, you can do something similar.

wget https://jmxsh.googlecode.com/files/jmxsh-R5.jar
wget https://jmxsh.googlecode.com/files/jmxsh
echo jmx_set -m org.apache.cassandra.db:type=CompactionManager CoreCompactorThreads 4 > changeCoreCompactors.sh
echo jmx_set -m org.apache.cassandra.db:type=CompactionManager MaximumCompactorThreads 4 > changeMaxCompactors.sh
java -jar jmxsh-R5.jar -h localhost -p 7199 -q changeCoreCompactors.sh 
java -jar jmxsh-R5.jar -h localhost -p 7199 -q changeMaxCompactors.sh 
phact
  • 7,305
  • 23
  • 27
  • 2
    Thanks ! Can you guide me to any such 'JMXSH' existing code for this purpose. Any idea why Cassandra driver haven't provided such functionality(or I am wrong)? – Mayank Raghav Dec 01 '15 at 09:07