cloner 0.5.7 → 0.9.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 +5 -5
- data/.ruby-version +1 -1
- data/LICENSE.txt +1 -1
- data/README.md +85 -31
- data/cloner.gemspec +2 -2
- data/lib/cloner.rb +10 -6
- data/lib/cloner/ar.rb +54 -0
- data/lib/cloner/internal.rb +3 -1
- data/lib/cloner/mysql.rb +77 -0
- data/lib/cloner/postgres.rb +25 -35
- data/lib/cloner/rsync.rb +19 -3
- data/lib/cloner/version.rb +1 -1
- data/lib/generators/cloner_generator.rb +25 -0
- data/lib/generators/templates/cloner_base.template +29 -0
- data/lib/generators/templates/cloner_extend.thor.erb +72 -0
- metadata +19 -16
- data/.ruby-gemset +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 652e0cb307e408f626c4376e97480acb8bb830f3463b7272befe0eb8b6cd9b2c
|
4
|
+
data.tar.gz: 825b8ea077f10294d0a561ef75d751e4f85e0109935cafb51ec92de7bd1d74e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 87ab8f908f2c9428f39bf8a2d536a54b647b4eac6393aa07c9ebe4db2149226f0d80bed75f46eb25c1359f03e097ac036cde83b847bed9e21d62c26be724d23c
|
7
|
+
data.tar.gz: 5b172cfb19ad692494218221ac0ca0dae3ebbabab08978fdaf314e911bcf334d2fd6db47ce600ebf426f0df6ff8409a9542058e9d36461d269a349b57e416b2f
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
ruby-2.6.6
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
# Cloner
|
2
2
|
|
3
|
-
Easily clone your production Mongoid or PostgreSQL database and files for local development or staging area.
|
3
|
+
Easily clone your production Mongoid or PostgreSQL / MySQL database and files for local development or staging area.
|
4
|
+
|
5
|
+
Uses rsync and database-specific default dump/restore tools (pg_dump/pg_restore, mysqldump/mysql, mongodump/mongorestore)
|
6
|
+
|
4
7
|
|
5
8
|
## Installation
|
6
9
|
|
@@ -20,37 +23,44 @@ Or install it yourself as:
|
|
20
23
|
|
21
24
|
## Usage
|
22
25
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
end
|
38
|
-
def remote_dump_path
|
39
|
-
'/data/tea/dump'
|
40
|
-
end
|
41
|
-
def remote_app_path
|
42
|
-
"/data/tea/app/current"
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
desc "download", "clone files and DB from production"
|
47
|
-
def download
|
48
|
-
load_env
|
49
|
-
clone_db
|
50
|
-
rsync_public("ckeditor_assets")
|
51
|
-
rsync_public("uploads")
|
52
|
-
end
|
26
|
+
For generate cloner base template, run:
|
27
|
+
|
28
|
+
```
|
29
|
+
bundle exec rails generate cloner
|
30
|
+
```
|
31
|
+
|
32
|
+
This is create `lib/tasks/dl.thor` file with following content:
|
33
|
+
```ruby
|
34
|
+
require 'cloner'
|
35
|
+
|
36
|
+
class Dl < Cloner::Base
|
37
|
+
no_commands do
|
38
|
+
def rails_path
|
39
|
+
File.expand_path("../../../config/environment", __FILE__)
|
53
40
|
end
|
41
|
+
def ssh_host
|
42
|
+
'hottea.ru'
|
43
|
+
end
|
44
|
+
def ssh_user
|
45
|
+
'tea'
|
46
|
+
end
|
47
|
+
def remote_dump_path
|
48
|
+
'/data/tea/dump'
|
49
|
+
end
|
50
|
+
def remote_app_path
|
51
|
+
"/data/tea/app/current"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
desc "download", "clone files and DB from production"
|
56
|
+
def download
|
57
|
+
load_env
|
58
|
+
clone_db
|
59
|
+
rsync_public("ckeditor_assets")
|
60
|
+
rsync_public("uploads")
|
61
|
+
end
|
62
|
+
end
|
63
|
+
```
|
54
64
|
|
55
65
|
Adjust it to your project and deployment.
|
56
66
|
|
@@ -58,6 +68,30 @@ Run it:
|
|
58
68
|
|
59
69
|
thor dl
|
60
70
|
|
71
|
+
|
72
|
+
If you generate extended cloner template as: `rails g cloner -e`,
|
73
|
+
you can run `thor dl` with additional parameters, for example:
|
74
|
+
```
|
75
|
+
bundle exec thor dl -D # For skip clone database
|
76
|
+
bundle exec thor dl -F # For skip clone files
|
77
|
+
```
|
78
|
+
|
79
|
+
For details see help:
|
80
|
+
```
|
81
|
+
bundle exec thor help dl:download
|
82
|
+
|
83
|
+
Usage:
|
84
|
+
thor dl:download
|
85
|
+
|
86
|
+
Options:
|
87
|
+
[--from=FROM] # stage name where cloner get data
|
88
|
+
# Default: production
|
89
|
+
-D, [--skip-database], [--no-skip-database] # skip clone database
|
90
|
+
-F, [--skip-files], [--no-skip-files] # skip clone files
|
91
|
+
|
92
|
+
clone files and DB from production
|
93
|
+
```
|
94
|
+
|
61
95
|
## Additional
|
62
96
|
|
63
97
|
All functions from cloner/internal.rb can be overriden, for example:
|
@@ -73,6 +107,26 @@ All functions from cloner/internal.rb can be overriden, for example:
|
|
73
107
|
{}
|
74
108
|
end
|
75
109
|
|
110
|
+
## Changelog
|
111
|
+
|
112
|
+
### 0.9.0
|
113
|
+
|
114
|
+
- Add option to rsync to allow sync one file (thx @AnatolyShirykalov)
|
115
|
+
- Add env_database to allow overriding database env (thx @Yarroo)
|
116
|
+
|
117
|
+
### 0.8.0
|
118
|
+
|
119
|
+
- Change default rsync flags - -z to -zz to support newer versions of rsync
|
120
|
+
- Allow overriding rsync flags via ```rsync_flags``` and ```rsync_compression```
|
121
|
+
|
122
|
+
### 0.7.0
|
123
|
+
|
124
|
+
- Add thor file generators
|
125
|
+
|
126
|
+
### 0.6.0
|
127
|
+
|
128
|
+
- Support MySQL
|
129
|
+
|
76
130
|
## Contributing
|
77
131
|
|
78
132
|
1. Fork it ( https://github.com/[my-github-username]/cloner/fork )
|
data/cloner.gemspec
CHANGED
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_dependency "activesupport"
|
23
23
|
spec.add_dependency 'net-ssh'
|
24
24
|
|
25
|
-
spec.add_development_dependency "bundler"
|
26
|
-
spec.add_development_dependency "rake"
|
25
|
+
spec.add_development_dependency "bundler"
|
26
|
+
spec.add_development_dependency "rake"
|
27
27
|
end
|
28
28
|
|
data/lib/cloner.rb
CHANGED
@@ -1,10 +1,14 @@
|
|
1
1
|
require "cloner/version"
|
2
2
|
require 'thor'
|
3
3
|
require 'active_support/concern'
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
module Cloner
|
5
|
+
autoload :Base, "cloner/base"
|
6
|
+
autoload :Internal, "cloner/internal"
|
7
|
+
autoload :Ar, "cloner/ar"
|
8
|
+
autoload :MongoDB, "cloner/mongodb"
|
9
|
+
autoload :Postgres, "cloner/postgres"
|
10
|
+
autoload :MySQL, "cloner/mysql"
|
11
|
+
autoload :SSH, "cloner/ssh"
|
12
|
+
autoload :RSync, "cloner/rsync"
|
13
|
+
end
|
10
14
|
|
data/lib/cloner/ar.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
module Cloner::Ar
|
2
|
+
def ar_conf
|
3
|
+
@conf ||= begin
|
4
|
+
YAML.load_file(Rails.root.join('config', 'database.yml'))[env_database]
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
def env_database
|
9
|
+
Rails.env
|
10
|
+
end
|
11
|
+
|
12
|
+
def ar_to
|
13
|
+
ar_conf['database']
|
14
|
+
end
|
15
|
+
|
16
|
+
def ar_r_conf
|
17
|
+
@ar_r_conf ||= begin
|
18
|
+
do_ssh do |ssh|
|
19
|
+
ret = ssh_exec!(ssh, "cat #{e(remote_app_path + '/config/database.yml')}")
|
20
|
+
check_ssh_err(ret)
|
21
|
+
begin
|
22
|
+
res = YAML.load(ret[0])[env_from]
|
23
|
+
raise 'no data' if res.blank?
|
24
|
+
#res['host'] ||= '127.0.0.1'
|
25
|
+
rescue Exception => e
|
26
|
+
puts "unable to read remote database.yml for env #{env_from}."
|
27
|
+
puts "Remote file contents:"
|
28
|
+
puts ret[0]
|
29
|
+
end
|
30
|
+
res
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def clone_ar
|
36
|
+
if ar_conf["adapter"] != ar_r_conf["adapter"]
|
37
|
+
puts "Error: ActiveRecord adapter mismatch: local #{ar_conf["adapter"]}, remote #{ar_r_conf["adapter"]}"
|
38
|
+
puts "it is not possible to convert from one database to another via this tool."
|
39
|
+
exit
|
40
|
+
end
|
41
|
+
|
42
|
+
case ar_conf["adapter"]
|
43
|
+
when 'postgresql'
|
44
|
+
clone_pg
|
45
|
+
when 'mysql2'
|
46
|
+
clone_my
|
47
|
+
else
|
48
|
+
puts "unknown activerecord adapter: #{ar_conf["adapter"]}"
|
49
|
+
puts "currently supported adapters: mysql2, postgresql"
|
50
|
+
exit
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
data/lib/cloner/internal.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
module Cloner::Internal
|
2
2
|
extend ActiveSupport::Concern
|
3
3
|
include Cloner::MongoDB
|
4
|
+
include Cloner::Ar
|
4
5
|
include Cloner::Postgres
|
6
|
+
include Cloner::MySQL
|
5
7
|
include Cloner::SSH
|
6
8
|
include Cloner::RSync
|
7
9
|
|
@@ -27,7 +29,7 @@ module Cloner::Internal
|
|
27
29
|
if defined?(Mongoid)
|
28
30
|
clone_mongodb
|
29
31
|
else
|
30
|
-
|
32
|
+
clone_ar
|
31
33
|
end
|
32
34
|
end
|
33
35
|
end
|
data/lib/cloner/mysql.rb
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
module Cloner::MySQL
|
2
|
+
def my_local_auth
|
3
|
+
if ar_conf['password'].blank?
|
4
|
+
""
|
5
|
+
else
|
6
|
+
"--password='#{ar_conf['password']}'"
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def my_remote_auth
|
11
|
+
if ar_r_conf['password'].blank?
|
12
|
+
""
|
13
|
+
else
|
14
|
+
"--password='#{ar_r_conf['password']}'"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def my_dump_param
|
19
|
+
"--add-drop-table"
|
20
|
+
end
|
21
|
+
|
22
|
+
def my_restore_param
|
23
|
+
""
|
24
|
+
end
|
25
|
+
|
26
|
+
def my_bin_path(util)
|
27
|
+
util
|
28
|
+
end
|
29
|
+
|
30
|
+
def my_dump_remote
|
31
|
+
puts "backup remote DB via ssh"
|
32
|
+
do_ssh do |ssh|
|
33
|
+
ssh.exec!("rm -R #{e remote_dump_path}")
|
34
|
+
ret = ssh_exec!(ssh, "mkdir -p #{e remote_dump_path}")
|
35
|
+
check_ssh_err(ret)
|
36
|
+
host = ar_r_conf['host'].present? ? " --host #{e ar_r_conf['host']}" : ""
|
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 + '/cloner.sql')}"
|
39
|
+
puts dump if verbose?
|
40
|
+
ret = ssh_exec!(ssh, dump)
|
41
|
+
check_ssh_err(ret)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def my_dump_restore
|
46
|
+
puts "restoring DB"
|
47
|
+
host = ar_conf['host'].present? ? " --host #{e ar_conf['host']}" : ""
|
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 + '/cloner.sql')}"
|
50
|
+
puts restore if verbose?
|
51
|
+
pipe = IO.popen(restore)
|
52
|
+
while (line = pipe.gets)
|
53
|
+
print line if verbose?
|
54
|
+
end
|
55
|
+
ret = $?.to_i
|
56
|
+
if ret != 0
|
57
|
+
puts "Error: local command exited with #{ret}"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def my_path
|
62
|
+
Rails.root.join("tmp", "dump").to_s
|
63
|
+
end
|
64
|
+
|
65
|
+
def my_dump_copy
|
66
|
+
FileUtils.mkdir_p(my_path)
|
67
|
+
`mkdir -p #{e my_path}`
|
68
|
+
rsync(remote_dump_path, my_path)
|
69
|
+
end
|
70
|
+
|
71
|
+
def clone_my
|
72
|
+
my_dump_remote()
|
73
|
+
my_dump_copy()
|
74
|
+
my_dump_restore()
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
data/lib/cloner/postgres.rb
CHANGED
@@ -1,37 +1,8 @@
|
|
1
1
|
module Cloner::Postgres
|
2
2
|
extend ActiveSupport::Concern
|
3
3
|
|
4
|
-
def ar_conf
|
5
|
-
@conf ||= begin
|
6
|
-
YAML.load_file(Rails.root.join('config', 'database.yml'))[Rails.env]
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
def ar_to
|
11
|
-
ar_conf['database']
|
12
|
-
end
|
13
|
-
|
14
|
-
def ar_r_conf
|
15
|
-
@ar_r_conf ||= begin
|
16
|
-
do_ssh do |ssh|
|
17
|
-
ret = ssh_exec!(ssh, "cat #{e(remote_app_path + '/config/database.yml')}")
|
18
|
-
check_ssh_err(ret)
|
19
|
-
begin
|
20
|
-
res = YAML.load(ret[0])[env_from]
|
21
|
-
raise 'no data' if res.blank?
|
22
|
-
#res['host'] ||= '127.0.0.1'
|
23
|
-
rescue Exception => e
|
24
|
-
puts "unable to read remote database.yml for env #{env_from}."
|
25
|
-
puts "Remote file contents:"
|
26
|
-
puts ret[0]
|
27
|
-
end
|
28
|
-
res
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
4
|
def pg_local_auth
|
34
|
-
if ar_conf['password'].
|
5
|
+
if ar_conf['password'].blank?
|
35
6
|
""
|
36
7
|
else
|
37
8
|
"PGPASSWORD='#{ar_conf['password']}' "
|
@@ -39,7 +10,7 @@ module Cloner::Postgres
|
|
39
10
|
end
|
40
11
|
|
41
12
|
def pg_remote_auth
|
42
|
-
if ar_r_conf['password'].
|
13
|
+
if ar_r_conf['password'].blank?
|
43
14
|
""
|
44
15
|
else
|
45
16
|
"PGPASSWORD='#{ar_r_conf['password']}' "
|
@@ -50,10 +21,29 @@ module Cloner::Postgres
|
|
50
21
|
""
|
51
22
|
end
|
52
23
|
|
24
|
+
def pg_dump_param
|
25
|
+
if pg_dump_extra != ""
|
26
|
+
puts "WARN pg_dump_extra is deprecated, use def pg_dump_param; super + ' extra'"
|
27
|
+
end
|
28
|
+
"-Fc #{pg_dump_extra}"
|
29
|
+
end
|
30
|
+
|
31
|
+
def pg_restore_param
|
32
|
+
"--no-owner -Fc -c"
|
33
|
+
end
|
34
|
+
|
53
35
|
def pg_bin_path(util)
|
54
36
|
util
|
55
37
|
end
|
56
38
|
|
39
|
+
def pg_local_bin_path(util)
|
40
|
+
pg_bin_path(util)
|
41
|
+
end
|
42
|
+
|
43
|
+
def pg_remote_bin_path(util)
|
44
|
+
pg_bin_path(util)
|
45
|
+
end
|
46
|
+
|
57
47
|
def pg_dump_remote
|
58
48
|
puts "backup remote DB via ssh"
|
59
49
|
do_ssh do |ssh|
|
@@ -62,7 +52,7 @@ module Cloner::Postgres
|
|
62
52
|
check_ssh_err(ret)
|
63
53
|
host = ar_r_conf['host'].present? ? " -h #{e ar_r_conf['host']}" : ""
|
64
54
|
port = ar_r_conf['port'].present? ? " -p #{e ar_r_conf['port']}" : ""
|
65
|
-
dump = pg_remote_auth + "#{
|
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 + '/tmp.bak')}"
|
66
56
|
puts dump if verbose?
|
67
57
|
ret = ssh_exec!(ssh, dump)
|
68
58
|
check_ssh_err(ret)
|
@@ -73,14 +63,14 @@ module Cloner::Postgres
|
|
73
63
|
puts "restoring DB"
|
74
64
|
host = ar_conf['host'].present? ? " -h #{e ar_conf['host']}" : ""
|
75
65
|
port = ar_conf['port'].present? ? " -p #{e ar_conf['port']}" : ""
|
76
|
-
restore = pg_local_auth + "#{
|
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 + '/tmp.bak')}"
|
77
67
|
puts restore if verbose?
|
78
68
|
pipe = IO.popen(restore)
|
79
69
|
while (line = pipe.gets)
|
80
70
|
print line if verbose?
|
81
71
|
end
|
82
72
|
ret = $?.to_i
|
83
|
-
if ret != 0
|
73
|
+
if ret != 0
|
84
74
|
puts "Error: local command exited with #{ret}"
|
85
75
|
end
|
86
76
|
end
|
@@ -92,7 +82,7 @@ module Cloner::Postgres
|
|
92
82
|
def pg_dump_copy
|
93
83
|
FileUtils.mkdir_p(pg_path)
|
94
84
|
`mkdir -p #{e pg_path}`
|
95
|
-
rsync(remote_dump_path
|
85
|
+
rsync(remote_dump_path, pg_path)
|
96
86
|
end
|
97
87
|
|
98
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.ends_with?('/')
|
16
|
+
to = "#{to}/" unless to.ends_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)
|
@@ -10,7 +23,10 @@ module Cloner::RSync
|
|
10
23
|
end
|
11
24
|
pipe.close
|
12
25
|
ret = $?.to_i
|
13
|
-
if ret != 0
|
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
@@ -0,0 +1,25 @@
|
|
1
|
+
class ClonerGenerator < Rails::Generators::Base
|
2
|
+
source_root File.expand_path('templates', __dir__)
|
3
|
+
|
4
|
+
class_option :extend, default: false, type: :boolean, aliases: '-e'
|
5
|
+
|
6
|
+
desc "This generator create lib/tasks/dl.thor"
|
7
|
+
def create_task_file
|
8
|
+
unless options[:extend]
|
9
|
+
create_default_task_file
|
10
|
+
else
|
11
|
+
create_extended_task_file
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
def create_default_task_file
|
17
|
+
copy_file 'cloner_base.template', 'lib/tasks/dl.thor'
|
18
|
+
end
|
19
|
+
|
20
|
+
def create_extended_task_file
|
21
|
+
say 'Create extend file'
|
22
|
+
@username = Rails.application.class.parent_name.downcase
|
23
|
+
template 'cloner_extend.thor.erb', 'lib/tasks/dl.thor'
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'cloner'
|
2
|
+
|
3
|
+
class Dl < Cloner::Base
|
4
|
+
no_commands do
|
5
|
+
def rails_path
|
6
|
+
File.expand_path("../../../config/environment", __FILE__)
|
7
|
+
end
|
8
|
+
def ssh_host
|
9
|
+
'hottea.ru'
|
10
|
+
end
|
11
|
+
def ssh_user
|
12
|
+
'tea'
|
13
|
+
end
|
14
|
+
def remote_dump_path
|
15
|
+
'/data/tea/dump'
|
16
|
+
end
|
17
|
+
def remote_app_path
|
18
|
+
"/data/tea/app/current"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
desc "download", "clone files and DB from production"
|
23
|
+
def download
|
24
|
+
load_env
|
25
|
+
clone_db
|
26
|
+
rsync_public("ckeditor_assets")
|
27
|
+
rsync_public("uploads")
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'cloner'
|
2
|
+
|
3
|
+
class Dl < Cloner::Base
|
4
|
+
no_commands do
|
5
|
+
def rails_path
|
6
|
+
File.expand_path("../../../config/environment", __FILE__)
|
7
|
+
end
|
8
|
+
def stages
|
9
|
+
@_stages ||= {
|
10
|
+
# TODO: Add new stages here if you needed
|
11
|
+
production: {
|
12
|
+
# TODO: Fix production settings
|
13
|
+
ssh_host: 'production.example.com',
|
14
|
+
ssh_user: '<%= @username %>'
|
15
|
+
},
|
16
|
+
staging: {
|
17
|
+
# TODO: Fix staging settings
|
18
|
+
ssh_host: 'production.example.com',
|
19
|
+
ssh_user: '<%= @username %>'
|
20
|
+
}
|
21
|
+
}
|
22
|
+
end
|
23
|
+
def ssh_host
|
24
|
+
stages.dig(options[:from].to_sym, :ssh_host)
|
25
|
+
end
|
26
|
+
def ssh_user
|
27
|
+
stages.dig(options[:from].to_sym, :ssh_user)
|
28
|
+
end
|
29
|
+
def remote_dump_path
|
30
|
+
# TODO: Fix remote dump path
|
31
|
+
'/data/<%= @username %>/dump'
|
32
|
+
end
|
33
|
+
def remote_app_path
|
34
|
+
# TODO: Fix remote app path
|
35
|
+
'/data/<%= @username %>/app/current'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class_option :from,
|
40
|
+
default: 'production',
|
41
|
+
type: :string,
|
42
|
+
desc: 'stage name where cloner get data'
|
43
|
+
class_option :skip_database,
|
44
|
+
default: false,
|
45
|
+
type: :boolean,
|
46
|
+
aliases: '-D',
|
47
|
+
desc: 'skip clone database'
|
48
|
+
class_option :skip_files,
|
49
|
+
default: false,
|
50
|
+
type: :boolean,
|
51
|
+
aliases: '-F',
|
52
|
+
desc: 'skip clone files'
|
53
|
+
|
54
|
+
desc "download", "clone files and DB from production"
|
55
|
+
def download
|
56
|
+
load_env
|
57
|
+
say "Clone from: #{options[:from]}", :green
|
58
|
+
if options[:skip_database]
|
59
|
+
say "Skip clone database!", :yellow
|
60
|
+
else
|
61
|
+
clone_db
|
62
|
+
end
|
63
|
+
|
64
|
+
if options[:skip_files]
|
65
|
+
say "Skip clone files!", :yellow
|
66
|
+
else
|
67
|
+
# TODO: Fix folders for synchronization here
|
68
|
+
rsync_public("ckeditor_assets")
|
69
|
+
rsync_public("uploads")
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
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.9.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: 2020-07-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -56,30 +56,30 @@ dependencies:
|
|
56
56
|
name: bundler
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rake
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '0'
|
83
83
|
description: ''
|
84
84
|
email:
|
85
85
|
- glebtv@gmail.com
|
@@ -88,7 +88,6 @@ extensions: []
|
|
88
88
|
extra_rdoc_files: []
|
89
89
|
files:
|
90
90
|
- ".gitignore"
|
91
|
-
- ".ruby-gemset"
|
92
91
|
- ".ruby-version"
|
93
92
|
- Gemfile
|
94
93
|
- LICENSE.txt
|
@@ -96,18 +95,23 @@ files:
|
|
96
95
|
- Rakefile
|
97
96
|
- cloner.gemspec
|
98
97
|
- lib/cloner.rb
|
98
|
+
- lib/cloner/ar.rb
|
99
99
|
- lib/cloner/base.rb
|
100
100
|
- lib/cloner/internal.rb
|
101
101
|
- lib/cloner/mongodb.rb
|
102
|
+
- lib/cloner/mysql.rb
|
102
103
|
- lib/cloner/postgres.rb
|
103
104
|
- lib/cloner/rsync.rb
|
104
105
|
- lib/cloner/ssh.rb
|
105
106
|
- lib/cloner/version.rb
|
107
|
+
- lib/generators/cloner_generator.rb
|
108
|
+
- lib/generators/templates/cloner_base.template
|
109
|
+
- lib/generators/templates/cloner_extend.thor.erb
|
106
110
|
homepage: https://github.com/rs-pro/cloner
|
107
111
|
licenses:
|
108
112
|
- MIT
|
109
113
|
metadata: {}
|
110
|
-
post_install_message:
|
114
|
+
post_install_message:
|
111
115
|
rdoc_options: []
|
112
116
|
require_paths:
|
113
117
|
- lib
|
@@ -122,9 +126,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
122
126
|
- !ruby/object:Gem::Version
|
123
127
|
version: '0'
|
124
128
|
requirements: []
|
125
|
-
|
126
|
-
|
127
|
-
signing_key:
|
129
|
+
rubygems_version: 3.1.3
|
130
|
+
signing_key:
|
128
131
|
specification_version: 4
|
129
132
|
summary: Easily clone your production Mongoid database and files for local development
|
130
133
|
test_files: []
|
data/.ruby-gemset
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
cloner
|