elasticsearch_s3_backup 2.0.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 873b7e21f3194143c4dd273e4322343a0f9f6344
4
- data.tar.gz: e25e7eaa0608847db2fe70fe45e87a7aea16df2e
3
+ metadata.gz: 081728682c1244d2281ea3eb51fcd4bbf77e3c38
4
+ data.tar.gz: b25a45c8f558abc41a53d77cb50f62c2192ada16
5
5
  SHA512:
6
- metadata.gz: d33d3cef2877c0a0247fde1616da0c4aa87fdd7c6c1298f25a10fc46aef8d6f34d73b42cb2403fb0fd103547b405fd985ff4563807d6ba4b68eebd319351e5f0
7
- data.tar.gz: 5d38407897c26c38abe0b4734cf4f32c44bc7a1b35b1c2db7ced2911fc58a6111e944c1467c29b0c9772156f9f637220e38256820a1d7311f13721921cdce1ef
6
+ metadata.gz: ae09000b630cc92a3762906230c1bf5d0e2a1bd9c05219d36975f24b26656f6be0b472f022b97de8ff91bf8eae94dc0cd530c3b7bf2735fae38fef62e35b295f
7
+ data.tar.gz: 22bccb3af01e88c01f6641a99a59ffa23b3e16d812935f0d0ee9e20491ec70dd283f00f535bcd1fbf5d95dd3e132b71f22c1fecf184915f194b9ac3ae11d14c1
@@ -23,6 +23,45 @@ module EverTools
23
23
 
24
24
  attr_reader :conf, :backup_repo, :snapshot_label
25
25
 
26
+ # rubocop:disable Metrics/AbcSize, Lint/RescueException
27
+ def run
28
+ unless master?
29
+ logger.info 'This node is not the currently elected master. Exiting.'
30
+ exit
31
+ end
32
+
33
+ cleanup_test_indexes
34
+ insert_test_data
35
+
36
+ # Create a new repo if none exists (typically at beginning of month)
37
+ create_repo unless es_api.snapshot.get_repository[backup_repo]
38
+ create_snapshot
39
+
40
+ restore_test_index
41
+ # Compare each doc in the original backup_test index to the restored index
42
+ logger.info "Verifying the newly-restored #{@backup_test_index}…"
43
+ test_size.times { |i| compare_index_item! i }
44
+ logger.info 'Successfully verified the test data!'
45
+ delete_test_indexes
46
+
47
+ remove_expired_backups
48
+ logger.info 'Finished'
49
+ rescue Interrupt => e
50
+ puts "Received #{e.class}"
51
+ exit 99
52
+ rescue SignalException => e
53
+ logger.info "Received: #{e.signm} (#{e.signo})"
54
+ exit 2
55
+ rescue SystemExit => e
56
+ exit e.status
57
+ rescue Exception => e # Need to rescue "Exception" so that Sentry gets it
58
+ notify e
59
+ logger.fatal e.message
60
+ logger.fatal e.backtrace.join("\n")
61
+ raise e
62
+ end
63
+ # rubocop:enable Metrics/AbcSize, Lint/RescueException
64
+
26
65
  def initialize
27
66
  @conf = OpenStruct.new(YAML.load_file('/etc/s3_backup.yml'))
28
67
 
@@ -40,6 +79,8 @@ module EverTools
40
79
  @snapshot_label = now.strftime '%m-%d_%H%M'
41
80
  end
42
81
 
82
+ private
83
+
43
84
  def logger
44
85
  @logger ||= Logger.new(conf['log']).tap { |l| l.progname = 's3_backup' }
45
86
  end
@@ -139,7 +180,7 @@ module EverTools
139
180
 
140
181
  def restore_test_index
141
182
  # Restore just the backup_test index to a new index
142
- logger.info 'Restoring the backup_test index…'
183
+ logger.info "Restoring the #{@backup_test_index} index to #{@restore_test_index}"
143
184
  es_api.snapshot.restore repository: backup_repo,
144
185
  snapshot: snapshot_label,
145
186
  wait_for_completion: true,
@@ -165,57 +206,18 @@ module EverTools
165
206
  end
166
207
 
167
208
  def delete_test_indexes
168
- tries ||= 1
169
209
  [@restore_test_index, @backup_test_index].each do |test_index|
170
210
  es_api.indices.delete index: test_index
171
211
  end
172
212
  end
173
213
 
174
214
  def cleanup_test_indexes
175
- logger.info "Removing remnant test indexes..."
215
+ logger.info 'Removing remnant test indexes...'
176
216
  # Gather backup test indices
177
- es_api.indices.get(index: 'backup_test_*').each do |test_index, value|
217
+ es_api.indices.get(index: 'backup_test_*').each do |test_index, _value|
178
218
  # Check again that they are backup test indices
179
219
  es_api.indices.delete index: test_index if test_index =~ /backup_test_(.*)/
180
220
  end
181
221
  end
182
-
183
- # rubocop:disable Metrics/AbcSize, Lint/RescueException
184
- def run
185
- unless master?
186
- logger.info 'This node is not the currently elected master. Exiting.'
187
- exit
188
- end
189
-
190
- cleanup_test_indexes
191
- insert_test_data
192
-
193
- # Create a new repo if none exists (typically at beginning of month)
194
- create_repo unless es_api.snapshot.get_repository[backup_repo]
195
- create_snapshot
196
- restore_test_index
197
- # Compare each doc in the original backup_test index to the restored index
198
- logger.info "Verifying the newly-restored #{@backup_test_index}…"
199
- test_size.times { |i| compare_index_item! i }
200
- logger.info 'Successfully verified the test data!'
201
- delete_test_indexes
202
-
203
- remove_expired_backups
204
- logger.info 'Finished'
205
- rescue Interrupt => e
206
- puts "Received #{e.class}"
207
- exit 99
208
- rescue SignalException => e
209
- logger.info "Received: #{e.signm} (#{e.signo})"
210
- exit 2
211
- rescue SystemExit => e
212
- exit e.status
213
- rescue Exception => e # Need to rescue "Exception" so that Sentry gets it
214
- notify e
215
- logger.fatal e.message
216
- logger.fatal e.backtrace.join("\n")
217
- raise e
218
- end
219
- # rubocop:enable Metrics/AbcSize, Lint/RescueException
220
222
  end
221
223
  end
@@ -1,5 +1,5 @@
1
1
  module EverTools
2
2
  class ElasticsearchS3Backup
3
- VERSION = '2.0.1'
3
+ VERSION = '2.0.2'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elasticsearch_s3_backup
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Herot
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-10-28 00:00:00.000000000 Z
11
+ date: 2016-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler