dumper 1.3.7 → 1.4.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: b6b408bf82e51cfbc886c06ef6f6bb3466fd49a7
4
- data.tar.gz: c5156f36b7f7d5a29cee37008db59a74ba307c94
3
+ metadata.gz: 821b7a382e2fe27d7fe8fb1c3d4368368d3bea54
4
+ data.tar.gz: fccb695b3b21ac6998bf8423ca891be8033398db
5
5
  SHA512:
6
- metadata.gz: fda0aa66cdeaad61af0e83d6b9ca21f3df63ffa7371d0c440df842d11dadb22b9f24548bded0f62595936c0db115a7388ebf57e8510488d00846145ad407b6c2
7
- data.tar.gz: 7a3852e30755078dec633d9da7b6a494b4fe10c77816555119e18ebde86fe9ed93b1ca644b0f741fe104f4b76dece96f3891c88291192e698c695428d8a9bf24
6
+ metadata.gz: 31f45ae50d8441350d87e90168cec56054c1295851f6066d0ca852cf9263938fa2c33eeb02223554fa2889dd126836fb24d0306f9b63d39f71e79e4f60332500
7
+ data.tar.gz: 424fedc83af11fa9a493a1ab12a8a5391068f34ff4a14aa2d251003e800d33969cdc0ad0c00d67d7574682c1154b70e5777464b43e410a6daffe8466c5450632
@@ -1,5 +1,6 @@
1
1
  Dumper::Dependency.load('thor')
2
2
  Dumper::Dependency.load('rainbow')
3
+ Dumper::Dependency.load('net-ntp')
3
4
 
4
5
  module Dumper
5
6
  class Cli < Thor
@@ -9,23 +10,23 @@ module Dumper
9
10
  def doctor
10
11
  check_ip
11
12
  check_cnf
13
+ check_clock
12
14
  end
13
15
 
14
16
  no_tasks do
15
17
  def check_ip
16
- puts 'Checking IP address...'
18
+ print 'Checking IP address... '
17
19
  @ip = Dumper::Utility::IP.new
18
- str = "#{@ip.ip} ... "
20
+ print "#{@ip.ip} => "
19
21
  if @ip.ipaddr.private?
20
- str << 'private'.color(:red)
22
+ puts "private IP, #{fetch_will_fail_warning}".color(:red)
21
23
  else
22
- str << 'public'.color(:green)
24
+ puts 'public IP, good'.color(:green)
23
25
  end
24
- puts str
25
26
  end
26
27
 
27
28
  def check_cnf
28
- puts 'Checking my.cnf...'
29
+ print 'Checking my.cnf... '
29
30
  bound = nil
30
31
  ['/etc/my.cnf', '/etc/mysql/my.cnf', '/usr/etc/my.cnf', '~/.my.cnf'].each do |name|
31
32
  fullpath = File.expand_path(name)
@@ -39,14 +40,32 @@ module Dumper
39
40
  end
40
41
  if bound
41
42
  if bound == '127.0.0.1'
42
- puts 'There is bind-address = 127.0.0.1 ... ' << 'fail'.color(:red)
43
+ print 'There is bind-address = 127.0.0.1 => '
43
44
  elsif IPAddr.new(bound).private?
44
- puts "There is bind-address = #{bound} ... " << 'fail'.color(:red)
45
+ print "There is bind-address = #{bound} => "
45
46
  end
47
+ puts fetch_will_fail_warning.color(:red)
46
48
  else
47
- puts 'No bind-address defined in my.cnf ... ' << 'ok'.color(:green)
49
+ puts 'No bind-address defined in my.cnf => ' << 'good'.color(:green)
48
50
  end
49
51
  end
52
+
53
+ def check_clock
54
+ print 'Checking server clock accuracy... '
55
+ target = Net::NTP.get('us.pool.ntp.org').time
56
+ source = Time.now
57
+ diff = (target - source).abs.round(3)
58
+ print "#{source.strftime('%Y-%m-%d %H:%M:%S')} (server time) vs #{target.strftime('%Y-%m-%d %H:%M:%S')} (ntp time), diff: #{diff} seconds => "
59
+ if diff > 15 * 60
60
+ puts 'warning, Amazon S3 does not accept clock skewed more than 15 minutes.'.color(:red)
61
+ else
62
+ puts 'good'.color(:green)
63
+ end
64
+ end
65
+
66
+ def fetch_will_fail_warning
67
+ 'warning - fetch from dumper.io to this server will fail, you will need to use the dumper gem with rails.'
68
+ end
50
69
  end
51
70
  end
52
71
  end
@@ -1,8 +1,9 @@
1
1
  module Dumper
2
2
  class Dependency
