Skip to content

Instantly share code, notes, and snippets.

@jonneale
Last active December 17, 2015 20:39
Show Gist options
  • Save jonneale/5669298 to your computer and use it in GitHub Desktop.
Save jonneale/5669298 to your computer and use it in GitHub Desktop.
Dynamo DB backups using the Ruby AWS SDK
require 'aws-sdk'
AWS.config({:access_key_id => "your-access-key-id",
:secret_access_key => "your-secrect-access-key",
:region => "eu-west-1"}) #region is optional
log_uri = "s3n://dynamo-backups/dynamo-backup-resources/logs" #Can be anywhere you like on S3
emr = AWS::EMR.new
job = emr.job_flows.create('dynamo-db-backup', {log_uri: log_uri,
instances:
{keep_job_flow_alive_when_no_steps: false,
instance_count: 1,
master_instance_type: 'm1.small',
slave_instance_type: 'm1.small'},
ami_version: "latest"})
job.add_steps([{:name => 'setup-hive',
:action_on_failure => 'TERMINATE_JOB_FLOW',
:hadoop_jar_step => {
:jar => "s3://us-east-1.elasticmapreduce/libs/script-runner/script-runner.jar",
:args => ["s3://us-east-1.elasticmapreduce/libs/hive/hive-script",
"--base-path",
"s3://us-east-1.elasticmapreduce/libs/hive/",
"--install-hive",
"--hive-versions",
"0.8.1.7"]}},
{:name => 'run-hive-script',
:action_on_failure => 'CANCEL_AND_WAIT',
:hadoop_jar_step => {
:jar => "s3://us-east-1.elasticmapreduce/libs/script-runner/script-runner.jar",
:args => ["s3://us-east-1.elasticmapreduce/libs/hive/hive-script",
"--base-path",
"s3://us-east-1.elasticmapreduce/libs/hive/",
"--hive-versions",
"0.8.1.7",
"--run-hive-script",
"--args",
"-f",
"s3n://dynamo-backup-resources/backup-to-s3.hql",
"-hiveconf",
"backup_path=s3n://dynamo-backups/#{Time.now.strftime("%Y-%m-%d")}"
]}}])
STDOUT.puts "Job #{job.id} has been started on the EMR cluster. Please check the Amazon dashboard for progress. Logs are available at #{log_uri}/#{job.id}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment