preserve-rds-snapshot 0.3.0 → 0.3.1

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: af7578d5b6ba4324962222bf6bd9cf4644e62989
4
- data.tar.gz: 13a489abbdce7d030d46814c6580546b4392029e
3
+ metadata.gz: 81954fb5d44f1f9e831c994e02583453d74f413c
4
+ data.tar.gz: 9c4b7851629b3e1540ed11f2071b58aa8d5c8ab2
5
5
  SHA512:
6
- metadata.gz: cfdcfa7f4f7c88dbf8425130c1b1ad54e04b6edf947b46a1ff248d45402c52ba3066a943cfa671fa88da2cdad08eb9284a009e4a231d8b567d73d4faff5e41d4
7
- data.tar.gz: 767ffdf614c32684300dda5b69aa508814f099b6f3610f825f8e590e0a4cbb1b3c7d7bdcf7a74669a68dcc13aab4d0fe07f130253911f712fcea419f57a46323
6
+ metadata.gz: de72b07225b860dfb120607dfdaa9f700a2e985086f88ae72c875db49a3b8c548e06bbe5b7f8084f2b0c8266652a80e3949de15c764dc2c3679a85020694d2a8
7
+ data.tar.gz: f994b08e6b03f707663b1746c7051de638ba3fe8d87a9584ef789eac82ba3ed358fc2c5ec5c944d74ab27ae66a328768406691ad770cca1d49aaa9be8df4271e
data/README.md CHANGED
@@ -10,10 +10,12 @@ Amazon RDS create a snapshot automatically. Snapshot that is created automatical
10
10
  * copy_db_snapshot
11
11
  * delete_db_snapshots
12
12
  * list_tags_for_resources
13
+ * add_tags_to_resources
14
+ * remove_tags_from_resources
13
15
  * EC2
14
16
  * describe_security_groups
15
17
 
16
- NOTE: describe_security_groups is required to get the AWS Account Number. You can use the '--aws-account-number' option instead.
18
+ NOTE: describe_security_groups is required to get the AWS Account Number. You can use the `--aws-account-number` option instead.
17
19
 
18
20
  ## Installation
19
21
 
@@ -37,6 +39,7 @@ Or install it yourself as:
37
39
  Commands:
38
40
  preserve-rds-snapshot copy -o src -t target # copy snapshot
39
41
  preserve-rds-snapshot help [COMMAND] # Describe available commands or one specific command
42
+ preserve-rds-snapshot init # initialize instance
40
43
  preserve-rds-snapshot latest # show latest snapshot
41
44
  preserve-rds-snapshot list # Show list of RDS Snapshots
42
45
  preserve-rds-snapshot preserve # copy automated snapshot to manual
@@ -48,16 +51,25 @@ Options:
48
51
  r, [--region=REGION] # AWS region.
49
52
  [--shared-credentials-path=SHARED_CREDENTIALS_PATH] # AWS shared credentials path.
50
53
  i, [--instance=INSTANCE] # target DB Instance
