cloner 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ad4ce3ece2b17ced4d179da7bfdc37494e5342e6
4
- data.tar.gz: 02aac9260349ecb47b60a475100fa0fa72210a53
3
+ metadata.gz: cea32c10a5456a2af0d37b26384e651e1234f16d
4
+ data.tar.gz: ffcd5ad320f56b8ea5e627f751e677af51647edd
5
5
  SHA512:
6
- metadata.gz: 7ee9e31b738b36af8c6aa0326019e1c4f55231b8f0d818431754fca63d4bebae3f39975147ac5040fc091c4094d8763eb6dc14825c4a99b88b8ad0bda81dfdef
7
- data.tar.gz: 12f1d24e1e6b2471c12faaca671c5c66e5710fb3bfae56953d4b755979a571149e0bbbb23d2a3a12791f1960fe19a33029cbea835d970a22293053f1c3cf8c91
6
+ metadata.gz: 84ce1cfcd5e9875cbb06aee952fab09413fd99bbe128d86d5c0e9264f5a5af1784be4b3e49737e72c6a4acc2f421e33fcfb6e82b42aba59fb06c2c3f672eecc1
7
+ data.tar.gz: 1eb36edc996a3f00a1985af522f474644dc092a389d33f624b85d3212338210f4047ebaa221f3dcf92b5fb065756db547b087be320661ca81d9dd4674f756209
@@ -5,6 +5,10 @@ module Cloner::Internal
5
5
  include Cloner::SSH
6
6
  include Cloner::RSync
7
7
 
8
+ def e(str)
9
+ Shellwords.escape(str)
10
+ end
11
+
8
12
  def load_env
9
13
  unless defined?(Rails)
10
14
  require rails_path
@@ -14,7 +14,7 @@ module Cloner::MongoDB
14
14
  def mongodb_r_conf
15
15
  @r_conf ||= begin
16
16
  Net::SSH.start(ssh_host, ssh_user, ssh_opts) do |ssh|
17
- ret = ssh_exec!(ssh, "cat #{remote_app_path}/config/mongoid.yml")
17
+ ret = ssh_exec!(ssh, "cat #{e(remote_app_path + '/config/mongoid.yml')}")
18
18
  check_ssh_err(ret)
19
19
  YAML.load(ret[0])[env_from]['sessions']['default']
20
20
  end
@@ -25,7 +25,7 @@ module Cloner::MongoDB
25
25
  if mongodb_conf['password'].nil?
26
26
  ""
27
27
  else
28
- "-u #{mongodb_conf['username']} -p #{mongodb_conf['password']}"
28
+ "-u #{e mongodb_conf['username']} -p #{e mongodb_conf['password']}"
29
29
  end
30
30
  end
31
31
 
@@ -35,7 +35,7 @@ module Cloner::MongoDB
35
35
  ssh.exec!("rm -R #{remote_dump_path}")
36
36
  ret = ssh_exec!(ssh, "mkdir -p #{remote_dump_path}")
37
37
  check_ssh_err(ret)
38
- dump = "mongodump -u #{mongodb_r_conf['username']} -p #{mongodb_r_conf['password']} -d #{mongodb_r_conf['database']} --authenticationDatabase #{mongodb_r_conf['database']} -o #{remote_dump_path}"
38
+ dump = "mongodump -u #{e mongodb_r_conf['username']} -p #{e mongodb_r_conf['password']} -d #{e mongodb_r_conf['database']} --authenticationDatabase #{e mongodb_r_conf['database']} -o #{e remote_dump_path}"
39
39
  puts dump if verbose?
40
40
  ret = ssh_exec!(ssh, dump)
41
41
  check_ssh_err(ret)
@@ -44,7 +44,7 @@ module Cloner::MongoDB
44
44
 
45
45
  def mongodb_dump_restore
46
46
  puts "restoring DB"
47
- restore = "mongorestore --drop -d #{mongodb_to} #{mongodb_local_auth} #{mongodb_path}"
47
+ restore = "mongorestore --drop -d #{e mongodb_to} #{mongodb_local_auth} #{e mongodb_path}"
48
48
  puts restore if verbose?
49
49
  pipe = IO.popen(restore)
50
50
  while (line = pipe.gets)
@@ -8,16 +8,17 @@ module Cloner::Postgres
8
8
  end
