ll-innobackup 0.1.18 → 0.1.23

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.
Files changed (3) hide show
  1. checksums.yaml +5 -5
  2. data/lib/ll-innobackup.rb +37 -13
  3. metadata +20 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: d09c40ad1250fc616aee53e4d78cf9e5bc5efdc6
4
- data.tar.gz: d02829f2bfcbabbd365e8a914c22ad98fc5fa950
2
+ SHA256:
3
+ metadata.gz: fd27a56519f0cdd13a91e939f23e72456a75038431bd9c9f859ab5ad594a03b9
4
+ data.tar.gz: ded194f7c99d75373087f380abf7aecb2e99e934fb34301cb782567ce62fd8a7
5
5
  SHA512:
6
- metadata.gz: 548e3d2beef7af97b014b4b4b17be021aed68462811df87a725f69c1a662979adb1f0c066c678a11884f8edfecd592cca5d29e52730a23f069206cb94c1d2efd
7
- data.tar.gz: f1a8a54bce6df502895a23ad5e4ba7640e216778d0656ff4cd27606a3801e0aed80e2916e50df5a83cb6eed2a4d9632964709d8e21d4089922272810a67496fb
6
+ metadata.gz: 01bc8257a97fd022789492d3d5f28379d4336cf4894ffbf78d71a010cf59fe4f45c8bdf4b8e03beefaab1b80b98c10f54afb643457852a2fdbb7a924d10a0a85
7
+ data.tar.gz: ad7016da0416537ee9313629ad88c0d00f1e26b1c876cb6028e03ad2dd15a7c946501c0a23b4213ef8292c6b0572a4fc848d90b6498a3d8420f44528032ec85c
@@ -1,5 +1,6 @@
1
1
  require 'json'
2
2
  require 'date'
3
+ require 'aws-sdk-s3'
3
4
 
4
5
  # Run Inmental or Full backups on MySQL
5
6
  module LL
@@ -62,7 +63,8 @@ class InnoBackup
62
63
  :date,
63
64
  :state_files,
64
65
  :lock_files,
65
- :options
66
+ :options,
67
+ :s3
66
68
 
67
69
  def initialize(options = {})
68
70
  @now = Time.now
@@ -71,6 +73,7 @@ class InnoBackup
71
73
  @lock_files = {}
72
74
  @state_files = {}
73
75
  @type = backup_type
76
+ @s3 = Aws::S3::Resource.new()
74
77
  end
75
78
 
76
79
  def aws_log
@@ -105,6 +108,10 @@ class InnoBackup
105
108
  false
106
109
  end
107
110
 
111
+ def is_encrypted?
112
+ !options['encryption_key'].empty?
113
+ end
114
+
108
115
  def can_full_backup?
109
116
  !fully_backed_up_today? && lock?('full')
110
117
  end
@@ -135,6 +142,10 @@ class InnoBackup
135
142
  @backup_compress_threads = options['backup_compress_threads'] ||= 4
136
143
  end
137
144
 
145
+ def encryption_threads
146
+ @encryption_threads = options['encryption_threads'] ||= 4
147
+ end
148
+
138
149
  def sql_backup_user
139
150
  @sql_backup_user ||= options['sql_backup_user']
140
151
  end
@@ -143,6 +154,10 @@ class InnoBackup
143
154
  @sql_backup_password ||= options['sql_backup_password']
144
155
  end
145
156
 
157
+ def encryption_key
158
+ @encryption_key ||= options['encryption_key']
159
+ end
160
+
146
161
  def aws_bin
147
162
  @aws_bin = options['aws_bin'] ||= '/usr/local/bin/aws'
148
163
  end
@@ -170,9 +185,12 @@ class InnoBackup
170
185
  end
171
186
 
172
187
  def innobackup_options
