-
Notifications
You must be signed in to change notification settings - Fork 0
/
functionForAll.py
60 lines (41 loc) · 1.58 KB
/
functionForAll.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/python
import os
import sys
import yaml
def getCassandraHome():
cassandraHome=''
try:
cassandraHome = os.environ['CASSANDRA_HOME']
except KeyError:
print "Please set the environment variable CASSANDRA_HOME"
sys.exit(1)
return cassandraHome
def validateKeyspace(keyspace):
if keyspace == "":
print "Please Provide Keyspace to Backup"
sys.exit(1)
def getCassandraDataDirectory():
cassandraHome = getCassandraHome()
cassandraConfigFile = cassandraHome+"/conf/cassandra.yaml"
with open(cassandraConfigFile, 'r') as f:
keys = yaml.load(f)
dataFileDirectory = keys["data_file_directories"]
return dataFileDirectory[0]
def userInteractionAndConfirmationForRestoreAction():
length=len(sys.argv)
if ( length <=3 ):
userInput = raw_input("If you proceed further the Keyspace provided will be restored on node, following actions will be taken: 1. Stop Cassandra, 2. Delete commit logs, 3. Restore keyspace 4. Restart cassandra. Do you want to continue [Y/n]?")
if userInput == "Y":
print("Cassandra Stopped")
else:
sys.exit(1)
cassandraDataDir = getCassandraDataDirectory()
#os.system("pgrep -f cassandra | xargs kill")
commitLogsLocation = "rm -rf " + cassandraDataDir+ "/../commitlog/*"
#os.system(commitLogsLocation)
keySpaceSSTLocation=cassandraDataDir+"/"+keyspace+"/"
print "Deleting Key Space SST table from " + keySpaceSSTLocation
deletSSTTablesCommand = "rm -rf " + keySpaceSSTLocation
#os.system ( deletSSTTablesCommand)
keyspace = sys.argv[1]
userInteractionAndConfirmationForRestoreAction()