mongo-ec2-backup 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/Rakefile +1 -1
  2. data/bin/ec2_snapshot_restorer +37 -39
  3. metadata +1 -1
data/Rakefile CHANGED
@@ -8,7 +8,7 @@ task :default => :package
8
8
 
9
9
  spec = Gem::Specification.new do |s|
10
10
  s.name = 'mongo-ec2-backup'
11
- s.version = '0.0.6'
11
+ s.version = '0.0.7'
12
12
  s.summary = 'Snapshot your mongodb in the EC2 cloud via XFS Freeze'
13
13
 
14
14
  s.author = 'Pierre Baillet'
@@ -86,46 +86,44 @@ class SnapshotRestorer
86
86
  end
87
87
  end
88
88
 
89
- if __FILE__ == $0
90
- require 'trollop'
91
- require 'ec2_instance_identifier'
92
- require 'pp'
93
- opts = Trollop::options do
94
- opt :hostname, "Hostname tag to use to find the instance", :type => :string, :required => true
95
- opt :access_key_id, "Access Key Id for AWS", :type => :string, :required => true
96
- opt :secret_access_key, "Secret Access Key for AWS", :type => :string, :required => true
97
- opt :date, "Date to restore, use LATEST to take latest data", :type => :string
98
- opt :type, "Snapshot type to restore, defaults to snapshot", :type => :string, :default => 'snapshot'
99
- opt :target, "Creates volume ready for mounting on instance id. Use special value SELF to restore here", :type => :string
100
- opt :first_device, "First device to attach to (default is to use source first device) /dev/sdx", :type => :string
101
- end
102
-
103
- finder = EC2InstanceIdentifier.new(opts[:access_key_id], opts[:secret_access_key])
104
- instance_identifier = finder.get_instance(opts[:hostname]).id
105
- s = SnapshotRestorer.new(opts[:access_key_id], opts[:secret_access_key])
89
+ require 'trollop'
90
+ require 'ec2_instance_identifier'
91
+ require 'pp'
92
+ opts = Trollop::options do
93
+ opt :hostname, "Hostname tag to use to find the instance", :type => :string, :required => true
94
+ opt :access_key_id, "Access Key Id for AWS", :type => :string, :required => true
95
+ opt :secret_access_key, "Secret Access Key for AWS", :type => :string, :required => true
96
+ opt :date, "Date to restore, use LATEST to take latest data", :type => :string
97
+ opt :type, "Snapshot type to restore, defaults to snapshot", :type => :string, :default => 'snapshot'
98
+ opt :target, "Creates volume ready for mounting on instance id. Use special value SELF to restore here", :type => :string
99
+ opt :first_device, "First device to attach to (default is to use source first device) /dev/sdx", :type => :string
100
+ end
101
+
102
+ finder = EC2InstanceIdentifier.new(opts[:access_key_id], opts[:secret_access_key])
103
+ instance_identifier = finder.get_instance(opts[:hostname]).id
104
+ s = SnapshotRestorer.new(opts[:access_key_id], opts[:secret_access_key])
106
105
 
107
- # Find this instance snapshots
108
- snaps = s.find_snapshots(instance_identifier, opts[:type])
106
+ # Find this instance snapshots
107
+ snaps = s.find_snapshots(instance_identifier, opts[:type])
109
108
 
110
- if ! opts[:date] || !snaps.has_key?(opts[:date])
111
- puts "We have found the following snapshot's dates:"
112
- snaps.each do |k,v|
113
- puts "- #{k} (#{v.length} volume snapshots)"
114
- end
115
- else
116
- puts "Snapshot taken at #{opts[:date]}"
117
- snaps[opts[:date]].each do |snapshot|
118
- puts "- #{snapshot.id}, #{snapshot.volume_size}GB - #{snapshot.tags['device']}"
119
- end
120
- if opts[:target]
121
- s.snaps = snaps[opts[:date]].map{ |s| s.id }
122
- target = opts[:target]
123
- target = open("http://169.254.169.254/latest/meta-data/instance-id").read if target == "SELF"
124
- puts "Preparing volumes for instance #{target}"
125
- s.prepare_volumes(target)
126
- # Need to clone, because trollop freeze the variable
127
- s.rattach_volumes(opts[:first_device])
128
- end
109
+ if ! opts[:date] || !snaps.has_key?(opts[:date])
110
+ puts "We have found the following snapshot's dates:"
111
+ snaps.each do |k,v|
112
+ puts "- #{k} (#{v.length} volume snapshots)"
113
+ end
114
+ else
115
+ puts "Snapshot taken at #{opts[:date]}"
116
+ snaps[opts[:date]].each do |snapshot|
117
+ puts "- #{snapshot.id}, #{snapshot.volume_size}GB - #{snapshot.tags['device']}"
118
+ end
119
+ if opts[:target]
120
+ s.snaps = snaps[opts[:date]].map{ |s| s.id }
121
+ target = opts[:target]
122
+ target = open("http://169.254.169.254/latest/meta-data/instance-id").read if target == "SELF"
123
+ puts "Preparing volumes for instance #{target}"
124
+ s.prepare_volumes(target)
125
+ # Need to clone, because trollop freeze the variable
126
+ s.rattach_volumes(opts[:first_device])
129
127
  end
130
-
131
128
  end
129
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongo-ec2-backup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: