mongo-ec2-backup 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +1 -1
- data/bin/ec2_snapshot_restorer +37 -39
- metadata +1 -1
data/Rakefile
CHANGED
data/bin/ec2_snapshot_restorer
CHANGED
@@ -86,46 +86,44 @@ class SnapshotRestorer
|
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
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
|
-
|
108
|
-
|
106
|
+
# Find this instance snapshots
|
107
|
+
snaps = s.find_snapshots(instance_identifier, opts[:type])
|
109
108
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
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
|
+
|