dumper 1.0.2 → 1.1.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.
- data/lib/dumper/agent.rb +5 -2
- data/lib/dumper/database/base.rb +0 -4
- data/lib/dumper/database/mongodb.rb +4 -4
- data/lib/dumper/database/mysql.rb +5 -5
- data/lib/dumper/database/postgresql.rb +6 -6
- data/lib/dumper/database/redis.rb +3 -3
- data/lib/dumper/job.rb +4 -11
- data/lib/dumper/stack.rb +6 -6
- data/lib/dumper/version.rb +1 -1
- metadata +2 -2
data/lib/dumper/agent.rb
CHANGED
@@ -6,8 +6,9 @@ module Dumper
|
|
6
6
|
include Dumper::Utility::LoggingMethods
|
7
7
|
|
8
8
|
API_VERSION = 1
|
9
|
+
MAX_FILESIZE = 2.gigabytes
|
9
10
|
|
10
|
-
attr_reader :stack
|
11
|
+
attr_reader :stack, :max_filesize
|
11
12
|
|
12
13
|
class << self
|
13
14
|
def start(options = {})
|
@@ -60,7 +61,9 @@ module Dumper
|
|
60
61
|
return log("agent stopped: #{json.to_s}") if json[:status] == 'error'
|
61
62
|
|
62
63
|
@token = json[:token]
|
63
|
-
|
64
|
+
@max_filesize = (json[:max_filesize] || MAX_FILESIZE).to_i
|
65
|
+
log "agent started as #{@token ? 'primary' : 'secondary'}, max_filesize = #{@max_filesize}"
|
66
|
+
|
64
67
|
sleep 1.hour + rand(10) unless @token
|
65
68
|
|
66
69
|
loop do
|
data/lib/dumper/database/base.rb
CHANGED
@@ -10,8 +10,8 @@ module Dumper
|
|
10
10
|
|
11
11
|
def connection_options
|
12
12
|
[ :database, :host, :port, :username, :password ].map do |option|
|
13
|
-
next if @config
|
14
|
-
"--#{option}='#{@config
|
13
|
+
next if @config[option].blank?
|
14
|
+
"--#{option}='#{@config[option]}'".gsub('--database', '--db')
|
15
15
|
end.compact.join(' ')
|
16
16
|
end
|
17
17
|
|
@@ -19,11 +19,11 @@ module Dumper
|
|
19
19
|
"--out='#{tmpdir}'"
|
20
20
|
end
|
21
21
|
|
22
|
-
def
|
22
|
+
def set_config_for(rails_env=nil)
|
23
23
|
return unless defined?(Mongo::DB) &&
|
24
24
|
(mongo = find_instance_in_object_space(Mongo::DB))
|
25
25
|
|
26
|
-
{
|
26
|
+
@config = {
|
27
27
|
:host => mongo.connection.host,
|
28
28
|
:port => mongo.connection.port,
|
29
29
|
:database => mongo.name,
|
@@ -5,13 +5,13 @@ module Dumper
|
|
5
5
|
FILE_EXT = 'sql.gz'
|
6
6
|
|
7
7
|
def command
|
8
|
-
"cd #{tmpdir} && #{dump_tool_path} #{connection_options} #{additional_options} #{@config
|
8
|
+
"cd #{tmpdir} && #{dump_tool_path} #{connection_options} #{additional_options} #{@config[:database]} | gzip > #{filename}"
|
9
9
|
end
|
10
10
|
|
11
11
|
def connection_options
|
12
12
|
[ :host, :port, :username, :password ].map do |option|
|
13
|
-
next if @config
|
14
|
-
"--#{option}='#{@config
|
13
|
+
next if @config[option].blank?
|
14
|
+
"--#{option}='#{@config[option]}'".gsub('--username', '--user')
|
15
15
|
end.compact.join(' ')
|
16
16
|
end
|
17
17
|
|
@@ -19,13 +19,13 @@ module Dumper
|
|
19
19
|
'--single-transaction'
|
20
20
|
end
|
21
21
|
|
22
|
-
def
|
22
|
+
def set_config_for(rails_env=nil)
|
23
23
|
return unless defined?(ActiveRecord::Base) &&
|
24
24
|
ActiveRecord::Base.configurations &&
|
25
25
|
(config = ActiveRecord::Base.configurations[rails_env]) &&
|
26
26
|
%w(mysql mysql2).include?(config['adapter'])
|
27
27
|
|
28
|
-
{
|
28
|
+
@config = {
|
29
29
|
:host => config['host'],
|
30
30
|
:port => config['port'],
|
31
31
|
:username => config['username'],
|
@@ -5,27 +5,27 @@ module Dumper
|
|
5
5
|
FILE_EXT = 'sql.gz'
|
6
6
|
|
7
7
|
def command
|
8
|
-
"cd #{tmpdir} && #{password_variable} #{dump_tool_path} #{connection_options} #{@config
|
8
|
+
"cd #{tmpdir} && #{password_variable} #{dump_tool_path} #{connection_options} #{@config[:database]} | gzip > #{filename}"
|
9
9
|
end
|
10
10
|
|
11
11
|
def connection_options
|
12
12
|
[ :host, :port, :socket ].map do |option|
|
13
|
-
next if @config
|
14
|
-
"--#{option}='#{@config
|
13
|
+
next if @config[option].blank?
|
14
|
+
"--#{option}='#{@config[option]}'".gsub('--socket', '--host')
|
15
15
|
end.compact.join(' ')
|
16
16
|
end
|
17
17
|
|
18
18
|
def password_variable
|
19
|
-
@config
|
19
|
+
@config[:password].blank? ? '' : "PGPASSWORD='#{@config[:password]}'"
|
20
20
|
end
|
21
21
|
|
22
|
-
def
|
22
|
+
def set_config_for(rails_env=nil)
|
23
23
|
return unless defined?(ActiveRecord::Base) &&
|
24
24
|
ActiveRecord::Base.configurations &&
|
25
25
|
(config = ActiveRecord::Base.configurations[rails_env]) &&
|
26
26
|
(config['adapter'] == 'postgresql')
|
27
27
|
|
28
|
-
{
|
28
|
+
@config = {
|
29
29
|
:host => config['host'],
|
30
30
|
:port => config['port'],
|
31
31
|
:username => config['username'],
|
@@ -6,10 +6,10 @@ module Dumper
|
|
6
6
|
|
7
7
|
def command
|
8
8
|
uncompressed = filename.sub('.gz','')
|
9
|
-
"cd #{tmpdir} && cp #{@config
|
9
|
+
"cd #{tmpdir} && cp #{@config[:dbpath]} #{uncompressed} && gzip #{uncompressed}"
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
12
|
+
def set_config_for(rails_env=nil)
|
13
13
|
return unless defined?(::Redis) &&
|
14
14
|
(main_thread_redis = find_instance_in_object_space(::Redis))
|
15
15
|
|
@@ -23,7 +23,7 @@ module Dumper
|
|
23
23
|
|
24
24
|
return unless File.exist?(dbpath) # Redis must run on the back up node
|
25
25
|
|
26
|
-
{
|
26
|
+
@config = {
|
27
27
|
:host => client.host,
|
28
28
|
:port => client.port,
|
29
29
|
:password => client.password,
|
data/lib/dumper/job.rb
CHANGED
@@ -6,11 +6,8 @@ module Dumper
|
|
6
6
|
include POSIX::Spawn
|
7
7
|
include Dumper::Utility::LoggingMethods
|
8
8
|
|
9
|
-
MAX_FILESIZE = 4.gigabytes
|
10
|
-
|
11
9
|
def initialize(agent, job)
|
12
10
|
@agent = agent
|
13
|
-
@stack = agent.stack
|
14
11
|
@job = job
|
15
12
|
end
|
16
13
|
|
@@ -25,14 +22,10 @@ module Dumper
|
|
25
22
|
end
|
26
23
|
|
27
24
|
def perform(server)
|
28
|
-
#
|
25
|
+
# Find database
|
29
26
|
server_type = server[:type].to_sym
|
30
|
-
|
31
|
-
|
32
|
-
@database.config = OpenStruct.new(@stack.configs[Dumper::Stack::DATABASES.key(@database.class)])
|
33
|
-
else
|
34
|
-
abort_with "invalid server type: #{server_type}"
|
35
|
-
end
|
27
|
+
abort_with "invalid server type: #{server_type}" unless Dumper::Stack::DATABASES.keys.include?(server_type)
|
28
|
+
return log "database not found: #{@database.inspect}" unless @database = @agent.stack.databases[server_type]
|
36
29
|
|
37
30
|
# Prepare
|
38
31
|
json = @agent.api_request('backup/prepare', :params => { :server_id => server[:id], :manual => server[:manual].to_s, :ext => @database.file_ext })
|
@@ -61,7 +54,7 @@ module Dumper
|
|
61
54
|
|
62
55
|
dump_duration = Time.now - start_at
|
63
56
|
log "dump_duration = #{dump_duration}"
|
64
|
-
if (filesize = File.size(@database.dump_path)) >
|
57
|
+
if (filesize = File.size(@database.dump_path)) > @agent.max_filesize
|
65
58
|
abort_with("max filesize exceeded: #{filesize}", :too_large)
|
66
59
|
end
|
67
60
|
|
data/lib/dumper/stack.rb
CHANGED
@@ -9,10 +9,10 @@ module Dumper
|
|
9
9
|
:redis => Dumper::Database::Redis,
|
10
10
|
}
|
11
11
|
|
12
|
-
attr_accessor :rails_env, :dispatcher, :framework, :rackup, :
|
12
|
+
attr_accessor :rails_env, :dispatcher, :framework, :rackup, :databases
|
13
13
|
|
14
14
|
def initialize(options = {})
|
15
|
-
@
|
15
|
+
@databases = {}
|
16
16
|
|
17
17
|
# Rackup?
|
18
18
|
@rackup = find_instance_in_object_space(Rack::Server)
|
@@ -25,8 +25,8 @@ module Dumper
|
|
25
25
|
@is_supported_rails_version = (::Rails::VERSION::MAJOR >= 3)
|
26
26
|
DATABASES.each do |key, klass|
|
27
27
|
database = klass.new
|
28
|
-
next unless
|
29
|
-
@
|
28
|
+
next unless database.set_config_for(@rails_env) || database.set_config_for(options[:additional_env])
|
29
|
+
@databases[key] = database
|
30
30
|
end
|
31
31
|
|
32
32
|
else
|
@@ -45,13 +45,13 @@ module Dumper
|
|
45
45
|
rails_env: @rails_env,
|
46
46
|
rails_version: @rails_version,
|
47
47
|
dispatcher: @dispatcher,
|
48
|
-
configs: Hash[@
|
48
|
+
configs: Hash[@databases.map{|k, database| [ k, database.config.reject{|k,v| k == :password } ] }]
|
49
49
|
}
|
50
50
|
end
|
51
51
|
|
52
52
|
# Compatibility
|
53
53
|
def supported?
|
54
|
-
@is_supported_rails_version && @dispatcher && !@
|
54
|
+
@is_supported_rails_version && @dispatcher && !@databases.empty?
|
55
55
|
end
|
56
56
|
|
57
57
|
# Dispatcher
|
data/lib/dumper/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dumper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-06-
|
12
|
+
date: 2012-06-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: multi_json
|