3
3
  LIBS = {
4
- 'thor' => { :require => 'thor', :version => '~> 0.14.0' },
4
+ 'thor' => { :require => 'thor', :version => '~> 0.14' },
5
5
  'rainbow' => { :require => 'rainbow', :version => '~> 1.1.4' },
6
+ 'net-ntp' => { :require => 'net/ntp', :version => '~> 2.1.1' },
6
7
  }
7
8
 
8
9
  def self.load(name)
@@ -55,12 +55,13 @@ module Dumper
55
55
  end
56
56
 
57
57
  dump_duration = Time.now - start_at
58
- log "dump_duration = #{dump_duration}"
59
- if (filesize = File.size(@database.dump_path)) > @agent.max_filesize
60
- abort_with("max filesize exceeded: #{filesize}", :too_large)
58
+ @filesize = File.size(@database.dump_path)
59
+ log "dump_duration = #{dump_duration}, filesize = #{@filesize}"
60
+ if @filesize > @agent.max_filesize
61
+ abort_with("max filesize exceeded: #{@filesize}", :too_large)
61
62
  end
62
63
 
63
- upload_to_s3(json[:url], json[:fields])
64
+ upload_to_s3(json)
64
65
 
65
66
  json = @agent.api_request('backup/commit', :params => { :backup_id => @backup_id, :dump_duration => dump_duration.to_i })
66
67
  rescue
@@ -70,10 +71,37 @@ module Dumper
70
71
  end
71
72
 
72
73
  # Upload
73
- def upload_to_s3(url, fields)
74
+ def upload_to_s3(json)
75
+ if defined?(AWS::S3::MultipartUpload) and @filesize > 100.megabytes
76
+ # aws-sdk gem installed
77
+ upload_by_aws_sdk(json)
78
+ else
79
+ # fallback to multipart-post
80
+ upload_by_multipart_post(json)
81
+ end
82
+ rescue
83
+ abort_with("upload error: #{$!} - please contact our support.", :upload_error)
84
+ end
85
+
86
+ def upload_by_aws_sdk(json)
87
+ log "uploading by aws-sdk v#{AWS::VERSION}"
88
+
89
+ s3 = json[:s3_federation]
90
+ aws = AWS::S3.new(s3[:credentials])
91
+ aws.buckets[s3[:bucket]].objects[s3[:key]].write(
92
+ file: @database.dump_path,
93
+ content_type: 'application/octet-stream',
94
+ content_disposition: "attachment; filename=#{@database.filename}",
95
+ )
96
+ end
97
+
98
+ def upload_by_multipart_post(json)
74
99
  require 'net/http/post/multipart'
100
+ log "uploading by multipart-post v#{Gem.loaded_specs['multipart-post'].version.to_s}"
101
+
102
+ fields = json[:fields]
75
103
  fields['file'] = UploadIO.new(@database.dump_path, 'application/octet-stream', @database.filename)
76
- uri = URI.parse(url)
104
+ uri = URI.parse(json[:url])
77
105
  request = Net::HTTP::Post::Multipart.new uri.path, fields
78
106
  http = Net::HTTP.new(uri.host, uri.port)
79
107
  if uri.is_a? URI::HTTPS
@@ -102,8 +130,6 @@ module Dumper
102
130
  else
103
131
  abort_with("upload error: #{response.to_s} - #{response.body}", :upload_error)
104
132
  end
105
- rescue
106
- abort_with("upload error: #{$!}", :upload_error)
107
133
  end
108
134
 
109
135
  def abort_with(text, code=nil)
@@ -1,3 +1,3 @@
1
1
  module Dumper
2
- VERSION = '1.3.7'
2
+ VERSION = '1.4.0'
3
3
  end
@@ -7,6 +7,23 @@ describe Dumper do
7
7
  Dumper::Agent.respond_to?(:start).should be_true
8
8
  end
9
9
 
10
+ it 'loads everything' do
11
+ expect {
12
+ Dumper::Agent
13
+ # Dumper::Cli
14
+ Dumper::Dependency
15
+ Dumper::Job
16
+ Dumper::Stack
17
+ Dumper::Utility
18
+ Dumper::VERSION
19
+ Dumper::Database::Base
20
+ Dumper::Database::MySQL
21
+ Dumper::Database::PostgreSQL
22
+ Dumper::Database::MongoDB
23
+ Dumper::Database::Redis
24
+ }.to_not raise_error
25
+ end
26
+
10
27
  describe :Stack do
11
28
  it 'initializes stack' do
12
29
  stack = Dumper::Stack.new
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dumper
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.7
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kenn Ejima
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-13 00:00:00.000000000 Z
11
+ date: 2013-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json