backup-remote 0.0.12 → 0.0.13

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: d4379e0693acbedd3bcb5c275a10470cb5959ebb
4
- data.tar.gz: 729a39f66fd3a3cf07f670025309fd00bb148c80
3
+ metadata.gz: 2f73d688f49424946ba926eff0541054f9946dae
4
+ data.tar.gz: b0d632be9cfca6dd4355aba0019307b894daea1b
5
5
  SHA512:
6
- metadata.gz: 11e8f455c85912b2903901cac87cbb2b1a115b8c7bb6b44c6ac523c4301f220a05f0c9b0af8264ff157b5439623b3933721881bebc05085bd64f147b1fe80a52
7
- data.tar.gz: 6cae404e2d3fa1f8078b4502b15b3c5f98ca08ef7d45ee0c35dd4edf5526ff4fe959d014aca584399ce3821ffbef35fe35c7f15fd6e8f74842b6a2056674110f
6
+ metadata.gz: 99987d967fdc2c3010b9d9608c3eedf42a193daf80315a1132830e26392e4b89dbc6b650d3cbf25e8889d30e5902cb7b9de6ef08bf94e06bc748cce3be304930
7
+ data.tar.gz: 0a2ddf605d64b30b500b9a36b03d39035300369efacedc3dce4160747e62d3881254673de99ea595b6c88e70bb69351de89d183e5afef54b0e53faeb1dffa125
@@ -145,7 +145,9 @@ module Backup
145
145
  private
146
146
 
147
147
  def mysqldump
148
- "#{ utility(:mysqldump) } #{ user_options } #{ credential_options } " +
148
+ #"#{ utility(:mysqldump) } #{ user_options } #{ credential_options } " +
149
+ u = utility_remote(:mysqldump, server_host, server_ssh_user, server_ssh_password)
150
+ "#{u} #{ user_options } #{ credential_options } " +
149
151
  "#{ connectivity_options } #{ name_option } " +
150
152
  "#{ tables_to_dump } #{ tables_to_skip }"
151
153
  end
@@ -6,60 +6,66 @@ require 'sshkit/sudo'
6
6
 
7
7
  module Backup
8
8
  module Remote
9
-
10
9
  class Command
11
10
 
12
- include SSHKit::DSL
11
+ include SSHKit::DSL
13
12
 
14
13
 
15
- def run_ssh_cmd(hostname, ssh_user, ssh_pass, cmd)
16
- host = SSHKit::Host.new({hostname: hostname, user: ssh_user})
17
- host.password = ssh_pass
14
+ def run_ssh_cmd(hostname, ssh_user, ssh_pass, cmd)
15
+ host = SSHKit::Host.new({hostname: hostname, user: ssh_user})
16
+ host.password = ssh_pass
18
17
 
19
- #srv = ssh_user+'@'+hostname
20
- all_servers = [host]
18
+ #srv = ssh_user+'@'+hostname
19
+ all_servers = [host]
21
20
 
22
- output = ''
21
+ output = ''
23
22
 
24
- on all_servers do |srv|
25
- #SSHKit::Coordinator.new(host).each in: :sequence do
26
- as(user: ssh_user) do
27
- #execute(cmd)
28
- output = capture(cmd)
29
- end
30
- end
23
+ on all_servers do |srv|
24
+ #SSHKit::Coordinator.new(host).each in: :sequence do
25
+ as(user: ssh_user) do
26
+ #execute(cmd)
27
+ output = capture(cmd)
28
+ end
29
+ end
31
30
 
32
- #
33
- return { res: 1, output: output }
34
- end
31
+ #
32
+ return { res: 1, output: output }
35
33
 
36
- def run_ssh_cmd_sudo(hostname, ssh_user, ssh_pass, cmd, handler=nil)
37
- host = SSHKit::Host.new("#{ssh_user}@#{hostname}")
38
- host.password = ssh_pass
34
+ rescue => e
35
+ {
36
+ res: 0,
37
+ output: output,
38
+ error: e.message
39
+ }
40
+ end
39
41
 