51
-
52
- Options:
53
- p, [--profile=PROFILE] # Load credentials by profile name from shared credentials file.
54
- k, [--access-key-id=ACCESS_KEY_ID] # AWS access key id.
55
- s, [--secret-access-key=SECRET_ACCESS_KEY] # AWS secret access key.
56
- r, [--region=REGION] # AWS region.
57
- [--shared-credentials-path=SHARED_CREDENTIALS_PATH] # AWS shared credentials path.
58
- i, [--instance=INSTANCE] # target DB Instance
54
+ n, [--aws-account-number=AWS_ACCOUNT_NUMBER] # AWS Account Number (ex: 012345678901)
55
+ [--dry-run], [--no-dry-run] # show only, don't modify
59
56
  ```
60
57
 
58
+ ### initialize instance
59
+
60
+ ```
61
+ $ preserve-rds-snapshot init
62
+ ```
63
+
64
+ init subcommand add 'preserve-rds-snapshot' tag to RDS instance.
65
+
66
+ ### preserve snapshot
67
+
68
+ ```
69
+ $ preserve-rds-snapshot preserve
70
+ ```
71
+
72
+ preserve subcommand copy automated snapshot to manual snapshot.
61
73
 
62
74
  ## Development
63
75
 
@@ -0,0 +1,90 @@
1
+ # preserve-rds-snapshot
2
+
3
+ Amazo RDSの自動バックアップによって作成されるスナップショット(automatedスナップショット)は、インスタンスが削除されたら消えてしまうので、それを manualスナップショットにコピーして保護することを目的としたスクリプトである。
4
+
5
+ automatedスナップショットは、RDSのBackup Windowの中で作成される。cronやタスクスケジューラなどを使って、Backup Windowの後にこのスクリプトを実行すれば、常に最新のコピーを作成することができる。
6
+
7
+ ## 導入
8
+
9
+ Rubygemsのパッケージなので、gemコマンドでインストールできる。
10
+
11
+ ```
12
+ $ gem install preserve-rds-snapshot
13
+ ```
14
+
15
+ ## AWS認証情報(credentials)
16
+
17
+ AWSの認証情報は、AWS CLIと同様に使用することができる。[thor-aws](http://github.com/y13i/thor-aws)を使っているので、詳細はそちらを参照のこと。EC2上で実行するのであれば、IAM Roleが利用できる。手元の環境で実行するのであれば、--profileがおすすめ。
18
+
19
+ ## 初期化
20
+
21
+ まずは、対象となるRDSインスタンスを初期化する。
22
+
23
+ ```
24
+ $ preserve-rds-snapshot init --region ap-northeast-1 --generations 5 --instance my-rds
25
+ ```
26
+
27
+ `--instance` オプションでインスタンスを指定しなかった場合は、指定したリージョンの全てのRDSインスタンスが対象となる。その他のサブコマンドも全て同様。
28
+
29
+ `--generations` オプションは、スナップショットを残す世代数となる。 automatedスナップショットと違い、 manualスナップショットは自動的に削除されないため、新しくコピーを作成した際に、指定した世代数を超えた分のスナップショットを削除するようになっている。指定しなかった場合は10となる。
30
+
31
+ 初期化処理は、RDSインスタンスに `preserve-rds-snapshot` タグを付与する。値には指定した世代数が入る。
32
+
33
+ ## 実行
34
+
35
+ スナップショットをコピーする。
36
+
37
+ ```
38
+ $ preserve-rds-snapshot preserve --region ap-northeast-1 --instance my-rds
39
+ ```
40
+
41
+ preserveサブコマンドは、 `preserve-rds-snapshot` タグが付与されているインスタンスの、 automated スナップショットのうち、最新のスナップショットをコピーする。コピーする際には、インスタンスと同様に `preserve-rds-snapshot` タグを付与する。
42
+
43
+ コピー後、 `preserve-rds-snapshot` タグが付与されたスナップショットのうち、指定の世代数を超えた分のスナップショットを、snapshot create timeの古いものから削除する。
44
+
45
+ automatedスナップショットは、Backup Windowに合わせて毎日作成されるので、このスクリプトも、それに合わせて毎日実行される想定となっている。
46
+
47
+ ## その他
48
+
49
+ 最新のスナップショット以外を対象にしたい場合は、copyサブコマンドが使える。対象となるスナップショットを指定すれば良い。
50
+
51
+ あるスナップショットを、自動削除の対象外にしたい場合は、 `preserve-rds-snapshot` タグを削除すれば良い。
52
+
53
+ タグを生成する際に、AWSアカウント番号を使用する(対象のARNが必要となる)。そのため、EC2のセキュリティグループからAWSアカウント番号を取得している。EC2のDescribeSecurityGroups APIを実行する権限が必要となる([参考](http://muramasa64.fprog.org/diary/?date=20141208))。もし権限が付与できない場合は、`--aws-account-number` オプションを付与すること。
54
+
55
+ ### 使用する AWS API
56
+
57
+ * RDS
58
+ * describe_db_instances
59
+ * describe_db_snapshots
60
+ * copy_db_snapshot
61
+ * delete_db_snapshots
62
+ * list_tags_for_resources
63
+ * add_tags_to_resources
64
+ * remove_tags_from_resources
65
+ * EC2
66
+ * describe_security_groups
67
+
68
+ 註: describe_security_groupsはAWS Account Numberを取得するのに利用する。 `--aws-account-number` オプションに値を渡せば、describe_security_groupsの実行権限は不要。
69
+
70
+ ## コマンド一覧
71
+
72
+ ```
73
+ Commands:
74
+ preserve-rds-snapshot copy -o src -t target # copy snapshot
75
+ preserve-rds-snapshot help [COMMAND] # Describe available commands or one specific command
76
+ preserve-rds-snapshot init # initialize instance
77
+ preserve-rds-snapshot latest # show latest snapshot
78
+ preserve-rds-snapshot list # Show list of RDS Snapshots
79
+ preserve-rds-snapshot preserve # copy automated snapshot to manual
80
+
81
+ Options:
82
+ p, [--profile=PROFILE] # Load credentials by profile name from shared credentials file.
83
+ k, [--access-key-id=ACCESS_KEY_ID] # AWS access key id.
84
+ s, [--secret-access-key=SECRET_ACCESS_KEY] # AWS secret access key.
85
+ r, [--region=REGION] # AWS region.
86
+ [--shared-credentials-path=SHARED_CREDENTIALS_PATH] # AWS shared credentials path.
87
+ i, [--instance=INSTANCE] # target DB Instance
88
+ n, [--aws-account-number=AWS_ACCOUNT_NUMBER] # AWS Account Number (ex: 012345678901)
89
+ [--dry-run], [--no-dry-run] # show only, don't modify
90
+ ```
@@ -34,6 +34,7 @@ module PreserveRdsSnapshot
34
34
  end
35
35
  rescue ::Aws::Errors::ServiceError => e
36
36
  $stderr.puts e
37
+ exit 1
37
38
  end
38
39
  end
39
40
 
@@ -57,6 +58,7 @@ module PreserveRdsSnapshot
57
58
  fix_tags
58
59
  rescue ::Aws::Errors::ServiceError => e
59
60
  $stderr.puts e
61
+ exit 1
60
62
  end
61
63
  end
62
64
 
@@ -90,6 +92,7 @@ module PreserveRdsSnapshot
90
92
  end
91
93
  rescue ::Aws::Errors::ServiceError => e
92
94
  $stderr.puts e
95
+ exit 1
93
96
  end
94
97
  end
95
98
 
@@ -121,6 +124,7 @@ module PreserveRdsSnapshot
121
124
  puts "#{s.db_snapshot_identifier}\t#{s.snapshot_create_time}"
122
125
  rescue ::Aws::Errors::ServiceError => e
123
126
  $stderr.puts e
127
+ exit 1
124
128
  end
125
129
  end
126
130
 
@@ -145,6 +149,7 @@ module PreserveRdsSnapshot
145
149
  latest = resp.db_snapshots.sort_by(&:snapshot_create_time).last
146
150
  rescue ::Aws::Errors::ServiceError => e
147
151
  $stderr.puts e
152
+ exit 1
148
153
  end
149
154
  latest
150
155
  end
@@ -161,6 +166,7 @@ module PreserveRdsSnapshot
161
166
  end
162
167
  rescue ::Aws::Errors::ServiceError => e
163
168
  $stderr.puts e
169
+ exit 1
164
170
  end
165
171
  list
166
172
  end
@@ -177,6 +183,7 @@ module PreserveRdsSnapshot
177
183
  return ec2.security_groups(group_names: ['default']).first.owner_id
178
184
  rescue ::Aws::Errors::ServiceError => e
179
185
  $stderr.puts e
186
+ exit 1
180
187
  end
181
188
  end
182
189
  end
@@ -194,6 +201,7 @@ module PreserveRdsSnapshot
194
201
  tag = resp.tag_list.find {|t| t[:key] == PRESERVE_TAG_NAME}
195
202
  rescue ::Aws::Errors::ServiceError => e
196
203
  $stderr.puts e
204
+ exit 1
197
205
  end
198
206
  tag
199
207
  end
@@ -211,6 +219,7 @@ module PreserveRdsSnapshot
211
219
  end
212
220
  rescue ::Aws::Errors::ServiceError => e
213
221
  $stderr.puts e
222
+ exit 1
214
223
  end
215
224
  end
216
225
 
@@ -238,6 +247,7 @@ module PreserveRdsSnapshot
238
247
  end
239
248
  rescue ::Aws::Errors::ServiceError => e
240
249
  $stderr.puts e
250
+ exit 1
241
251
  end
242
252
  end
243
253
 
@@ -251,6 +261,7 @@ module PreserveRdsSnapshot
251
261
  return resp.db_snapshot
252
262
  rescue ::Aws::Errors::ServiceError => e
253
263
  $stderr.puts e
264
+ exit 1
254
265
  end
255
266
  end
256
267
 
@@ -267,6 +278,7 @@ module PreserveRdsSnapshot
267
278
  expired_snapshots = snapshots[generations..-1] if snapshots.size > generations
268
279
  rescue ::Aws::Errors::ServiceError => e
269
280
  $stderr.puts e
281
+ exit 1
270
282
  end
271
283
  expired_snapshots
272
284
  end
@@ -1,3 +1,3 @@
1
1
  module PreserveRdsSnapshot
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: preserve-rds-snapshot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ISOBE Kazuhiko
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-03-31 00:00:00.000000000 Z
11
+ date: 2015-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.9'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.9'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '10.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: thor-aws
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  description: Amazon RDS create a snapshot automatically. Snapshot that is created
@@ -62,11 +62,12 @@ executables:
62
62
  extensions: []
63
63
  extra_rdoc_files: []
64
64
  files:
65
- - .gitignore
65
+ - ".gitignore"
66
66
  - CODE_OF_CONDUCT.md
67
67
  - Gemfile
68
68
  - LICENSE.txt
69
69
  - README.md
70
+ - README_ja.md
70
71
  - Rakefile
71
72
  - bin/console
72
73
  - bin/setup
@@ -85,12 +86,12 @@ require_paths:
85
86
  - lib
86
87
  required_ruby_version: !ruby/object:Gem::Requirement
87
88
  requirements:
88
- - - '>='
89
+ - - ">="
89
90
  - !ruby/object:Gem::Version
90
91
  version: '0'
91
92
  required_rubygems_version: !ruby/object:Gem::Requirement
92
93
  requirements:
93
- - - '>='
94
+ - - ">="
94
95
  - !ruby/object:Gem::Version
95
96
  version: '0'
96
97
  requirements: []