9
9
 
10
10
  def ar_to
11
- p ar_conf
12
11
  ar_conf['database']
13
12
  end
14
13
 
15
14
  def ar_r_conf
16
15
  @ar_r_conf ||= begin
17
16
  Net::SSH.start(ssh_host, ssh_user, ssh_opts) do |ssh|
18
- ret = ssh_exec!(ssh, "cat #{remote_app_path}/config/database.yml")
17
+ ret = ssh_exec!(ssh, "cat #{e(remote_app_path + '/config/database.yml')}")
19
18
  check_ssh_err(ret)
20
- YAML.load(ret[0])[env_from]
19
+ res = YAML.load(ret[0])[env_from]
20
+ res['host'] ||= '127.0.0.1'
21
+ res
21
22
  end
22
23
  end
23
24
  end
@@ -41,10 +42,10 @@ module Cloner::Postgres
41
42
  def pg_dump_remote
42
43
  puts "backup remote DB via ssh"
43
44
  Net::SSH.start(ssh_host, ssh_user, ssh_opts) do |ssh|
44
- ssh.exec!("rm -R #{remote_dump_path}")
45
- ret = ssh_exec!(ssh, "mkdir -p #{remote_dump_path}")
45
+ ssh.exec!("rm -R #{e remote_dump_path}")
46
+ ret = ssh_exec!(ssh, "mkdir -p #{e remote_dump_path}")
46
47
  check_ssh_err(ret)
47
- dump = pg_remote_auth + "pg_dump -Fc -U #{ar_r_conf['username']} #{ar_r_conf['database']} > #{remote_dump_path}/tmp.bak"
48
+ dump = pg_remote_auth + "pg_dump -Fc -U #{e ar_r_conf['username']} -h #{e ar_r_conf['host']} #{e ar_r_conf['database']} > #{e(remote_dump_path + '/tmp.bak')}"
48
49
  puts dump if verbose?
49
50
  ret = ssh_exec!(ssh, dump)
50
51
  check_ssh_err(ret)
@@ -53,7 +54,7 @@ module Cloner::Postgres
53
54
 
54
55
  def pg_dump_restore
55
56
  puts "restoring DB"
56
- restore = pg_local_auth + "pg_restore -Fc -c -U #{ar_conf['username']} -d #{ar_to} #{pg_path}/tmp.bak"
57
+ restore = pg_local_auth + "pg_restore -Fc -c -U #{e ar_conf['username']} -d #{e ar_to} #{e(pg_path + '/tmp.bak')}"
57
58
  puts restore
58
59
  puts restore if verbose?
59
60
  pipe = IO.popen(restore)
@@ -72,8 +73,8 @@ module Cloner::Postgres
72
73
 
73
74
  def pg_dump_copy
74
75
  FileUtils.mkdir_p(pg_path)
75
- `mkdir -p #{pg_path}`
76
- rsync("#{remote_dump_path}/", pg_path)
76
+ `mkdir -p #{e pg_path}`
77
+ rsync(remote_dump_path + '/', pg_path)
77
78
  end
78
79
 
79
80
  def clone_pg
data/lib/cloner/rsync.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module Cloner::RSync
2
2
  extend ActiveSupport::Concern
3
3
  def rsync(from, to)
4
- cmd = "rsync -e ssh -zutvr --checksum #{ssh_user}@#{ssh_host}:#{from}/ #{to}/"
4
+ cmd = "rsync -e ssh -zutvr --checksum #{e ssh_user}@#{e ssh_host}:#{e from}/ #{e to}/"
5
5
  puts "Running RSync: #{cmd}"
6
6
  pipe = IO.popen(cmd)
7
7
  while (line = pipe.gets)
@@ -1,3 +1,3 @@
1
1
  module Cloner
2
- VERSION = "0.3.1"
2
+ VERSION = "0.4.0"
3
3
  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.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - glebtv
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-02 00:00:00.000000000 Z
11
+ date: 2015-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -123,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
123
  version: '0'
124
124
  requirements: []
125
125
  rubyforge_project:
126
- rubygems_version: 2.4.4
126
+ rubygems_version: 2.4.5
127
127
  signing_key:
128
128
  specification_version: 4
129
129
  summary: Easily clone your production Mongoid database and files for local development