173
- "--parallel=#{backup_parallel} "\
174
- "--compress-threads=#{backup_compress_threads} "\
175
- '--stream=xbstream --compress'
188
+ [
189
+ "--parallel=#{backup_parallel}",
190
+ "--compress-threads=#{backup_compress_threads}",
191
+ ("--encrypt=AES256 --encrypt-key=#{encryption_key} --encrypt-threads=#{encryption_threads}" if is_encrypted?),
192
+ '--stream=xbstream --compress'
193
+ ].join(" ")
176
194
  end
177
195
 
178
196
  def innobackup_command
@@ -202,10 +220,14 @@ class InnoBackup
202
220
  "--expected-size=#{expected_full_size}" if type == 'full'
203
221
  end
204
222
 
205
- def aws_command
206
- "#{aws_bin} s3 cp #{working_file} s3://#{aws_bucket}/#{aws_backup_file} "\
207
- "#{expected_size} #{expires} "\
208
- "2> #{aws_log} >> #{aws_log}"
223
+ def s3object_uploaded?(bucket_name, object_key, file_path)
224
+ object = @s3.bucket(bucket_name).object(object_key)
225
+ object.upload_file(file_path, {expires: expires_date, thread_count: @options['thread_count']}) do |r|
226
+ return true
227
+ end
228
+ rescue StandardError => e
229
+ STDERR.puts "Error uploading object: #{e.message}"
230
+ return false
209
231
  end
210
232
 
211
233
  def valid_commands?
@@ -218,12 +240,11 @@ class InnoBackup
218
240
  return unless valid_commands?
219
241
  `#{innobackup_command}`
220
242
  @completed_inno = $CHILD_STATUS == 0
221
- raise Innobackup::StateError, 'Unable to run innobackup correctly' unless @completed_inno
222
- `#{aws_command}`
223
- @completed_aws = $CHILD_STATUS == 0
224
- raise Innobackup::StateError, 'Unable to run aws upload correctly' unless @completed_aws
243
+ raise InnoBackup::StateError, 'Unable to run innobackup correctly' unless @completed_inno
244
+ @completed_aws = s3object_uploaded?(aws_bucket, aws_backup_file, working_file)
245
+ raise InnoBackup::StateError, 'Unable to run aws upload correctly' unless @completed_aws
225
246
  return record if success? && completed?
226
- rescue Innobackup::StateError => e
247
+ rescue InnoBackup::StateError => e
227
248
  revert_aws
228
249
  rescue InnoBackup::NoStateError => e
229
250
  STDERR.puts e.message
@@ -340,6 +361,9 @@ class InnoBackup
340
361
 
341
362
  class NoStateError < StandardError
342
363
  end
364
+
365
+ class StateError < StandardError
366
+ end
343
367
  end
344
368
  end
345
369
  InnoBackup.new(InnoBackup.options).backup if $PROGRAM_NAME == __FILE__
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ll-innobackup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.18
4
+ version: 0.1.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stuart Harland, LiveLink Technology Ltd
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-11 00:00:00.000000000 Z
11
+ date: 2021-01-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
26
  version: 4.2.6
27
+ - !ruby/object:Gem::Dependency
28
+ name: aws-sdk-s3
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1'
27
41
  description: A program to conduct innobackup
28
42
  email: essjayhch@gmail.com, infra@livelinktechnology.net
29
43
  executables:
@@ -37,7 +51,7 @@ homepage: http://rubygems.org/gems/ll-innobackup
37
51
  licenses:
38
52
  - MIT
39
53
  metadata: {}
40
- post_install_message:
54
+ post_install_message:
41
55
  rdoc_options: []
42
56
  require_paths:
43
57
  - lib
@@ -52,9 +66,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
52
66
  - !ruby/object:Gem::Version
53
67
  version: '0'
54
68
  requirements: []
55
- rubyforge_project:
56
- rubygems_version: 2.6.13
57
- signing_key:
69
+ rubygems_version: 3.1.4
70
+ signing_key:
58
71
  specification_version: 4
59
72
  summary: Livelink Innobackup Script
60
73
  test_files: []