amirotate 0.0.16 → 0.0.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/amirotate/client.rb +37 -0
- data/lib/amirotate/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 31f16325898481501b4e535e513bc369c67a75f8
|
4
|
+
data.tar.gz: 272b8b2581529dd70d48ec3f6de7552c090f8aeb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fcc41546e0cebc3fe5bab319b89671901bfe298f5cf4de76ef70dccae7eb9ad7238935978063b90fda601edbd57947fcc8bbed6b8dd2a7bc71459e658bf281d5
|
7
|
+
data.tar.gz: 93a9be2cc8f9781db95e180a5a57bc2272d962ed5667d620265ae9ba5acc61d60656d94ff1ab36a2cdf386bf8e429db8a8f4d16adbd6cf3d5fa5583ba5f28458
|
data/lib/amirotate/client.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require "aws-sdk"
|
2
2
|
require "time"
|
3
|
+
require "ostruct"
|
3
4
|
|
4
5
|
module AMIRotate
|
5
6
|
class Client
|
@@ -48,6 +49,7 @@ module AMIRotate
|
|
48
49
|
end
|
49
50
|
|
50
51
|
def preserve
|
52
|
+
backuped_amis = []
|
51
53
|
instances.each do |instance|
|
52
54
|
tag_key = "amirotate:#{@cli_options[:profile_name]}:retention_period"
|
53
55
|
tag = instance.tags.find {|tag| tag.key == tag_key}
|
@@ -76,6 +78,7 @@ module AMIRotate
|
|
76
78
|
].join(" - ")
|
77
79
|
)
|
78
80
|
|
81
|
+
backuped_amis << OpenStruct.new(name: name, id: image.id, tag: tag)
|
79
82
|
image.wait_until {|image| image.state.match /available|pending/}
|
80
83
|
|
81
84
|
image.create_tags(
|
@@ -97,6 +100,40 @@ module AMIRotate
|
|
97
100
|
logger.info "Did nothing due to dry run."
|
98
101
|
end
|
99
102
|
end
|
103
|
+
|
104
|
+
timeout_at = Time.now + (60 * 5)
|
105
|
+
begin
|
106
|
+
backuped_amis.each do |ami|
|
107
|
+
image = @ec2.image(ami.id)
|
108
|
+
next unless image.state.match /available/
|
109
|
+
|
110
|
+
begin
|
111
|
+
image.block_device_mappings.map do |block_device|
|
112
|
+
logger.info "Tag to snapshot #{block_device.ebs.snapshot_id}"
|
113
|
+
@ec2.snapshot(block_device.ebs.snapshot_id.to_s).create_tags(
|
114
|
+
dry_run: @cli_options[:dry_run],
|
115
|
+
tags: [
|
116
|
+
{
|
117
|
+
key: ami.tag.key,
|
118
|
+
value: ami.tag.value,
|
119
|
+
},
|
120
|
+
|
121
|
+
{
|
122
|
+
key: "Name",
|
123
|
+
value: "#{ami.name}: #{block_device.device_name}"
|
124
|
+
},
|
125
|
+
],
|
126
|
+
)
|
127
|
+
end
|
128
|
+
backuped_amis.delete(ami)
|
129
|
+
rescue Aws::EC2::Errors
|
130
|
+
next
|
131
|
+
end
|
132
|
+
end
|
133
|
+
break if backuped_amis.empty?
|
134
|
+
logger.info "To wait 1 minutes for the snapshot is created"
|
135
|
+
sleep(60)
|
136
|
+
end while Time.now < timeout_at
|
100
137
|
end
|
101
138
|
|
102
139
|
def invalidate
|
data/lib/amirotate/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: amirotate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.17
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- y13i
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -180,7 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
180
180
|
version: '0'
|
181
181
|
requirements: []
|
182
182
|
rubyforge_project:
|
183
|
-
rubygems_version: 2.4.5
|
183
|
+
rubygems_version: 2.4.5.1
|
184
184
|
signing_key:
|
185
185
|
specification_version: 4
|
186
186
|
summary: Back up EC2 instances by Snapshot/AMI.
|