mys3ql 1.2.1 → 1.3.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
- SHA256:
3
- metadata.gz: 45f85278cadc72fb6e195a38f152bdf4540b084ecd51d328c73edada8528ec17
4
- data.tar.gz: 33527921e258fba6bd9b3de255c6e4e9105030283164898777b2593d04b887d1
2
+ SHA1:
3
+ metadata.gz: 86d0a66ce7dab918b298c22eb4d667df2cb9ac7c
4
+ data.tar.gz: cd9527db20ae5a07349b3456e544a0aa3552f9bd
5
5
  SHA512:
6
- metadata.gz: 9201515cf1d9cc6ae53cfd0079622f09549c2026f1e86759179e32aa42fcf65699cc4f100ea621c59ae22ee018fc3bcdd3de0e931df0d3e257e3629e3e852952
7
- data.tar.gz: 051301e9ee660ca95ac3045d78739f2c9a17d988e5433f90987595730c4b69d065a31bd05d7f4510c0bf8998c425308575c4c6f3e9c09e446bbd1c4e443fc0d9
6
+ metadata.gz: 25abe9f3cc7daee801c8402dbd07b8827608d139ed4a2ca95ec089ed1a7d4335dfbfaa8fd30f10ea06118159d3513fa90c866ac9fa09976b48dc8d05645ac105
7
+ data.tar.gz: 340d29d1230eda51d4408b8f5fb3597ed7da31276171608469092c10fbe04ceb5f3e0640f3758cbdbe14c2af99804bc5ebb81dd27e6097c661c492d4339d56f4
data/README.md CHANGED
@@ -21,6 +21,12 @@ To restore from the latest backup (plus binlogs if present):
21
21
 
22
22
  $ mys3ql restore
23
23
 
24
+ To restore a recent subset of binlogs:
25
+
26
+ $ mys3ql restore --after NUMBER
27
+
28
+ – where NUMBER is a 6-digit binlog file number.
29
+
24
30
  By default mys3ql looks for a configuration file at `~/.mys3ql`. You can override this like so:
25
31
 
26
32
  $ mys3ql [command] -c FILE
data/bin/mys3ql CHANGED
@@ -6,14 +6,21 @@ require 'optparse'
6
6
 
7
7
  params = {}
8
8
  op = OptionParser.new do |opts|
9
- opts.banner = 'Usage: mys3ql <full|incremental|restore> [<args>]'
9
+ opts.banner = 'Usage: mys3ql <full|incremental|restore> [<options>]'
10
+
11
+ opts.separator ''
12
+ opts.separator 'Common options:'
10
13
 
11
14
  opts.on('-c', '--config CONFIG', 'Load configuration from YAML file (default ~/.mys3ql)') { |v| params[:config] = v }
12
- opts.on_tail('-d', '--debug', 'Be verbose') { |v| params[:debug] = v }
13
- opts.on_tail '-v', '--version', 'Print version' do
15
+ opts.on('-d', '--debug', 'Be verbose') { |v| params[:debug] = v }
16
+ opts.on '-v', '--version', 'Print version' do
14
17
  puts "mys3ql v#{Mys3ql::VERSION}"
15
18
  exit
16
19
  end
20
+
21
+ opts.separator ''
22
+ opts.separator 'restore options:'
23
+ opts.on('-a', '--after NUMBER', 'Use only the subset of binary logs after NUMBER') { |v| params[:after] = v }
17
24
  end
18
25
  op.parse! ARGV
19
26
 
@@ -23,4 +30,4 @@ unless %w[full incremental restore].include? params[:command]
23
30
  exit 1
24
31
  end
25
32
 
26
- Mys3ql::Conductor.run params[:command], params[:config], params[:debug]
33
+ Mys3ql::Conductor.run params
@@ -6,10 +6,16 @@ require 'mys3ql/s3'
6
6
  module Mys3ql
7
7
  class Conductor
8
8
 
9
- def self.run(command, config, debug)
10
- conductor = Conductor.new(config)
11
- conductor.debug = debug
12
- conductor.send command
9
+ def self.run(args)
10
+ conductor = Conductor.new args.fetch(:config, nil)
11
+ conductor.debug = args.fetch(:debug, false)
12
+
13
+ command = args.fetch(:command)
14
+ if command == 'restore'
15
+ conductor.restore args.fetch(:after, nil)
16
+ else
17
+ conductor.send command
18
+ end
13
19
  end
