Permalink
Browse files

Mount the EBS volume on the EC2 instance

  • Loading branch information...
alloy committed Jul 9, 2009
1 parent a9e2506 commit ac179cc41bc4388c8f1f7327a95b8ca2e307a8d7
Showing with 28 additions and 1 deletion.
  1. +12 −1 lib/backup.rb
  2. +15 −0 test/backup_test.rb
  3. +1 −0 test/fixtures/config.yml
View
@@ -1,6 +1,8 @@
+require "yaml"
+
require "rubygems"
require "executioner"
-require "yaml"
+require "net/ssh"
require "ec2"
@@ -29,6 +31,15 @@ def bring_backup_volume_online!
@ec2.attach_volume(@config['ec2']['ebs'], @ec2_instance_id, :d => "/dev/sdh")
sleep 2.5 until @ec2.attached?(@config['ec2']['ebs'])
+
+ mount_backup_volume!
+ end
+
+ def mount_backup_volume!
+ Net::SSH.start(@ec2.host_of_instance(@ec2_instance_id), 'root', :keys => [@config['ec2']['keypair_file']]) do |ssh|
+ ssh.exec! 'mkdir /mnt/data-store'
+ ssh.exec! 'mount /dev/sdh /mnt/data-store'
+ end
end
def mysql_databases
View
@@ -72,6 +72,8 @@ def strip_comments(sql)
end
it "should run an EC2 instance and wait till it's online" do
+ @backup.stubs(:mount_backup_volume!)
+
@ec2.expects(:run_instance).with('ami-nonexistant', :k => 'fingertips', :z => 'eu-west-1a').returns("i-nonexistant")
@ec2.expects(:running?).with do |id|
@@ -88,6 +90,8 @@ def @ec2.running?(id)
end
it "should attach the existing EBS instance and wait till it's online" do
+ @backup.stubs(:mount_backup_volume!)
+
@ec2.expects(:attach_volume).with("vol-nonexistant", "i-nonexistant", :d => "/dev/sdh")
@ec2.expects(:attached?).with do |id|
@@ -101,4 +105,15 @@ def @ec2.attached?(id)
@backup.bring_backup_volume_online!
end
+
+ it "should mount the attached EBS volume on the running instance" do
+ @ec2.expects(:host_of_instance).with('i-nonexistant').returns('instance.amazon.com')
+
+ ssh = mock('Net::SSH')
+ Net::SSH.expects(:start).with('instance.amazon.com', 'root', :keys => [@backup.config['ec2']['keypair_file']]).yields(ssh)
+ ssh.expects(:exec!).with('mkdir /mnt/data-store')
+ ssh.expects(:exec!).with('mount /dev/sdh /mnt/data-store')
+
+ @backup.bring_backup_volume_online!
+ end
end
View
@@ -3,6 +3,7 @@ ec2:
ebs: vol-nonexistant
ami: ami-nonexistant
keypair_name: fingertips
+ keypair_file: /Volumes/Fingertips Confidential/aws/fingertips/keys/fingertips
private_key_file: /Volumes/Fingertips Confidential/aws/fingertips/pk-6LN7EWTYKIDRU25OJYMTY6P75S43WA45.pem
certificate_file: /Volumes/Fingertips Confidential/aws/fingertips/cert-6LN7EWTYKIDRU25OJYMTY6P75S43WA45.pem
backup:

0 comments on commit ac179cc

Please sign in to comment.