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 +4 -4
- data/lib/backup/database/remote_mysql.rb +3 -1
- data/lib/backup/remote/command.rb +47 -41
- data/lib/backup/utilities.rb +32 -0
- data/lib/backup/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2f73d688f49424946ba926eff0541054f9946dae
|
4
|
+
data.tar.gz: b0d632be9cfca6dd4355aba0019307b894daea1b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
11
|
+
include SSHKit::DSL
|
13
12
|
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
|
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
|
-
|
20
|
-
|
18
|
+
#srv = ssh_user+'@'+hostname
|
19
|
+
all_servers = [host]
|
21
20
|
|
22
|
-
|
21
|
+
output = ''
|
23
22
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
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
|
-
|
34
|
-
end
|
31
|
+
#
|
32
|
+
return { res: 1, output: output }
|
35
33
|
|
36
|
-
|
37
|
-
|
38
|
-
|
34
|
+
rescue => e
|
35
|
+
{
|
36
|
+
res: 0,
|
37
|
+
output: output,
|
38
|
+
error: e.message
|
39
|
+
}
|
40
|
+
end
|
39
41
|
|
40
|
-
|
41
|
-
|
42
|
-
|
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
|
-
|
46
|
+
on host do |host|
|
47
|
+
execute("#{cmd}", interaction_handler: handler)
|
48
|
+
end
|
46
49
|
|
47
|
-
|
48
|
-
|
49
|
-
res: 0,
|
50
|
-
error: e.message
|
51
|
-
}
|
52
|
-
end
|
50
|
+
#
|
51
|
+
return {res: 1, output: ""}
|
53
52
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
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
|
|
data/lib/backup/utilities.rb
CHANGED
@@ -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
|
data/lib/backup/version.rb
CHANGED