Skip to content

Instantly share code, notes, and snippets.

@ashayh
Forked from lusis/create_ebs.rb
Created October 15, 2012 00:01
Show Gist options
  • Save ashayh/3890216 to your computer and use it in GitHub Desktop.
Save ashayh/3890216 to your computer and use it in GitHub Desktop.
Small script to setup ec2 instances and EBS volumes for my blog post series
# Create 4 volumes and attach them to hdb
%w[sdi sdj sdk sdl].each do |dev|
volume = AWS.volumes.new :device => "/dev/#{dev}", :size => 5, :availability_zone => hdb.availability_zone
volume.server = hdb
volume.save
end
require 'rubygems'
require 'fog'
require 'ap'
settings = YAML.load_file("#{ENV['HOME']}/.fog")
aws_access_key = settings[:default][:aws_access_key_id]
aws_secret_key = settings[:default][:aws_secret_access_key]
AWS = Fog::AWS::Compute.new(:aws_access_key_id => aws_access_key, :aws_secret_access_key => aws_secret_key)
# HDB is our original server
hdb = AWS.servers.new :image_id => 'ami-eb807682', :key_name => 'prod'
hdb.save
# TDB is our testing server
tdb = AWS.servers.new :image_id => 'ami-eb807682', :key_name => 'prod'
tdb.save
# Make note of the instance ids for each of the new instances
# Create 4 volumes and attach them to hdb
%w[sdi sdj sdk sdl].each do |dev|
volume = AWS.volumes.new :device => "/dev/#{dev}", :size => 5, :availability_zone => hdb.availability_zone
volume.server = hdb
volume.save
end
# From this point, you can log on to the hdb server and create an array:
# mdadm --create /dev/md0 --level=0 --raid-devices=4 /dev/sdi /dev/sdj /dev/sdk /dev/sdl
# mkfs.ext3 -j /dev/md0
# mkdir /data
# mount /dev/md0 /data
#
# You can install mysql on the box, point the data directory to /data or whatever.
# When done, you can snapshot the volumes in Fog with the following:
hdb.block_device_mapping.each do |block_device|
snap = AWS.snapshots.new :volume_id => block_device['volumeId'], :description => 'HDB_BACKUP_2010-12-02'
snap.save
end
# Be sure and clean up after yourself:
# - detach the volumes from tdb
# - delete the volumes previously attached to tdb
# - shutdown tdb
# - delete the snapshots you created
# - detach the volumes from hdb
# - delete the volumes from hdb
# - shutdown hdb
require 'rubygems'
require 'fog'
require 'ap'
settings = YAML.load_file("#{ENV['HOME']}/.fog")
aws_access_key = settings[:default][:aws_access_key_id]
aws_secret_key = settings[:default][:aws_secret_access_key]
AWS = Fog::AWS::Compute.new(:aws_access_key_id => aws_access_key, :aws_secret_access_key => aws_secret_key)
# HDB is our original server
hdb = AWS.servers.new :image_id => 'ami-eb807682', :key_name => 'prod'
hdb.save
# TDB is our testing server
tdb = AWS.servers.new :image_id => 'ami-eb807682', :key_name => 'prod'
tdb.save
hdb.block_device_mapping.each do |block_device|
snap = AWS.snapshots.new :volume_id => block_device['volumeId'], :description => 'HDB_BACKUP_2010-12-02'
snap.save
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment