ebs_snapper 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,3 +5,4 @@ aws:
5
5
  volume_tag : 'Snapper' # tag to use in AWS for the EBS backup flags
6
6
  retain : '10.days'
7
7
  log_to: '/var/log/ebs_snapper.log'
8
+ pause_time: 1
@@ -54,6 +54,7 @@ class EbsSnapper::CLI
54
54
  options[:verbose] = false
55
55
  options[:out] = ''
56
56
  options[:config] = nil
57
+ options[:pause_time] = 1
57
58
 
58
59
  opts = OptionParser.new do |opts|
59
60
  opts.banner = "Usage: ebs_snapper [options]"
@@ -17,6 +17,7 @@ require 'aws-sdk'
17
17
  class EbsSnapper::Ebs
18
18
 
19
19
  DEFAULT_TAG_NAME = 'Snapper'
20
+ DEFAULT_PAUSE_TIME = 0
20
21
 
21
22
  def initialize(opts = {})
22
23
  if !opts[:secret_access_key].nil? && !opts[:access_key_id].nil?
@@ -27,6 +28,7 @@ class EbsSnapper::Ebs
27
28
  @logger = opts[:logger] || Logger.new(STDOUT)
28
29
  @retain = opts[:retain]
29
30
  @tag_name = opts[:volume_tag] || DEFAULT_TAG_NAME # default
31
+ PausingEnumerable.pause_time = opts[:pause_time] || DEFAULT_PAUSE_TIME
30
32
  end
31
33
 
32
34
  def snapshot_and_purge
@@ -41,7 +43,8 @@ class EbsSnapper::Ebs
41
43
  volumes = []
42
44
 
43
45
  each_region do |r|
44
- r.tags.filter('resource-type', 'volume').filter('key', @tag_name).each do |tag|
46
+ tags = r.tags.filter('resource-type', 'volume').filter('key', @tag_name)
47
+ PausingEnumerable.wrap(tags).each do |tag|
45
48
  # if the tag exists, it's using the default retention (TTL)
46
49
  ttl_value = @retain
47
50
  if tag.value != nil && !tag.value.strip.empty?
@@ -72,14 +75,14 @@ class EbsSnapper::Ebs
72
75
  end
73
76
 
74
77
  def purge_old_snapshots(ttl, region, vol_id)
75
- region.snapshots.filter('volume-id', vol_id).filter('tag-key', @tag_name).each do |snapshot|
78
+ snapshots = region.snapshots.filter('volume-id', vol_id).filter('tag-key', @tag_name)
79
+ PausingEnumerable.wrap(snapshots).each do |snapshot|
76
80
  unless snapshot.status == :pending
77
81
  ts = snapshot.tags[@tag_name]
78
82
  if ttl.purge?(ts)
79
83
  @logger.info {"Purging #{vol_id} snapshot: #{snapshot.id}"}
80
84
  begin
81
85
  snapshot.delete
82
- sleep 1 # we need to slow down our processing..
83
86
  rescue => e
84
87
  @logger.error "Exception: #{e}\n" + e.backtrace().join("\n")
85
88
  end
@@ -87,8 +90,37 @@ class EbsSnapper::Ebs
87
90
  end
88
91
  end
89
92
  end
90
-
91
-
93
+
94
+ module PausingEnumerable
95
+
96
+ def self.pause_time=(time)
97
+ @pause_time = time
98
+ end
99
+
100
+ def self.pause_time
101
+ @pause_time || EbsSnapper::Ebs::DEFAULT_PAUSE_TIME
102
+ end
103
+
104
+ def self.included(base)
105
+ base.class_eval do
106
+ if !method_defined?(:orig_each)
107
+ alias_method :orig_each, :each
108
+ def each(&block)
109
+ orig_each(&block)
110
+ sleep PausingEnumerable.pause_time # we need to slow down our processing..
111
+ end
112
+ end
113
+ end
114
+ end
115
+
116
+ def self.wrap(enumerable)
117
+ enumerable.class.module_eval do
118
+ include PausingEnumerable
119
+ end
120
+ enumerable
121
+ end
122
+ end
123
+
92
124
  def each_region
93
125
  ec2.regions.each do |region|
94
126
  yield (region)
@@ -13,5 +13,5 @@
13
13
  # limitations under the License.
14
14
 
15
15
  module EbsSnapper
16
- VERSION = "0.0.7"
16
+ VERSION = "0.0.8"
17
17
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ebs_snapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-01-03 00:00:00.000000000 Z
12
+ date: 2014-01-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: aws-sdk
@@ -111,7 +111,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
111
111
  version: '0'
112
112
  segments:
113
113
  - 0
114
- hash: 1005220110206046927
114
+ hash: 529299969700256006
115
115
  required_rubygems_version: !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
@@ -120,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
120
  version: '0'
121
121
  segments:
122
122
  - 0
123
- hash: 1005220110206046927
123
+ hash: 529299969700256006
124
124
  requirements: []
125
125
  rubyforge_project:
126
126
  rubygems_version: 1.8.24