dumper 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/dumper.rb +5 -4
- data/lib/dumper/agent.rb +1 -1
- data/lib/dumper/database/base.rb +1 -1
- data/lib/dumper/database/mongodb.rb +2 -2
- data/lib/dumper/database/mysql.rb +3 -3
- data/lib/dumper/database/postgresql.rb +39 -0
- data/lib/dumper/database/redis.rb +1 -1
- data/lib/dumper/job.rb +6 -8
- data/lib/dumper/stack.rb +7 -5
- data/lib/dumper/version.rb +1 -1
- metadata +3 -2
data/lib/dumper.rb
CHANGED
@@ -10,9 +10,10 @@ module Dumper
|
|
10
10
|
autoload :VERSION, 'dumper/version'
|
11
11
|
|
12
12
|
module Database
|
13
|
-
autoload :Base,
|
14
|
-
autoload :MySQL,
|
15
|
-
autoload :
|
16
|
-
autoload :
|
13
|
+
autoload :Base, 'dumper/database/base'
|
14
|
+
autoload :MySQL, 'dumper/database/mysql'
|
15
|
+
autoload :PostgreSQL, 'dumper/database/postgresql'
|
16
|
+
autoload :MongoDB, 'dumper/database/mongodb'
|
17
|
+
autoload :Redis, 'dumper/database/redis'
|
17
18
|
end
|
18
19
|
end
|
data/lib/dumper/agent.rb
CHANGED
@@ -22,7 +22,7 @@ module Dumper
|
|
22
22
|
def initialize(options = {})
|
23
23
|
log 'app_key is missing' if options[:app_key].blank?
|
24
24
|
|
25
|
-
@stack = Dumper::Stack.new
|
25
|
+
@stack = Dumper::Stack.new(options)
|
26
26
|
@api_base = options[:api_base] || 'http://dumper.io'
|
27
27
|
@app_key = options[:app_key]
|
28
28
|
@app_env = @stack.rails_env
|
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 @
|
14
|
-
"--#{option}='#{@
|
13
|
+
next if @config.send(option).blank?
|
14
|
+
"--#{option}='#{@config.send(option)}'".gsub('--database', '--db')
|
15
15
|
end.compact.join(' ')
|
16
16
|
end
|
17
17
|
|
@@ -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} #{@
|
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 @
|
14
|
-
"--#{option}='#{@
|
13
|
+
next if @config.send(option).blank?
|
14
|
+
"--#{option}='#{@config.send(option)}'".gsub('--username', '--user')
|
15
15
|
end.compact.join(' ')
|
16
16
|
end
|
17
17
|
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Dumper
|
2
|
+
module Database
|
3
|
+
class PostgreSQL < Base
|
4
|
+
DUMP_TOOL = 'pg_dump'
|
5
|
+
FILE_EXT = 'sql.gz'
|
6
|
+
|
7
|
+
def command
|
8
|
+
"cd #{tmpdir} && #{password_variable} #{dump_tool_path} #{connection_options} #{@config.database} | gzip > #{filename}"
|
9
|
+
end
|
10
|
+
|
11
|
+
def connection_options
|
12
|
+
[ :host, :port, :socket ].map do |option|
|
13
|
+
next if @config.send(option).blank?
|
14
|
+
"--#{option}='#{@config.send(option)}'".gsub('--socket', '--host')
|
15
|
+
end.compact.join(' ')
|
16
|
+
end
|
17
|
+
|
18
|
+
def password_variable
|
19
|
+
@config.password.blank? ? '' : "PGPASSWORD='#{@config.password}'"
|
20
|
+
end
|
21
|
+
|
22
|
+
def config_for(rails_env=nil)
|
23
|
+
return unless defined?(ActiveRecord::Base) &&
|
24
|
+
ActiveRecord::Base.configurations &&
|
25
|
+
(config = ActiveRecord::Base.configurations[rails_env]) &&
|
26
|
+
(config['adapter'] == 'postgresql')
|
27
|
+
|
28
|
+
{
|
29
|
+
:host => config['host'],
|
30
|
+
:port => config['port'],
|
31
|
+
:username => config['username'],
|
32
|
+
:password => config['password'],
|
33
|
+
:database => config['database'],
|
34
|
+
:dump_tool => dump_tool_path
|
35
|
+
}
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -6,7 +6,7 @@ module Dumper
|
|
6
6
|
|
7
7
|
def command
|
8
8
|
uncompressed = filename.sub('.gz','')
|
9
|
-
"cd #{tmpdir} && cp #{@
|
9
|
+
"cd #{tmpdir} && cp #{@config.dbpath} #{uncompressed} && gzip #{uncompressed}"
|
10
10
|
end
|
11
11
|
|
12
12
|
def config_for(rails_env=nil)
|
data/lib/dumper/job.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'ostruct'
|
1
2
|
require 'posix/spawn'
|
2
3
|
|
3
4
|
module Dumper
|
@@ -25,15 +26,12 @@ module Dumper
|
|
25
26
|
|
26
27
|
def perform(server)
|
27
28
|
# Initialize database
|
28
|
-
|
29
|
-
|
30
|
-
@database = Dumper::
|
31
|
-
|
32
|
-
@database = Dumper::Database::MongoDB.new(@stack)
|
33
|
-
when 'redis'
|
34
|
-
@database = Dumper::Database::Redis.new(@stack)
|
29
|
+
server_type = server[:type].to_sym
|
30
|
+
if Dumper::Stack::DATABASES.keys.include?(server_type)
|
31
|
+
@database = Dumper::Stack::DATABASES[server_type].new(@stack)
|
32
|
+
@database.config = OpenStruct.new(@stack.configs[Dumper::Stack::DATABASES.key(@database.class)])
|
35
33
|
else
|
36
|
-
abort_with "invalid server type: #{
|
34
|
+
abort_with "invalid server type: #{server_type}"
|
37
35
|
end
|
38
36
|
|
39
37
|
# Prepare
|
data/lib/dumper/stack.rb
CHANGED
@@ -3,14 +3,15 @@ module Dumper
|
|
3
3
|
include Dumper::Utility::ObjectFinder
|
4
4
|
|
5
5
|
DATABASES = {
|
6
|
-
:mysql
|
7
|
-
:
|
8
|
-
:
|
6
|
+
:mysql => Dumper::Database::MySQL,
|
7
|
+
:postgresql => Dumper::Database::PostgreSQL,
|
8
|
+
:mongodb => Dumper::Database::MongoDB,
|
9
|
+
:redis => Dumper::Database::Redis,
|
9
10
|
}
|
10
11
|
|
11
12
|
attr_accessor :rails_env, :dispatcher, :framework, :rackup, :configs
|
12
13
|
|
13
|
-
def initialize
|
14
|
+
def initialize(options = {})
|
14
15
|
@configs = {}
|
15
16
|
|
16
17
|
# Rackup?
|
@@ -23,7 +24,8 @@ module Dumper
|
|
23
24
|
@rails_version = Rails::VERSION::STRING
|
24
25
|
@is_supported_rails_version = (::Rails::VERSION::MAJOR >= 3)
|
25
26
|
DATABASES.each do |key, klass|
|
26
|
-
|
27
|
+
database = klass.new
|
28
|
+
next unless config = database.config_for(@rails_env) || database.config_for(options[:additional_env])
|
27
29
|
@configs[key] = config
|
28
30
|
end
|
29
31
|
|
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: 0.
|
4
|
+
version: 0.4.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-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: multi_json
|
@@ -114,6 +114,7 @@ files:
|
|
114
114
|
- lib/dumper/database/base.rb
|
115
115
|
- lib/dumper/database/mongodb.rb
|
116
116
|
- lib/dumper/database/mysql.rb
|
117
|
+
- lib/dumper/database/postgresql.rb
|
117
118
|
- lib/dumper/database/redis.rb
|
118
119
|
- lib/dumper/dependency.rb
|
119
120
|
- lib/dumper/job.rb
|