14
20
 
15
21
  def initialize(config_file = nil)
@@ -38,22 +44,36 @@ module Mys3ql
38
44
  end
39
45
  end
40
46
 
41
- # Downloads the latest dump from S3 and loads it into the database.
42
- # Downloads each binary log from S3 and loads it into the database.
47
+ # When 'after' is nil:
48
+ #
49
+ # - downloads the latest dump from S3 and loads it into the database;
50
+ # - downloads each binary log from S3 and loads it into the database.
51
+ #
52
+ # When 'after' is given:
53
+ #
54
+ # - downloads each binary log following 'after' from S3 and loads it into the database.
55
+ #
43
56
  # Downloaded files are removed from the file system.
44
- def restore
45
- # get latest dump
46
- with_temp_file do |file|
47
- @s3.retrieve :latest, file
48
- @mysql.restore file
57
+ def restore(after = nil)
58
+ unless after
59
+ # get latest dump
60
+ with_temp_file do |file|
61
+ @s3.retrieve :latest, file
62
+ @mysql.restore file
63
+ end
49
64
  end
50
65
 
51
- # apply subsequent bin logs
52
- @s3.each_bin_log do |log|
53
- with_temp_file do |file|
54
- @s3.retrieve log, file
55
- @mysql.apply_bin_log file
66
+ # apply bin logs
67
+ begin
68
+ tmpfiles = []
69
+ @s3.each_bin_log(after) do |log|
70
+ file = Tempfile.new 'mys3ql'
71
+ tmpfiles << file
72
+ @s3.retrieve log, file.path
56
73
  end
74
+ @mysql.apply_bin_logs tmpfiles.map(&:path)
75
+ ensure
76
+ tmpfiles.each &:close!
57
77
  end
58
78
 
59
79
  # NOTE: not sure about this:
data/lib/mys3ql/mysql.rb CHANGED
@@ -60,8 +60,8 @@ module Mys3ql
60
60
  run "gunzip -c #{file} | #{@config.bin_path}mysql #{cli_options}"
61
61
  end
62
62
 
63
- def apply_bin_log(file)
64
- cmd = "#{@config.bin_path}mysqlbinlog --database=#{@config.database} #{file}"
63
+ def apply_bin_logs(*files)
64
+ cmd = "#{@config.bin_path}mysqlbinlog --database=#{@config.database} #{files.join ' '}"
65
65
  cmd += " | #{@config.bin_path}mysql -u'#{@config.user}'"
66
66
  cmd += " -p'#{@config.password}'" if @config.password
67
67
  run cmd
data/lib/mys3ql/s3.rb CHANGED
@@ -26,9 +26,15 @@ module Mys3ql
26
26
  end
27
27
  end
28
28
 
29
- def each_bin_log(&block)
29
+ def each_bin_log(after = nil, &block)
30
+ if after && after !~ /^\d{6}$/
31
+ puts 'Binary log file number must be 6 digits.'
32
+ exit 1
33
+ end
34
+
30
35
  bucket.objects(prefix: bin_logs_prefix)
31
36
  .sort_by { |file| file.key[/\d+/].to_i }
37
+ .select { |file| after.nil? || (file.key[/\d+/].to_i > after.to_i) }
32
38
  .each do |file|
33
39
  yield file
34
40
  end
@@ -52,7 +58,7 @@ module Mys3ql
52
58
 
53
59
  def save(local_file_name, s3_key)
54
60
  if bucket.object(s3_key).exists?
55
- log "s3: skipped #{local_file_name} - #{s3_key} exists"
61
+ log "s3: skipped #{local_file_name} - already exists"
56
62
  return
57
63
  end
58
64
 
@@ -1,3 +1,3 @@
1
1
  module Mys3ql
2
- VERSION = '1.2.1'
2
+ VERSION = '1.3.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mys3ql
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Stewart
@@ -77,7 +77,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
77
  - !ruby/object:Gem::Version
78
78
  version: '0'
79
79
  requirements: []
80
- rubygems_version: 3.1.2
80
+ rubyforge_project:
81
+ rubygems_version: 2.5.2.3
81
82
  signing_key:
82
83
  specification_version: 4
83
84
  summary: Simple backup of your MySql database onto Amazon S3.