rds-rotate-db-snapshots 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/Gemfile +2 -2
- data/Rakefile +5 -5
- data/VERSION +1 -1
- data/bin/rds-rotate-db-snapshots +41 -19
- data/lib/.empty +1 -1
- data/rds-rotate-db-snapshots.gemspec +26 -31
- metadata +22 -29
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
OGZmNTJiNGJmMTNiOWM4OGRmMTkwNjkzNjg2ZWJlNDZlYjdhZGU0NA==
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 89f6c03c428ea666793c1a5b1f8c73f9667466db382e4f69358aff1dee3026a1
|
4
|
+
data.tar.gz: 1a2ef773c19beeaefe8f393d26e97c4e1eb022288268f8881280978ad2ada7d6
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
OTE5OTIzMDU1YzhjMWYzMWZkN2ZiNjM3OWEwNWEwYWNkNGY4YjZmMDFhZDVi
|
11
|
-
YzkzYTZjMDE0NjVjN2RiOTJmMWM2OGQ4ZjcxZDFmYTJkMmZjY2M=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
YzgzZWRiMjA0OTM0OTdiNTAzNmJhMDIyNDJkMzQzMWQ2YzM5MDk4YWMwZmVm
|
14
|
-
OTk2MTA5OTVkNDQ0ZDQxZWExYmJiOTZkNDZlNGI3MjUzOWUyMzU3OWMxOWIz
|
15
|
-
ZTJkNGZkY2IxZmE4ZjRjM2FiZmRjY2VhMzc1ZWIwZWIxZTk5ZDE=
|
6
|
+
metadata.gz: 860abf62c29df38f7028c6466992af8c150217b9f0b5502343c895cb8620857ff8871795cccc3120d5ea226220dc897b8607652cf5f20c972e15306a1d25ecc3
|
7
|
+
data.tar.gz: c2d7fde7e855cbbc9fbd45edf7f935cfa4d310c6677ab9b0171b48840690ecee6ccca3af753c81fbae93ca425ef3d2df611c1323e953da14fd5bc57b835087d7
|
data/Gemfile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
source "http://rubygems.org"
|
2
2
|
|
3
|
-
gem 'aws-sdk', '
|
3
|
+
gem 'aws-sdk-rds', '~> 1'
|
4
4
|
|
5
5
|
# Add dependencies to develop your gem here.
|
6
6
|
# Include everything needed to run rake, tests, features, etc.
|
@@ -10,7 +10,7 @@ group :development, :test do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
group :development do
|
13
|
-
gem '
|
13
|
+
gem 'juwelier'
|
14
14
|
end
|
15
15
|
|
16
16
|
group :test do
|
data/Rakefile
CHANGED
@@ -9,9 +9,8 @@ rescue Bundler::BundlerError => e
|
|
9
9
|
end
|
10
10
|
require 'rake'
|
11
11
|
|
12
|
-
require '
|
13
|
-
|
14
|
-
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
12
|
+
require 'juwelier'
|
13
|
+
Juwelier::Tasks.new do |gem|
|
15
14
|
gem.name = "rds-rotate-db-snapshots"
|
16
15
|
gem.homepage = "http://github.com/serg-kovalev/rds-rotate-db-snapshots"
|
17
16
|
gem.license = "MIT"
|
@@ -19,8 +18,9 @@ Jeweler::Tasks.new do |gem|
|
|
19
18
|
gem.description = %Q{Provides a simple way to rotate RDS DB snapshots with configurable retention periods.}
|
20
19
|
gem.email = "kovserg@gmail.com"
|
21
20
|
gem.authors = ["Siarhei Kavaliou"]
|
21
|
+
gem.version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
22
22
|
end
|
23
|
-
|
23
|
+
Juwelier::RubygemsDotOrgTasks.new
|
24
24
|
|
25
25
|
require 'rake/testtask'
|
26
26
|
Rake::TestTask.new(:test) do |test|
|
@@ -28,7 +28,7 @@ Rake::TestTask.new(:test) do |test|
|
|
28
28
|
test.verbose = true
|
29
29
|
end
|
30
30
|
|
31
|
-
require 'simplecov'
|
31
|
+
# require 'simplecov'
|
32
32
|
# Rcov::RcovTask.new do |test|
|
33
33
|
# test.libs << 'test'
|
34
34
|
# test.pattern = 'test/**/test_*.rb'
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.0
|
data/bin/rds-rotate-db-snapshots
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require 'rubygems'
|
4
|
-
require 'aws-sdk'
|
4
|
+
require 'aws-sdk-rds'
|
5
5
|
require 'optparse'
|
6
6
|
|
7
7
|
$opts = {
|
8
8
|
:aws_access_key => ENV["AWS_ACCESS_KEY_ID"],
|
9
9
|
:aws_secret_access_key => ENV["AWS_SECRET_ACCESS_KEY"],
|
10
|
+
:aws_session_token => ENV["AWS_SESSION_TOKEN"],
|
10
11
|
:aws_region => ENV["AWS_REGION"],
|
11
12
|
:pattern => nil,
|
12
13
|
:by_tags => nil,
|
@@ -38,24 +39,24 @@ end
|
|
38
39
|
def rotate_em(snapshots)
|
39
40
|
# poor man's way to get a deep copy of our time_periods definition hash
|
40
41
|
periods = Marshal.load(Marshal.dump($time_periods))
|
41
|
-
|
42
|
+
|
42
43
|
snapshots.each do |snapshot|
|
43
44
|
time = snapshot[:snapshot_create_time]
|
44
45
|
db_id = snapshot[:db_instance_identifier]
|
45
46
|
snapshot_id = snapshot[:db_snapshot_identifier]
|
46
47
|
description = snapshot_id
|
47
48
|
keep_reason = nil
|
48
|
-
|
49
|
+
|
49
50
|
if $opts[:pattern] && description !~ /#{$opts[:pattern]}/
|
50
51
|
puts " #{time.strftime '%Y-%m-%d %H:%M:%S'} #{snapshot_id} Skipping snapshot with description #{description}"
|
51
52
|
next
|
52
53
|
end
|
53
|
-
|
54
|
+
|
54
55
|
periods.keys.sort { |a, b| periods[a][:seconds] <=> periods[b][:seconds] }.each do |period|
|
55
56
|
period_info = periods[period]
|
56
57
|
keep = period_info[:keep]
|
57
58
|
keeping = period_info[:keeping]
|
58
|
-
|
59
|
+
|
59
60
|
time_string = time.strftime period_info[:format]
|
60
61
|
if Time.now - time < keep * period_info[:seconds]
|
61
62
|
if !keeping.key?(time_string) && keeping.length < keep
|
@@ -65,18 +66,18 @@ def rotate_em(snapshots)
|
|
65
66
|
break
|
66
67
|
end
|
67
68
|
end
|
68
|
-
|
69
|
+
|
69
70
|
if keep_reason.nil? && snapshot == snapshots.last && $opts[:keep_last]
|
70
71
|
keep_reason = 'last snapshot'
|
71
72
|
end
|
72
|
-
|
73
|
+
|
73
74
|
if !keep_reason.nil?
|
74
75
|
puts " #{time.strftime '%Y-%m-%d %H:%M:%S'} #{snapshot_id} Keeping for #{keep_reason}"
|
75
76
|
else
|
76
77
|
puts " #{time.strftime '%Y-%m-%d %H:%M:%S'} #{snapshot_id} Deleting"
|
77
78
|
begin
|
78
79
|
$rds.delete_db_snapshot(db_snapshot_identifier: snapshot_id) unless $opts[:dry_run]
|
79
|
-
rescue
|
80
|
+
rescue Aws::RDS::Errors => e
|
80
81
|
backoff()
|
81
82
|
retry
|
82
83
|
end
|
@@ -93,7 +94,7 @@ def create_snapshot(name, db_indentifier_ids)
|
|
93
94
|
begin
|
94
95
|
$rds.create_db_snapshot(db_snapshot_identifier: name, db_instance_identifier: db_id) unless $opts[:dry_run]
|
95
96
|
puts " #{Time.now.strftime '%Y-%m-%d %H:%M:%S'} Creation snapshot #{name} is pending (db: #{db_id})"
|
96
|
-
rescue
|
97
|
+
rescue Aws::RDS::Errors::InvalidDBInstanceStateFault => e
|
97
98
|
backoff()
|
98
99
|
retry
|
99
100
|
end
|
@@ -116,6 +117,18 @@ def split_tag(hash,v)
|
|
116
117
|
end
|
117
118
|
end
|
118
119
|
|
120
|
+
def get_db_snapshots(options)
|
121
|
+
snapshots = []
|
122
|
+
response = $rds.describe_db_snapshots(options)
|
123
|
+
while true do
|
124
|
+
snapshots += response.db_snapshots
|
125
|
+
break unless response[:marker]
|
126
|
+
|
127
|
+
response = $rds.describe_db_snapshots(options.merge(marker: response[:marker]))
|
128
|
+
end
|
129
|
+
snapshots
|
130
|
+
end
|
131
|
+
|
119
132
|
OptionParser.new do |o|
|
120
133
|
script_name = File.basename($0)
|
121
134
|
o.banner = "Usage: #{script_name} [options] <db_indentifier>\nUsage: #{script_name} --by-tags <tag=value,...> [other options]"
|
@@ -133,6 +146,10 @@ OptionParser.new do |o|
|
|
133
146
|
$opts[:aws_region] = v
|
134
147
|
end
|
135
148
|
|
149
|
+
o.on("--aws-session-token SESSION_TOKEN", "AWS session token") do |v|
|
150
|
+
$opts[:aws_session_token] = v
|
151
|
+
end
|
152
|
+
|
136
153
|
o.on("--pattern STRING", "Snapshots without this string in the description will be ignored") do |v|
|
137
154
|
$opts[:pattern] = v
|
138
155
|
end
|
@@ -204,9 +221,14 @@ end
|
|
204
221
|
|
205
222
|
$backoffed = 0
|
206
223
|
begin
|
207
|
-
|
208
|
-
|
209
|
-
|
224
|
+
Aws.config.update(
|
225
|
+
access_key_id: $opts[:aws_access_key],
|
226
|
+
secret_access_key: $opts[:aws_secret_access_key],
|
227
|
+
region: $opts[:aws_region],
|
228
|
+
session_token: $opts[:aws_session_token]
|
229
|
+
)
|
230
|
+
$rds = Aws::RDS::Client.new
|
231
|
+
rescue Aws::RDS::Errors => e
|
210
232
|
backoff()
|
211
233
|
retry
|
212
234
|
end
|
@@ -221,7 +243,7 @@ if $opts[:by_tags]
|
|
221
243
|
begin
|
222
244
|
these_snapshots = $rds.describe_tags(snapshot_type: 'manual', filters: {'resource-type'=>"snapshot", 'key'=>tag, 'value'=>value}).
|
223
245
|
delete_if{ |e| e.status != 'available' }
|
224
|
-
rescue
|
246
|
+
rescue Aws::RDS::Errors => e
|
225
247
|
backoff()
|
226
248
|
retry
|
227
249
|
end
|
@@ -242,10 +264,10 @@ if $opts[:by_tags]
|
|
242
264
|
end
|
243
265
|
|
244
266
|
begin
|
245
|
-
rotate_these =
|
246
|
-
|
267
|
+
rotate_these = get_db_snapshots(db_instance_identifier: all_snapshots.map(&:db_instance_identifier).uniq).
|
268
|
+
delete_if{ |e| !all_snapshots.include?(e.db_snapshot_identifier) }.
|
247
269
|
sort {|a,b| a[:snapshot_create_time] <=> b[:snapshot_create_time] }
|
248
|
-
rescue
|
270
|
+
rescue Aws::RDS::Errors => e
|
249
271
|
backoff()
|
250
272
|
retry
|
251
273
|
end
|
@@ -253,9 +275,9 @@ if $opts[:by_tags]
|
|
253
275
|
rotate_em(rotate_these)
|
254
276
|
else
|
255
277
|
begin
|
256
|
-
all_snapshots =
|
257
|
-
delete_if{ |e| e
|
258
|
-
rescue
|
278
|
+
all_snapshots = get_db_snapshots(snapshot_type: 'manual').
|
279
|
+
delete_if{ |e| e[:status] != 'available' }
|
280
|
+
rescue Aws::RDS::Errors => e
|
259
281
|
backoff()
|
260
282
|
retry
|
261
283
|
end
|
data/lib/.empty
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
Juwelier doesn't like me not having a lib/ directory.
|
@@ -1,20 +1,20 @@
|
|
1
|
-
# Generated by
|
1
|
+
# Generated by juwelier
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit
|
3
|
+
# Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: rds-rotate-db-snapshots 0.
|
5
|
+
# stub: rds-rotate-db-snapshots 0.4.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
|
-
s.name = "rds-rotate-db-snapshots"
|
9
|
-
s.version = "0.
|
8
|
+
s.name = "rds-rotate-db-snapshots".freeze
|
9
|
+
s.version = "0.4.0"
|
10
10
|
|
11
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
|
-
s.require_paths = ["lib"]
|
13
|
-
s.authors = ["Siarhei Kavaliou"]
|
14
|
-
s.date = "
|
15
|
-
s.description = "Provides a simple way to rotate RDS DB snapshots with configurable retention periods."
|
16
|
-
s.email = "kovserg@gmail.com"
|
17
|
-
s.executables = ["rds-rotate-db-snapshots"]
|
11
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
12
|
+
s.require_paths = ["lib".freeze]
|
13
|
+
s.authors = ["Siarhei Kavaliou".freeze]
|
14
|
+
s.date = "2022-12-24"
|
15
|
+
s.description = "Provides a simple way to rotate RDS DB snapshots with configurable retention periods.".freeze
|
16
|
+
s.email = "kovserg@gmail.com".freeze
|
17
|
+
s.executables = ["rds-rotate-db-snapshots".freeze]
|
18
18
|
s.extra_rdoc_files = [
|
19
19
|
"LICENSE.txt",
|
20
20
|
"README.rdoc"
|
@@ -33,30 +33,25 @@ Gem::Specification.new do |s|
|
|
33
33
|
"test/helper.rb",
|
34
34
|
"test/test_rds-rotate-db-snapshots.rb"
|
35
35
|
]
|
36
|
-
s.homepage = "http://github.com/serg-kovalev/rds-rotate-db-snapshots"
|
37
|
-
s.licenses = ["MIT"]
|
38
|
-
s.rubygems_version = "
|
39
|
-
s.summary = "Amazon RDS DB snapshot rotator"
|
36
|
+
s.homepage = "http://github.com/serg-kovalev/rds-rotate-db-snapshots".freeze
|
37
|
+
s.licenses = ["MIT".freeze]
|
38
|
+
s.rubygems_version = "3.3.7".freeze
|
39
|
+
s.summary = "Amazon RDS DB snapshot rotator".freeze
|
40
40
|
|
41
41
|
if s.respond_to? :specification_version then
|
42
42
|
s.specification_version = 4
|
43
|
+
end
|
43
44
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
else
|
50
|
-
s.add_dependency(%q<aws-sdk>, ["< 2.0", ">= 1.51.0"])
|
51
|
-
s.add_dependency(%q<bundler>, [">= 0"])
|
52
|
-
s.add_dependency(%q<simplecov>, [">= 0"])
|
53
|
-
s.add_dependency(%q<jeweler>, [">= 0"])
|
54
|
-
end
|
45
|
+
if s.respond_to? :add_runtime_dependency then
|
46
|
+
s.add_runtime_dependency(%q<aws-sdk-rds>.freeze, ["~> 1"])
|
47
|
+
s.add_development_dependency(%q<bundler>.freeze, [">= 0"])
|
48
|
+
s.add_development_dependency(%q<simplecov>.freeze, [">= 0"])
|
49
|
+
s.add_development_dependency(%q<juwelier>.freeze, [">= 0"])
|
55
50
|
else
|
56
|
-
s.add_dependency(%q<aws-sdk
|
57
|
-
s.add_dependency(%q<bundler
|
58
|
-
s.add_dependency(%q<simplecov
|
59
|
-
s.add_dependency(%q<
|
51
|
+
s.add_dependency(%q<aws-sdk-rds>.freeze, ["~> 1"])
|
52
|
+
s.add_dependency(%q<bundler>.freeze, [">= 0"])
|
53
|
+
s.add_dependency(%q<simplecov>.freeze, [">= 0"])
|
54
|
+
s.add_dependency(%q<juwelier>.freeze, [">= 0"])
|
60
55
|
end
|
61
56
|
end
|
62
57
|
|
metadata
CHANGED
@@ -1,75 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rds-rotate-db-snapshots
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Siarhei Kavaliou
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-12-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name: aws-sdk
|
14
|
+
name: aws-sdk-rds
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
20
|
-
- - ! '>='
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: 1.51.0
|
19
|
+
version: '1'
|
23
20
|
type: :runtime
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
26
23
|
requirements:
|
27
|
-
- -
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: '2.0'
|
30
|
-
- - ! '>='
|
24
|
+
- - "~>"
|
31
25
|
- !ruby/object:Gem::Version
|
32
|
-
version: 1
|
26
|
+
version: '1'
|
33
27
|
- !ruby/object:Gem::Dependency
|
34
28
|
name: bundler
|
35
29
|
requirement: !ruby/object:Gem::Requirement
|
36
30
|
requirements:
|
37
|
-
- -
|
31
|
+
- - ">="
|
38
32
|
- !ruby/object:Gem::Version
|
39
33
|
version: '0'
|
40
34
|
type: :development
|
41
35
|
prerelease: false
|
42
36
|
version_requirements: !ruby/object:Gem::Requirement
|
43
37
|
requirements:
|
44
|
-
- -
|
38
|
+
- - ">="
|
45
39
|
- !ruby/object:Gem::Version
|
46
40
|
version: '0'
|
47
41
|
- !ruby/object:Gem::Dependency
|
48
42
|
name: simplecov
|
49
43
|
requirement: !ruby/object:Gem::Requirement
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - ">="
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0'
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
51
|
requirements:
|
58
|
-
- -
|
52
|
+
- - ">="
|
59
53
|
- !ruby/object:Gem::Version
|
60
54
|
version: '0'
|
61
55
|
- !ruby/object:Gem::Dependency
|
62
|
-
name:
|
56
|
+
name: juwelier
|
63
57
|
requirement: !ruby/object:Gem::Requirement
|
64
58
|
requirements:
|
65
|
-
- -
|
59
|
+
- - ">="
|
66
60
|
- !ruby/object:Gem::Version
|
67
61
|
version: '0'
|
68
62
|
type: :development
|
69
63
|
prerelease: false
|
70
64
|
version_requirements: !ruby/object:Gem::Requirement
|
71
65
|
requirements:
|
72
|
-
- -
|
66
|
+
- - ">="
|
73
67
|
- !ruby/object:Gem::Version
|
74
68
|
version: '0'
|
75
69
|
description: Provides a simple way to rotate RDS DB snapshots with configurable retention
|
@@ -82,8 +76,8 @@ extra_rdoc_files:
|
|
82
76
|
- LICENSE.txt
|
83
77
|
- README.rdoc
|
84
78
|
files:
|
85
|
-
- .document
|
86
|
-
- .travis.yml
|
79
|
+
- ".document"
|
80
|
+
- ".travis.yml"
|
87
81
|
- Gemfile
|
88
82
|
- LICENSE.txt
|
89
83
|
- README.rdoc
|
@@ -98,24 +92,23 @@ homepage: http://github.com/serg-kovalev/rds-rotate-db-snapshots
|
|
98
92
|
licenses:
|
99
93
|
- MIT
|
100
94
|
metadata: {}
|
101
|
-
post_install_message:
|
95
|
+
post_install_message:
|
102
96
|
rdoc_options: []
|
103
97
|
require_paths:
|
104
98
|
- lib
|
105
99
|
required_ruby_version: !ruby/object:Gem::Requirement
|
106
100
|
requirements:
|
107
|
-
- -
|
101
|
+
- - ">="
|
108
102
|
- !ruby/object:Gem::Version
|
109
103
|
version: '0'
|
110
104
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
105
|
requirements:
|
112
|
-
- -
|
106
|
+
- - ">="
|
113
107
|
- !ruby/object:Gem::Version
|
114
108
|
version: '0'
|
115
109
|
requirements: []
|
116
|
-
|
117
|
-
|
118
|
-
signing_key:
|
110
|
+
rubygems_version: 3.3.7
|
111
|
+
signing_key:
|
119
112
|
specification_version: 4
|
120
113
|
summary: Amazon RDS DB snapshot rotator
|
121
114
|
test_files: []
|