cloner 0.7.0 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/LICENSE.txt +1 -1
- data/README.md +41 -0
- data/lib/cloner/ar.rb +57 -4
- data/lib/cloner/mysql.rb +3 -3
- data/lib/cloner/postgres.rb +3 -3
- data/lib/cloner/rsync.rb +18 -2
- data/lib/cloner/version.rb +1 -1
- metadata +5 -7
- data/.ruby-gemset +0 -1
- data/HISTORY.md +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 61ad9f101c4e5a38fe4d2f15afadcd915e2bf8cff332e9b0d6f2e95a54f325ce
|
4
|
+
data.tar.gz: '08e3824a1bb16fb0f5d65451ed98d928c94f14192fc11ee9b01e3797fe6c727b'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '07080d76a94e16d7139648bc1d696ae311dc559927f9987614075def3f42e787300eb3609ad350a3dafcfa1f318915e1a630c61904b572eb7cbae7bc817b0bfa'
|
7
|
+
data.tar.gz: e51e3aa735fe16734ed22b1c03973f3c06f1797d0ef796f57e00d33c1299757e9182ea5f30f263f3a4c0c71acb8a6c00df9dcc8edaa36ce39a5fe4b86b1a3e17
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
ruby-2.6.6
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -2,6 +2,9 @@
|
|
2
2
|
|
3
3
|
Easily clone your production Mongoid or PostgreSQL / MySQL database and files for local development or staging area.
|
4
4
|
|
5
|
+
Uses rsync and database-specific default dump/restore tools (pg_dump/pg_restore, mysqldump/mysql, mongodump/mongorestore)
|
6
|
+
|
7
|
+
|
5
8
|
## Installation
|
6
9
|
|
7
10
|
Add this line to your application's Gemfile:
|
@@ -104,6 +107,44 @@ All functions from cloner/internal.rb can be overriden, for example:
|
|
104
107
|
{}
|
105
108
|
end
|
106
109
|
|
110
|
+
## Changelog
|
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
|
+
|
135
|
+
### 0.8.0
|
136
|
+
|
137
|
+
- Change default rsync flags - -z to -zz to support newer versions of rsync
|
138
|
+
- Allow overriding rsync flags via ```rsync_flags``` and ```rsync_compression```
|
139
|
+
|
140
|
+
### 0.7.0
|
141
|
+
|
142
|
+
- Add thor file generators
|
143
|
+
|
144
|
+
### 0.6.0
|
145
|
+
|
146
|
+
- Support MySQL
|
147
|
+
|
107
148
|
## Contributing
|
108
149
|
|
109
150
|
1. Fork it ( https://github.com/[my-github-username]/cloner/fork )
|
data/lib/cloner/ar.rb
CHANGED
@@ -1,15 +1,35 @@
|
|
1
1
|
module Cloner::Ar
|
2
|
-
def
|
2
|
+
def read_ar_conf
|
3
3
|
@conf ||= begin
|
4
|
-
YAML.load_file(Rails.root.join('config', 'database.yml'))[
|
4
|
+
YAML.load_file(Rails.root.join('config', 'database.yml'))[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')}")
|
@@ -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
@@ -1,8 +1,21 @@
|
|
1
1
|
module Cloner::RSync
|
2
2
|
extend ActiveSupport::Concern
|
3
|
-
|
3
|
+
|
4
|
+
def rsync_compression
|
5
|
+
"-zz"
|
6
|
+
end
|
7
|
+
|
8
|
+
def rsync_flags
|
4
9
|
port = ssh_opts[:port] || 22
|
5
|
-
|
10
|
+
"#{rsync_compression} -utvr --checksum -e \"ssh -p #{port}\""
|
11
|
+
end
|
12
|
+
|
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}"
|
6
19
|
puts "Running RSync: #{cmd}"
|
7
20
|
pipe = IO.popen(cmd)
|
8
21
|
while (line = pipe.gets)
|
@@ -11,6 +24,9 @@ module Cloner::RSync
|
|
11
24
|
pipe.close
|
12
25
|
ret = $?.to_i
|
13
26
|
if ret != 0
|
27
|
+
if raise_on_error
|
28
|
+
raise "Error: local command exited with #{ret}"
|
29
|
+
end
|
14
30
|
puts "Error: local command exited with #{ret}"
|
15
31
|
end
|
16
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.10.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-02-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -88,10 +88,8 @@ extensions: []
|
|
88
88
|
extra_rdoc_files: []
|
89
89
|
files:
|
90
90
|
- ".gitignore"
|
91
|
-
- ".ruby-gemset"
|
92
91
|
- ".ruby-version"
|
93
92
|
- Gemfile
|
94
|
-
- HISTORY.md
|
95
93
|
- LICENSE.txt
|
96
94
|
- README.md
|
97
95
|
- Rakefile
|
@@ -113,7 +111,7 @@ homepage: https://github.com/rs-pro/cloner
|
|
113
111
|
licenses:
|
114
112
|
- MIT
|
115
113
|
metadata: {}
|
116
|
-
post_install_message:
|
114
|
+
post_install_message:
|
117
115
|
rdoc_options: []
|
118
116
|
require_paths:
|
119
117
|
- lib
|
@@ -129,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
129
127
|
version: '0'
|
130
128
|
requirements: []
|
131
129
|
rubygems_version: 3.0.3
|
132
|
-
signing_key:
|
130
|
+
signing_key:
|
133
131
|
specification_version: 4
|
134
132
|
summary: Easily clone your production Mongoid database and files for local development
|
135
133
|
test_files: []
|
data/.ruby-gemset
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
cloner
|
data/HISTORY.md
DELETED