db_dumper 0.5.1 → 0.5.2
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 +4 -4
- data/lib/db_dumper/query_builder.rb +8 -8
- data/lib/db_dumper/remote_machine.rb +25 -43
- data/lib/db_dumper/remote_machine/ssh_agent.rb +16 -8
- data/lib/db_dumper/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae74a3eb271dba85c9185c0e805fae78b68fd055bcbdd85d5a5d485d62fa9237
|
4
|
+
data.tar.gz: 18a0336e0b869ae4b08662a5e4cc07f16cf80596f45b04eceb6843d1961c1c50
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 543832e4c9e6d37a1b4384325afa7e655a8d01fa76d80cd9563af1b90faf10c236549ae7e4700a146b29079d6c0f5fe541c18fa69336dca5c37bbe946558e477
|
7
|
+
data.tar.gz: f5837c1c71534c1448ef19a572e7b655a56b4720afc77de90628189a746d69cbabe27588f6c587e8c4736b8098f0e68330e5753d174a82f6a47412506381fd08
|
@@ -2,7 +2,6 @@ require_relative 'query_builder/table'
|
|
2
2
|
require_relative 'query_builder/query'
|
3
3
|
|
4
4
|
module DbDumper
|
5
|
-
|
6
5
|
# Generates queries for copying data
|
7
6
|
class QueryBuilder
|
8
7
|
attr_reader :config
|
@@ -31,6 +30,14 @@ module DbDumper
|
|
31
30
|
|
32
31
|
# DSL end
|
33
32
|
|
33
|
+
def self.establish_connection
|
34
|
+
return if ActiveRecord::Base.connected?
|
35
|
+
|
36
|
+
ActiveRecord::Migration.verbose = false
|
37
|
+
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
|
38
|
+
end
|
39
|
+
private_class_method :establish_connection
|
40
|
+
|
34
41
|
private
|
35
42
|
|
36
43
|
def to_sql
|
@@ -41,13 +48,6 @@ module DbDumper
|
|
41
48
|
@config = config
|
42
49
|
end
|
43
50
|
|
44
|
-
def self.establish_connection
|
45
|
-
return if ActiveRecord::Base.connected?
|
46
|
-
|
47
|
-
ActiveRecord::Migration.verbose = false
|
48
|
-
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
|
49
|
-
end
|
50
|
-
|
51
51
|
def queries
|
52
52
|
@queries ||= []
|
53
53
|
end
|
@@ -15,80 +15,63 @@ module DbDumper
|
|
15
15
|
|
16
16
|
with_ssh do |ssh|
|
17
17
|
upload_commands_sql_to_remote_machine(ssh)
|
18
|
+
|
18
19
|
dump_schema(ssh)
|
19
20
|
dump_data(ssh)
|
21
|
+
|
20
22
|
download_schema(ssh)
|
21
23
|
download_data(ssh)
|
22
|
-
|
24
|
+
|
25
|
+
clean(ssh)
|
23
26
|
end
|
24
27
|
end
|
25
28
|
|
26
29
|
private
|
27
30
|
|
28
31
|
def with_ssh
|
29
|
-
ssh_agent = SshAgent.new(
|
32
|
+
ssh_agent = SshAgent.new(config)
|
30
33
|
yield(ssh_agent)
|
31
34
|
end
|
32
35
|
|
33
|
-
# Upload
|
34
36
|
def save_commands_sql_to_tmp_file
|
35
|
-
File.open(local_commands_sql_file_path, 'w')
|
37
|
+
File.open(local_commands_sql_file_path, 'w') do |file|
|
38
|
+
file.write(copy_commands_sql)
|
39
|
+
end
|
36
40
|
end
|
37
41
|
|
38
42
|
def upload_commands_sql_to_remote_machine(ssh)
|
39
43
|
ssh.upload!(local_commands_sql_file_path, remote_commands_sql_file_path)
|
40
44
|
end
|
41
45
|
|
42
|
-
def commands_sql_fname
|
43
|
-
@commands_sql_fname ||= "#{Digest::MD5.hexdigest(copy_commands_sql)}.sql"
|
44
|
-
end
|
45
|
-
|
46
|
-
# Schema
|
47
|
-
|
48
46
|
def dump_schema(ssh)
|
49
47
|
ssh.exec!(db_utils.dump_schema_command(remote_machine_schema_file_path))
|
50
48
|
end
|
51
49
|
|
52
|
-
def download_schema(ssh)
|
53
|
-
ssh.download!(remote_machine_schema_file_path, dest_path)
|
54
|
-
end
|
55
|
-
|
56
|
-
# Data
|
57
|
-
|
58
50
|
def dump_data(ssh)
|
59
51
|
ssh.exec!("mkdir -p #{remote_machine_data_path}")
|
60
52
|
ssh.exec!(db_utils.dump_data_command(remote_commands_sql_file_path))
|
61
53
|
end
|
62
54
|
|
55
|
+
def download_schema(ssh)
|
56
|
+
ssh.download!(remote_machine_schema_file_path, dest_path)
|
57
|
+
end
|
58
|
+
|
63
59
|
def download_data(ssh)
|
64
60
|
ssh.download!(remote_machine_data_path, dest_path, recursive: true)
|
65
61
|
end
|
66
62
|
|
67
|
-
|
68
|
-
def clean_remote_machine(ssh)
|
63
|
+
def clean(ssh)
|
69
64
|
ssh.exec! "rm #{remote_commands_sql_file_path}"
|
70
65
|
ssh.exec! "rm #{remote_machine_schema_file_path}"
|
71
66
|
ssh.exec! "rm -rf #{remote_machine_data_path}"
|
72
|
-
end
|
73
67
|
|
74
|
-
def clean_local_machine
|
75
68
|
File.delete(local_commands_sql_file_path)
|
76
69
|
end
|
77
70
|
|
78
|
-
#
|
79
|
-
|
80
71
|
def db_utils
|
81
72
|
config.db_utils
|
82
73
|
end
|
83
74
|
|
84
|
-
def remote_machine_dest_path
|
85
|
-
config.remote_machine.dest_path
|
86
|
-
end
|
87
|
-
|
88
|
-
def remote_machine_data_path
|
89
|
-
config.remote_machine.data_path
|
90
|
-
end
|
91
|
-
|
92
75
|
def remote_machine_schema_file_path
|
93
76
|
"#{remote_machine_dest_path}/#{dump_schema_fname}"
|
94
77
|
end
|
@@ -101,25 +84,24 @@ module DbDumper
|
|
101
84
|
"#{dest_path}/#{commands_sql_fname}"
|
102
85
|
end
|
103
86
|
|
104
|
-
def
|
105
|
-
|
106
|
-
end
|
107
|
-
|
108
|
-
def ssh_credentials
|
109
|
-
[
|
110
|
-
ssh_user.host,
|
111
|
-
ssh_user.name,
|
112
|
-
keys: ssh_user.ssh_keys,
|
113
|
-
passphrase: ssh_user.passphrase
|
114
|
-
]
|
87
|
+
def remote_machine_data_path
|
88
|
+
config.remote_machine.data_path
|
115
89
|
end
|
116
90
|
|
117
|
-
def
|
118
|
-
config.
|
91
|
+
def remote_machine_dest_path
|
92
|
+
config.remote_machine.dest_path
|
119
93
|
end
|
120
94
|
|
121
95
|
def dest_path
|
122
96
|
config.local_machine.dest_path
|
123
97
|
end
|
98
|
+
|
99
|
+
def commands_sql_fname
|
100
|
+
@commands_sql_fname ||= "#{Digest::MD5.hexdigest(copy_commands_sql)}.sql"
|
101
|
+
end
|
102
|
+
|
103
|
+
def dump_schema_fname
|
104
|
+
'schema_dump.sql'
|
105
|
+
end
|
124
106
|
end
|
125
107
|
end
|
@@ -3,18 +3,13 @@ module DbDumper
|
|
3
3
|
|
4
4
|
# Wrapper around Net::SSH, Net:SCP
|
5
5
|
class SshAgent
|
6
|
-
attr_reader :
|
6
|
+
attr_reader :config
|
7
7
|
attr_reader :block, :ssh
|
8
|
-
attr_reader :ssh_user_name, :ssh_host_name
|
9
8
|
|
10
|
-
def initialize(
|
11
|
-
@credentials = credentials
|
9
|
+
def initialize(config, &block)
|
12
10
|
@config = config
|
13
11
|
@block = block
|
14
12
|
@ssh = Net::SSH.start(*credentials)
|
15
|
-
|
16
|
-
@ssh_host_name = credentials[0]
|
17
|
-
@ssh_user_name = credentials[1]
|
18
13
|
end
|
19
14
|
|
20
15
|
def exec!(command)
|
@@ -34,8 +29,21 @@ module DbDumper
|
|
34
29
|
|
35
30
|
private
|
36
31
|
|
32
|
+
def credentials
|
33
|
+
[
|
34
|
+
ssh_user.host,
|
35
|
+
ssh_user.name,
|
36
|
+
keys: ssh_user.ssh_keys,
|
37
|
+
passphrase: ssh_user.passphrase
|
38
|
+
]
|
39
|
+
end
|
40
|
+
|
41
|
+
def ssh_user
|
42
|
+
@ssh_user ||= config.ssh_user
|
43
|
+
end
|
44
|
+
|
37
45
|
def ssh_machine_name
|
38
|
-
"#{
|
46
|
+
"#{ssh_user.name}@#{ssh_user.host}"
|
39
47
|
end
|
40
48
|
|
41
49
|
def log(message)
|
data/lib/db_dumper/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: db_dumper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexey Lukyanov
|
@@ -96,7 +96,7 @@ licenses:
|
|
96
96
|
metadata:
|
97
97
|
bug_tracker_uri: https://github.com/alukyanov/db_dumper/issues
|
98
98
|
changelog_uri: https://github.com/alukyanov/db_dumper/CHANGELOG.md
|
99
|
-
documentation_uri: http://www.rubydoc.info/gems/db_dumper/0.5.
|
99
|
+
documentation_uri: http://www.rubydoc.info/gems/db_dumper/0.5.2
|
100
100
|
homepage_uri: https://github.com/alukyanov/db_dumper
|
101
101
|
source_code_uri: https://github.com/alukyanov/db_dumper
|
102
102
|
wiki_uri: https://github.com/alukyanov/db_dumper/wiki
|