cloner 0.8.0 → 0.11.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 +4 -4
- data/README.md +23 -0
- data/lib/cloner/ar.rb +58 -5
- data/lib/cloner/mysql.rb +3 -3
- data/lib/cloner/postgres.rb +3 -3
- data/lib/cloner/rsync.rb +9 -2
- data/lib/cloner/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b194b889c54f1cdbd1a60853f80c463a0f7d15f959f81d42618fd96c67f18ab
|
4
|
+
data.tar.gz: 303e8b18314d5041240b08f228d27f93cd89195cbb28edd252bb49f490fe867e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9fcb580d17ae6bacfffd3b5f7209f4e97cee07bc29eca23e86c9220a020bb47e3b0c58fc8b23289b2fa3b560b375207928955b34287b8ae62097e986d7bff71c
|
7
|
+
data.tar.gz: 640449403fb0af65d73fa5fcd68c15fc9a414a38c759c89bfae750b8108c4333ead02fcf84fc5b24183ca7bb4d39c6f908c2a5243bfd6c301e0e0c18c563eacd
|
data/README.md
CHANGED
@@ -109,6 +109,29 @@ All functions from cloner/internal.rb can be overriden, for example:
|
|
109
109
|
|
110
110
|
## Changelog
|
111
111
|
|
112
|
+
### 0.10.0
|
113
|
+
|
114
|
+
- Support rails 6 multi database activerecord apps via option
|
115
|
+
|
116
|
+
```
|
117
|
+
def multi_db?
|
118
|
+
true
|
119
|
+
end
|
120
|
+
def clone_databases
|
121
|
+
["primary", "gis"]
|
122
|
+
# nil - clone all databases
|
123
|
+
end
|
124
|
+
```
|
125
|
+
|
126
|
+
- Backwards incompatible change:
|
127
|
+
|
128
|
+
Changed default dump file name to cloner.bak in postgresql to make it same, and to allow to override it and multiple files.
|
129
|
+
|
130
|
+
### 0.9.0
|
131
|
+
|
132
|
+
- Add option to rsync to allow sync one file (thx @AnatolyShirykalov)
|
133
|
+
- Add env_database to allow overriding database env (thx @Yarroo)
|
134
|
+
|
112
135
|
### 0.8.0
|
113
136
|
|
114
137
|
- Change default rsync flags - -z to -zz to support newer versions of rsync
|
data/lib/cloner/ar.rb
CHANGED
@@ -1,21 +1,41 @@
|
|
1
1
|
module Cloner::Ar
|
2
|
-
def
|
2
|
+
def read_ar_conf
|
3
3
|
@conf ||= begin
|
4
|
-
YAML.
|
4
|
+
YAML.load(ERB.new(File.read(Rails.root.join('config', 'database.yml'))).result)[env_database]
|
5
|
+
end
|
6
|
+
end
|
7
|
+
def ar_conf
|
8
|
+
if multi_db?
|
9
|
+
read_ar_conf[@current_database]
|
10
|
+
else
|
11
|
+
read_ar_conf
|
5
12
|
end
|
6
13
|
end
|
7
14
|
|
15
|
+
def multi_db?
|
16
|
+
false
|
17
|
+
end
|
18
|
+
|
19
|
+
def clone_databases
|
20
|
+
# clone all databases by default
|
21
|
+
nil
|
22
|
+
end
|
23
|
+
|
24
|
+
def env_database
|
25
|
+
Rails.env
|
26
|
+
end
|
27
|
+
|
8
28
|
def ar_to
|
9
29
|
ar_conf['database']
|
10
30
|
end
|
11
31
|
|
12
|
-
def
|
32
|
+
def read_ar_r_conf
|
13
33
|
@ar_r_conf ||= begin
|
14
34
|
do_ssh do |ssh|
|
15
35
|
ret = ssh_exec!(ssh, "cat #{e(remote_app_path + '/config/database.yml')}")
|
16
36
|
check_ssh_err(ret)
|
17
37
|
begin
|
18
|
-
res = YAML.load(ret[0])[env_from]
|
38
|
+
res = YAML.load(ERB.new(ret[0]).result)[env_from]
|
19
39
|
raise 'no data' if res.blank?
|
20
40
|
#res['host'] ||= '127.0.0.1'
|
21
41
|
rescue Exception => e
|
@@ -28,7 +48,23 @@ module Cloner::Ar
|
|
28
48
|
end
|
29
49
|
end
|
30
50
|
|
31
|
-
def
|
51
|
+
def db_file_name
|
52
|
+
if multi_db?
|
53
|
+
"cloner_" + @current_database
|
54
|
+
else
|
55
|
+
"cloner"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def ar_r_conf
|
60
|
+
if multi_db?
|
61
|
+
read_ar_r_conf[@current_database]
|
62
|
+
else
|
63
|
+
read_ar_r_conf
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def run_clone_ar
|
32
68
|
if ar_conf["adapter"] != ar_r_conf["adapter"]
|
33
69
|
puts "Error: ActiveRecord adapter mismatch: local #{ar_conf["adapter"]}, remote #{ar_r_conf["adapter"]}"
|
34
70
|
puts "it is not possible to convert from one database to another via this tool."
|
@@ -46,5 +82,22 @@ module Cloner::Ar
|
|
46
82
|
exit
|
47
83
|
end
|
48
84
|
end
|
85
|
+
|
86
|
+
def clone_ar
|
87
|
+
if multi_db?
|
88
|
+
dblist = clone_databases
|
89
|
+
if dblist.nil?
|
90
|
+
dblist = read_ar_conf.keys
|
91
|
+
end
|
92
|
+
puts "cloning multiple databases: #{dblist.join(", ")}"
|
93
|
+
dblist.each do |dbn|
|
94
|
+
@current_database = dbn
|
95
|
+
run_clone_ar
|
96
|
+
end
|
97
|
+
@current_database = nil
|
98
|
+
else
|
99
|
+
run_clone_ar
|
100
|
+
end
|
101
|
+
end
|
49
102
|
end
|
50
103
|
|
data/lib/cloner/mysql.rb
CHANGED
@@ -35,7 +35,7 @@ module Cloner::MySQL
|
|
35
35
|
check_ssh_err(ret)
|
36
36
|
host = ar_r_conf['host'].present? ? " --host #{e ar_r_conf['host']}" : ""
|
37
37
|
port = ar_r_conf['port'].present? ? " --port #{e ar_r_conf['port']}" : ""
|
38
|
-
dump = "#{my_bin_path 'mysqldump'} #{my_dump_param} --user #{e ar_r_conf['username']} #{my_remote_auth}#{host}#{port} #{e ar_r_conf['database']} > #{e(remote_dump_path + '/
|
38
|
+
dump = "#{my_bin_path 'mysqldump'} #{my_dump_param} --user #{e ar_r_conf['username']} #{my_remote_auth}#{host}#{port} #{e ar_r_conf['database']} > #{e(remote_dump_path + '/'+db_file_name+'.sql')}"
|
39
39
|
puts dump if verbose?
|
40
40
|
ret = ssh_exec!(ssh, dump)
|
41
41
|
check_ssh_err(ret)
|
@@ -46,7 +46,7 @@ module Cloner::MySQL
|
|
46
46
|
puts "restoring DB"
|
47
47
|
host = ar_conf['host'].present? ? " --host #{e ar_conf['host']}" : ""
|
48
48
|
port = ar_conf['port'].present? ? " --port #{e ar_conf['port']}" : ""
|
49
|
-
restore = "#{my_bin_path 'mysql'} #{my_restore_param} --user #{e ar_conf['username']} #{my_local_auth}#{host}#{port} #{e ar_to} < #{e(my_path + '/
|
49
|
+
restore = "#{my_bin_path 'mysql'} #{my_restore_param} --user #{e ar_conf['username']} #{my_local_auth}#{host}#{port} #{e ar_to} < #{e(my_path + '/'+db_file_name+'.sql')}"
|
50
50
|
puts restore if verbose?
|
51
51
|
pipe = IO.popen(restore)
|
52
52
|
while (line = pipe.gets)
|
@@ -65,7 +65,7 @@ module Cloner::MySQL
|
|
65
65
|
def my_dump_copy
|
66
66
|
FileUtils.mkdir_p(my_path)
|
67
67
|
`mkdir -p #{e my_path}`
|
68
|
-
rsync(remote_dump_path
|
68
|
+
rsync(remote_dump_path, my_path)
|
69
69
|
end
|
70
70
|
|
71
71
|
def clone_my
|
data/lib/cloner/postgres.rb
CHANGED
@@ -52,7 +52,7 @@ module Cloner::Postgres
|
|
52
52
|
check_ssh_err(ret)
|
53
53
|
host = ar_r_conf['host'].present? ? " -h #{e ar_r_conf['host']}" : ""
|
54
54
|
port = ar_r_conf['port'].present? ? " -p #{e ar_r_conf['port']}" : ""
|
55
|
-
dump = pg_remote_auth + "#{pg_remote_bin_path 'pg_dump'} #{pg_dump_param} -U #{e ar_r_conf['username']}#{host}#{port} #{e ar_r_conf['database']} > #{e(remote_dump_path + '/
|
55
|
+
dump = pg_remote_auth + "#{pg_remote_bin_path 'pg_dump'} #{pg_dump_param} -U #{e ar_r_conf['username']}#{host}#{port} #{e ar_r_conf['database']} > #{e(remote_dump_path + '/'+db_file_name+'.bak')}"
|
56
56
|
puts dump if verbose?
|
57
57
|
ret = ssh_exec!(ssh, dump)
|
58
58
|
check_ssh_err(ret)
|
@@ -63,7 +63,7 @@ module Cloner::Postgres
|
|
63
63
|
puts "restoring DB"
|
64
64
|
host = ar_conf['host'].present? ? " -h #{e ar_conf['host']}" : ""
|
65
65
|
port = ar_conf['port'].present? ? " -p #{e ar_conf['port']}" : ""
|
66
|
-
restore = pg_local_auth + "#{pg_local_bin_path 'pg_restore'} #{pg_restore_param} -U #{e ar_conf['username']}#{host}#{port} -d #{e ar_to} #{e(pg_path + '/
|
66
|
+
restore = pg_local_auth + "#{pg_local_bin_path 'pg_restore'} #{pg_restore_param} -U #{e ar_conf['username']}#{host}#{port} -d #{e ar_to} #{e(pg_path + '/'+db_file_name+'.bak')}"
|
67
67
|
puts restore if verbose?
|
68
68
|
pipe = IO.popen(restore)
|
69
69
|
while (line = pipe.gets)
|
@@ -82,7 +82,7 @@ module Cloner::Postgres
|
|
82
82
|
def pg_dump_copy
|
83
83
|
FileUtils.mkdir_p(pg_path)
|
84
84
|
`mkdir -p #{e pg_path}`
|
85
|
-
rsync(remote_dump_path
|
85
|
+
rsync(remote_dump_path, pg_path)
|
86
86
|
end
|
87
87
|
|
88
88
|
def clone_pg
|
data/lib/cloner/rsync.rb
CHANGED
@@ -10,8 +10,12 @@ module Cloner::RSync
|
|
10
10
|
"#{rsync_compression} -utvr --checksum -e \"ssh -p #{port}\""
|
11
11
|
end
|
12
12
|
|
13
|
-
def rsync(from, to)
|
14
|
-
|
13
|
+
def rsync(from, to, directory: true, raise_on_error: false)
|
14
|
+
if directory
|
15
|
+
from = "#{from}/" unless from.to_s.end_with?('/')
|
16
|
+
to = "#{to}/" unless to.to_s.end_with?('/')
|
17
|
+
end
|
18
|
+
cmd = "rsync #{rsync_flags} #{e ssh_user}@#{e ssh_host}:#{e from} #{e to}"
|
15
19
|
puts "Running RSync: #{cmd}"
|
16
20
|
pipe = IO.popen(cmd)
|
17
21
|
while (line = pipe.gets)
|
@@ -20,6 +24,9 @@ module Cloner::RSync
|
|
20
24
|
pipe.close
|
21
25
|
ret = $?.to_i
|
22
26
|
if ret != 0
|
27
|
+
if raise_on_error
|
28
|
+
raise "Error: local command exited with #{ret}"
|
29
|
+
end
|
23
30
|
puts "Error: local command exited with #{ret}"
|
24
31
|
end
|
25
32
|
end
|
data/lib/cloner/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- glebtv
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-03-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -111,7 +111,7 @@ homepage: https://github.com/rs-pro/cloner
|
|
111
111
|
licenses:
|
112
112
|
- MIT
|
113
113
|
metadata: {}
|
114
|
-
post_install_message:
|
114
|
+
post_install_message:
|
115
115
|
rdoc_options: []
|
116
116
|
require_paths:
|
117
117
|
- lib
|
@@ -127,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
127
127
|
version: '0'
|
128
128
|
requirements: []
|
129
129
|
rubygems_version: 3.0.3
|
130
|
-
signing_key:
|
130
|
+
signing_key:
|
131
131
|
specification_version: 4
|
132
132
|
summary: Easily clone your production Mongoid database and files for local development
|
133
133
|
test_files: []
|