Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
datatstax_pssh and S3 store/restore capabilities
- Loading branch information
1 parent
7eb6036
commit 0380747
Showing
9 changed files
with
302 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#!/usr/bin/env python | ||
### Script provided by DataStax. | ||
|
||
import os | ||
import random | ||
import subprocess | ||
import shlex | ||
import sys | ||
|
||
|
||
commands = [ | ||
'Enter a custom command...', | ||
'nodetool -h localhost ring', | ||
'datastax_s3_store', | ||
'datastax_s3_restore', | ||
'sudo /etc/init.d/cassandra start', | ||
'sudo /etc/init.d/cassandra stop', | ||
'sudo /etc/init.d/cassandra restart' | ||
] | ||
|
||
# Function to execute commands and print traces of the command and output for debugging/logging purposes | ||
def exe(command, log=True): | ||
# Executes command and wait for completion | ||
process = subprocess.Popen(shlex.split(command), stderr=subprocess.PIPE, stdout=subprocess.PIPE) | ||
read = process.communicate() | ||
|
||
# Prints output to stdout | ||
print read[0] | ||
print read[1] | ||
|
||
# return process | ||
return read | ||
|
||
def datastax_ssh(command): | ||
exe('parallel-ssh --hosts /etc/cassandralauncher/nodelist --user ubuntu --print %s' % command) | ||
|
||
try: | ||
print "Welcome to DataStax' Parallel SSH Utility!" | ||
|
||
selection = False | ||
while not selection: | ||
print "Choose a command to run across the cluster:" | ||
for i, command in enumerate(commands): | ||
print " %s. %s" % (i, command) | ||
|
||
try: | ||
selection = int(raw_input("")) | ||
|
||
if selection == 0: | ||
selection = raw_input("Please input your command: ") | ||
else: | ||
if selection in [2, 3]: | ||
number = random.randint(0, 100) | ||
if raw_input("Enter the number '%s' to verify you wish to run `%s` clusterwide: " % (number, commands[selection])) != str(number): | ||
sys.exit(1) | ||
else: | ||
print "Performing command: %s..." % commands[selection] | ||
|
||
selection = commands[selection] | ||
except KeyboardInterrupt: | ||
raise | ||
except: | ||
print "Invalid selection. Please try again." | ||
selection = False | ||
|
||
datastax_ssh(selection) | ||
# Catch, log, and display pretty KeyboardInterrupts | ||
except KeyboardInterrupt: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#!/usr/bin/env python | ||
|
||
import ConfigParser | ||
import os | ||
import re | ||
import shlex | ||
import subprocess | ||
import yaml | ||
|
||
configfile = '/home/ubuntu/.s3cfg' | ||
|
||
def exe(command, wait=True): | ||
"""Execute a subprocess command""" | ||
|
||
# Open a subprocess to run your command | ||
process = subprocess.Popen(shlex.split(str(command)), stdout=subprocess.PIPE, stderr=subprocess.PIPE) | ||
if wait: | ||
read = process.communicate() | ||
return read | ||
else: | ||
return process | ||
|
||
def s3_restore(): | ||
print "Stopping the node..." | ||
exe('sudo service dse stop') | ||
exe('sudo service cassandra stop') | ||
|
||
print "Clearing current data..." | ||
exe('sudo rm -rf %s/*' % os.path.join(root_data_dir, 'data')) | ||
|
||
print "Downloading data..." | ||
response = exe('sudo s3cmd sync --delete-removed s3://%s-%s/%s/%s/ %s' % ( | ||
bucket_name, access_key, | ||
cluster_name, initial_token, | ||
os.path.join(root_data_dir, 'data/') | ||
)) | ||
if response[1]: | ||
print response[1] | ||
|
||
print "Restarting the node..." | ||
exe('sudo service dse restart') | ||
exe('sudo service cassandra restart') | ||
|
||
|
||
# Read access_key | ||
config = ConfigParser.RawConfigParser() | ||
config.read(configfile) | ||
access_key = config.get('default', 'access_key') | ||
bucket_name = config.get('datastax', 'bucket_name') if config.has_option('default', 'bucket_name') else 'datastax_s3_storage' | ||
root_data_dir = config.get('datastax', 'root_data_dir') if config.has_option('default', 'root_data_dir') else '/raid0/cassandra' | ||
|
||
# Read cluster_name and initial_token | ||
with open('/etc/dse/cassandra/cassandra.yaml') as f: | ||
dataMap = yaml.load(f) | ||
cluster_name = re.sub(r'\W+', '_', dataMap['cluster_name']) | ||
initial_token = dataMap['initial_token'] | ||
|
||
s3_restore() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#!/usr/bin/env python | ||
|
||
import ConfigParser | ||
import os | ||
import re | ||
import shlex | ||
import subprocess | ||
import yaml | ||
|
||
configfile = '/home/ubuntu/.s3cfg' | ||
|
||
def exe(command, wait=True): | ||
"""Execute a subprocess command""" | ||
|
||
# Open a subprocess to run your command | ||
process = subprocess.Popen(shlex.split(str(command)), stdout=subprocess.PIPE, stderr=subprocess.PIPE) | ||
if wait: | ||
read = process.communicate() | ||
return read | ||
else: | ||
return process | ||
|
||
def s3_store(): | ||
print "Draining the node..." | ||
exe('nodetool -h localhost drain') | ||
|
||
|
||
# Create the bucket | ||
exe('s3cmd mb s3://%s-%s' % (bucket_name, access_key)) | ||
|
||
print "Uploading data..." | ||
response = exe('sudo s3cmd sync --delete-removed %s s3://%s-%s/%s/%s/' % ( | ||
os.path.join(root_data_dir, 'data/'), | ||
bucket_name, access_key, | ||
cluster_name, initial_token | ||
)) | ||
if response[1]: | ||
print response[1] | ||
|
||
print "Stopping the node..." | ||
exe('sudo service dse stop') | ||
exe('sudo service cassandra stop') | ||
|
||
|
||
# Read access_key | ||
config = ConfigParser.RawConfigParser() | ||
config.read(configfile) | ||
access_key = config.get('default', 'access_key') | ||
bucket_name = config.get('datastax', 'bucket_name') if config.has_option('default', 'bucket_name') else 'datastax_s3_storage' | ||
root_data_dir = config.get('datastax', 'root_data_dir') if config.has_option('default', 'root_data_dir') else '/raid0/cassandra' | ||
|
||
# Read cluster_name and initial_token | ||
with open('/etc/dse/cassandra/cassandra.yaml') as f: | ||
dataMap = yaml.load(f) | ||
cluster_name = re.sub(r'\W+', '_', dataMap['cluster_name']) | ||
initial_token = dataMap['initial_token'] | ||
|
||
s3_store() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
[default] | ||
access_key = $ACCESS_KEY | ||
acl_public = False | ||
bucket_location = US | ||
cloudfront_host = cloudfront.amazonaws.com | ||
cloudfront_resource = /2008-06-30/distribution | ||
default_mime_type = binary/octet-stream | ||
delete_removed = False | ||
dry_run = False | ||
encoding = UTF-8 | ||
encrypt = False | ||
force = False | ||
get_continue = False | ||
gpg_command = /usr/bin/gpg | ||
gpg_decrypt = %(gpg_command)s -d --verbose --no-use-agent --batch --yes --passphrase-fd %(passphrase_fd)s -o %(output_file)s %(input_file)s | ||
gpg_encrypt = %(gpg_command)s -c --verbose --no-use-agent --batch --yes --passphrase-fd %(passphrase_fd)s -o %(output_file)s %(input_file)s | ||
gpg_passphrase = $SECRET_KEY | ||
guess_mime_type = True | ||
host_base = s3.amazonaws.com | ||
host_bucket = %(bucket)s.s3.amazonaws.com | ||
human_readable_sizes = False | ||
list_md5 = False | ||
preserve_attrs = True | ||
progress_meter = True | ||
proxy_host = | ||
proxy_port = 0 | ||
recursive = False | ||
recv_chunk = 4096 | ||
secret_key = $SECRET_KEY | ||
send_chunk = 4096 | ||
simpledb_host = sdb.amazonaws.com | ||
skip_existing = False | ||
urlencoding_mode = normal | ||
use_https = False | ||
verbosity = WARNING | ||
|
||
[datastax] | ||
root_data_dir = '/raid0/cassandra' | ||
bucket_name = 'datastax_s3_storage' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters