preserve-rds-snapshot 0.1.1 → 0.2.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c25bbc9519804445320069fb59c8bf3fddb9df59
4
- data.tar.gz: 34bc10c94f1d1d027d37d1a7725c2b13d5fc7f62
3
+ metadata.gz: 6ac1fad7b038d2f7714ce5775f6faca3f607865d
4
+ data.tar.gz: 9c4b3e1d56a99892049df09479be7d2196a5164e
5
5
  SHA512:
6
- metadata.gz: 7e4d64db09f185fe66afd4c1185a1ad269412791076f149f3d1bb77fdeddb043b943115c3b003054f43f78baaf9ca73dd30b705259f644a71f2ea0a7e0427d7a
7
- data.tar.gz: abebffd84912f43faface2deec9161a453310e1ade211ff22104fe416b19e1dc8711039f4d2fb72e256f947b55cb52ff8e6210ec6f4970a71afc6a1d991e1e7c
6
+ metadata.gz: 8b22cbca0519b61ada69d8ec3d0a2bfe29fd1af82c869d158694a493a5f23f22a1772ec42c599e944e0870eb6972814a281e8aecd5f22db33d7cea671beeb9e8
7
+ data.tar.gz: 58ea25f44eaef6accac79fe4e6a811c9570034a362038d4464f67ef1269833b72184517bf80f1157c71a5999d9fe93e0cd361f8607d55520d3d90376da18d7df
data/README.md CHANGED
@@ -22,9 +22,11 @@ Or install it yourself as:
22
22
 
23
23
  ```
24
24
  Commands:
25
- preserve-rds-snapshot help [COMMAND] ...
26
- preserve-rds-snapshot list ...
27
- preserve-rds-snapshot preserve o, --source-db-snapshot-identifier=SOURCE_DB_SNAPSHOT_IDENTIFIER t, --target-db-snap...
25
+ preserve-rds-snapshot copy -o src -t target # copy snapshot
26
+ preserve-rds-snapshot help [COMMAND] # Describe available commands or one specific command
27
+ preserve-rds-snapshot latest # show latest snapshot
28
+ preserve-rds-snapshot list # Show list of RDS Snapshots
29
+ preserve-rds-snapshot preserve # copy automated snapshot to manual
28
30
 
29
31
  Options:
30
32
  p, [--profile=PROFILE] # Load credentials by profile name from shared credentials file.
@@ -32,6 +34,15 @@ Options:
32
34
  s, [--secret-access-key=SECRET_ACCESS_KEY] # AWS secret access key.
33
35
  r, [--region=REGION] # AWS region.
34
36
  [--shared-credentials-path=SHARED_CREDENTIALS_PATH] # AWS shared credentials path.
37
+ i, [--instance=INSTANCE] # target DB Instance
38
+
39
+ Options:
40
+ p, [--profile=PROFILE] # Load credentials by profile name from shared credentials file.
41
+ k, [--access-key-id=ACCESS_KEY_ID] # AWS access key id.
42
+ s, [--secret-access-key=SECRET_ACCESS_KEY] # AWS secret access key.
43
+ r, [--region=REGION] # AWS region.
44
+ [--shared-credentials-path=SHARED_CREDENTIALS_PATH] # AWS shared credentials path.
45
+ i, [--instance=INSTANCE] # target DB Instance
35
46
  ```
36
47
 
37
48
  ## Development
@@ -5,6 +5,11 @@ module PreserveRdsSnapshot
5
5
  class CLI < Thor
6
6
  include Thor::Aws
7
7
 
8
+ class_option :instance,
9
+ aliases: [:i],
10
+ type: :string,
11
+ desc: 'target DB Instance'
12
+
8
13
  desc :list, 'Show list of RDS Snapshots'
9
14
  option :snapshot_type,
10
15
  aliases: [:t],
@@ -13,7 +18,8 @@ module PreserveRdsSnapshot
13
18
  def list
14
19
  begin
15
20
  resp = rds.client.describe_db_snapshots(
16
- snapshot_type: options[:snapshot_type]
21
+ snapshot_type: options[:snapshot_type],
22
+ db_instance_identifier: options[:instance]
17
23
  )
18
24
  resp.db_snapshots.each do |s|
19
25
  puts "#{s.db_snapshot_identifier}\t#{s.snapshot_create_time}"
@@ -24,6 +30,28 @@ module PreserveRdsSnapshot
24
30
  end
25
31
 
26
32
  desc :preserve, 'copy automated snapshot to manual'
33
+ def preserve
34
+ begin
35
+ instances = db_instances(options[:instance])
36
+ instances.each do |i|
37
+ latest = latest_auto_snapshot(i.db_instance_identifier)
38
+ if latest
39
+ db_snapshot_identifier = latest.db_snapshot_identifier
40
+ resp = rds.client.copy_db_snapshot(
41
+ source_db_snapshot_identifier: db_snapshot_identifier,
42
+ target_db_snapshot_identifier: preserve_snapshot_name(db_snapshot_identifier),
43
+ tags: [key: 'type', value: 'preserve']
44
+ )
45
+ s = resp.db_snapshot
46
+ puts "#{s.db_snapshot_identifier}\t#{s.snapshot_create_time}"
47
+ end
48
+ end
49
+ rescue ::Aws::Errors::ServiceError => e
50
+ $stderr.puts e
51
+ end
52
+ end
53
+
54
+ desc :copy, 'copy snapshot'
27
55
  option :source_db_snapshot_identifier,
28
56
  aliases: [:o],
29
57
  type: :string,
@@ -34,7 +62,7 @@ module PreserveRdsSnapshot
34
62
  type: :string,
35
63
  desc: 'target snapshot identifier',
36
64
  required: true
37
- def preserve
65
+ def copy
38
66
  begin
39
67
  resp = rds.client.copy_db_snapshot(
40
68
  source_db_snapshot_identifier: options[:source_db_snapshot_identifier],
@@ -47,5 +75,47 @@ module PreserveRdsSnapshot
47
75
  $stderr.puts e
48
76
  end
49
77
  end
78
+
79
+ desc :latest, 'show latest snapshot'
80
+ def latest
81
+ instances = db_instances(options[:instance])
82
+ instances.each do |instance|
83
+ s = latest_auto_snapshot(instance.db_instance_identifier)
84
+ puts "#{s.db_snapshot_identifier}\t#{s.snapshot_create_time}" if s
85
+ end
86
+ end
87
+
88
+ private
89
+
90
+ def latest_auto_snapshot(db_instance_identifier = nil)
91
+ latest = nil
92
+ begin
93
+ resp = rds.client.describe_db_snapshots(
94
+ snapshot_type: 'automated',
95
+ db_instance_identifier: db_instance_identifier
96
+ )
97
+ latest = resp.db_snapshots.sort_by(&:snapshot_create_time).last
98
+ rescue ::Aws::Errors::ServiceError => e
99
+ $stderr.puts e
100
+ end
101
+ latest
102
+ end
103
+
104
+ def db_instances(db_instance_identifier = nil)
105
+ list = []
106
+ begin
107
+ if db_instance_identifier
108
+ list << rds.db_instance(db_instance_identifier)
109
+ else
110
+ list = rds.db_instances.to_a
111
+ end
112
+ rescue ::Aws::Errors::ServiceError => e
113
+ $stderr.puts e
114
+ end
115
+ end
116
+
117
+ def preserve_snapshot_name(db_snapshot_identifier)
118
+ 'preserve-' + db_snapshot_identifier.gsub(/^rds:/, '')
119
+ end
50
120
  end
51
121
  end
@@ -1,3 +1,3 @@
1
1
  module PreserveRdsSnapshot
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: preserve-rds-snapshot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ISOBE Kazuhiko