40
- on host do |host|
41
- execute("#{cmd}", interaction_handler: handler)
42
- end
42
+ def run_ssh_cmd_sudo(hostname, ssh_user, ssh_pass, cmd, handler=nil)
43
+ host = SSHKit::Host.new("#{ssh_user}@#{hostname}")
44
+ host.password = ssh_pass
43
45
 
44
- #
45
- return {res: 1, output: ""}
46
+ on host do |host|
47
+ execute("#{cmd}", interaction_handler: handler)
48
+ end
46
49
 
47
- rescue => e
48
- {
49
- res: 0,
50
- error: e.message
51
- }
52
- end
50
+ #
51
+ return {res: 1, output: ""}
53
52
 
54
- def self.interaction_handler_pwd(user, pwd, host='')
55
- {
56
- "#{user}@#{host}'s password:" => "#{pwd}\n",
57
- /#{user}@#{host}'s password: */ => "#{pwd}\n",
58
- "password: " => "#{pwd}\n",
59
- "password:" => "#{pwd}\n",
60
- "Password: " => "#{pwd}\n",
61
- }
62
- end
53
+ rescue => e
54
+ {
55
+ res: 0,
56
+ error: e.message
57
+ }
58
+ end
59
+
60
+ def self.interaction_handler_pwd(user, pwd, host='')
61
+ {
62
+ "#{user}@#{host}'s password:" => "#{pwd}\n",
63
+ /#{user}@#{host}'s password: */ => "#{pwd}\n",
64
+ "password: " => "#{pwd}\n",
65
+ "password:" => "#{pwd}\n",
66
+ "Password: " => "#{pwd}\n",
67
+ }
68
+ end
63
69
 
64
70
 
65
71
 
@@ -115,6 +115,9 @@ module Backup
115
115
  @gnu_tar = !!run("#{ utility(:tar) } --version").match(/GNU/)
116
116
  end
117
117
 
118
+
119
+
120
+
118
121
  private
119
122
 
120
123
  ##
@@ -135,6 +138,8 @@ module Backup
135
138
  UTILITY[name].dup
136
139
  end
137
140
 
141
+
142
+
138
143
  ##
139
144
  # Returns the name of the command name from the given command line.
140
145
  # This is only used to simplify log messages.
@@ -217,6 +222,33 @@ module Backup
217
222
  define_method name, lambda {|arg| Utilities.send(name, arg) }
218
223
  private name
219
224
  end
225
+
226
+ ##
227
+ # Returns the full path to the specified utility.
228
+ # Raises an error if utility can not be found in the system's $PATH
229
+ def utility_remote(name, hostname, server_ssh_user, server_ssh_password)
230
+ name = name.to_s.strip
231
+ raise Error, 'Utility Name Empty' if name.empty?
232
+
233
+ req = Backup::Remote::Command.new
234
+ cmd = %Q(which '#{ name }' 2>/dev/null)
235
+ res = req.run_ssh_cmd(server_host, server_ssh_user, server_ssh_password, cmd)
236
+ output = res[:output].chomp
237
+
238
+ raise Error, <<-EOS if res[:res]==0 || output.empty?
239
+ Could not locate '#{ name }'.
240
+ Make sure the specified utility is installed
241
+ and available in your system's $PATH, or specify it's location
242
+ in your 'config.rb' file using Backup::Utilities.configure
243
+ EOS
244
+
245
+
246
+ UTILITY[name] ||= output
247
+
248
+
249
+ UTILITY[name].dup
250
+ end
251
+
220
252
  private
221
253
  def gnu_tar?; Utilities.gnu_tar?; end
222
254
  end
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Backup
4
- VERSION = '0.0.12'
4
+ VERSION = '0.0.13'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: backup-remote
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max Ivak, Michael van Rooijen