backup-remote 0.0.16 → 0.0.17
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 +4 -4
- data/lib/backup/database/remote_mysql.rb +29 -4
- data/lib/backup/remote/command.rb +28 -14
- data/lib/backup/remote_archive.rb +29 -11
- data/lib/backup/remote_data.rb +37 -21
- data/lib/backup/utilities.rb +2 -5
- data/lib/backup/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 60dcb5cc5bb3e4b58fa3c5ee62da0b1c75eac09e
|
4
|
+
data.tar.gz: c4ab9f0eebfd1cb916159ef874159e8ccb6f1bc5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ed749efeaded026be7c9eb989ac2c9fa8c9429aee4a852bfc2d0ee5dd77d25f69bd0e92e344ce9d4d6799f9289f4d36c0ea7deb8c27fb65460c6d8bbb870e3e
|
7
|
+
data.tar.gz: dfaaab1e3547f58fd5c37204cdc6293cd151870b25ac97556a9c8d40bf68069e640cdc26aa55b0a53944822aafef7c67b214810aa000d953e1e6fef8ecd3d1ed
|
@@ -15,9 +15,12 @@ module Backup
|
|
15
15
|
|
16
16
|
# server options
|
17
17
|
attr_accessor :server_host
|
18
|
+
attr_accessor :server_ssh_options
|
19
|
+
attr_accessor :server_ssh_port
|
18
20
|
attr_accessor :server_ssh_user
|
19
21
|
attr_accessor :server_ssh_password
|
20
22
|
attr_accessor :server_ssh_key
|
23
|
+
|
21
24
|
attr_accessor :server_backup_path
|
22
25
|
|
23
26
|
|
@@ -93,6 +96,8 @@ module Backup
|
|
93
96
|
def perform!
|
94
97
|
super
|
95
98
|
|
99
|
+
# prepare
|
100
|
+
build_server_ssh_options
|
96
101
|
|
97
102
|
#
|
98
103
|
pipeline = Pipeline.new
|
@@ -114,17 +119,18 @@ module Backup
|
|
114
119
|
# generate backup on remote server
|
115
120
|
cmd_remote = pipeline.commands.join(" | ")
|
116
121
|
|
122
|
+
|
117
123
|
remote = Backup::Remote::Command.new
|
118
|
-
res_generate = remote.run_ssh_cmd(server_host,
|
124
|
+
res_generate = remote.run_ssh_cmd(server_host, server_ssh_options, cmd_remote)
|
119
125
|
|
120
126
|
if res_generate[:res]==0
|
121
|
-
raise
|
127
|
+
raise "Cannot create backup on server. #{res_generate[:error]}"
|
122
128
|
end
|
123
129
|
|
124
130
|
# download backup
|
125
131
|
dump_file = File.join(dump_path, dump_filename+"."+dump_ext)
|
126
132
|
|
127
|
-
res_download = remote.ssh_download_file(server_host,
|
133
|
+
res_download = remote.ssh_download_file(server_host, server_ssh_options, dump_remote_file, dump_file)
|
128
134
|
|
129
135
|
if res_download[:res]==0
|
130
136
|
raise 'Cannot download file from server'
|
@@ -142,11 +148,30 @@ module Backup
|
|
142
148
|
#end
|
143
149
|
end
|
144
150
|
|
151
|
+
def build_server_ssh_options
|
152
|
+
ssh_options = {}
|
153
|
+
v = self.server_ssh_user
|
154
|
+
ssh_options[:user] = v if v
|
155
|
+
|
156
|
+
|
157
|
+
v = self.server_ssh_password
|
158
|
+
ssh_options[:password] = v if v
|
159
|
+
|
160
|
+
v = self.server_ssh_key
|
161
|
+
ssh_options[:key] = v if v
|
162
|
+
|
163
|
+
v = self.server_ssh_port
|
164
|
+
ssh_options[:port] = v if v
|
165
|
+
|
166
|
+
|
167
|
+
self.server_ssh_options = ssh_options
|
168
|
+
end
|
169
|
+
|
145
170
|
private
|
146
171
|
|
147
172
|
def mysqldump
|
148
173
|
#"#{ utility(:mysqldump) } #{ user_options } #{ credential_options } " +
|
149
|
-
u = utility_remote(:mysqldump
|
174
|
+
u = utility_remote(:mysqldump)
|
150
175
|
"#{u} #{ user_options } #{ credential_options } " +
|
151
176
|
"#{ connectivity_options } #{ name_option } " +
|
152
177
|
"#{ tables_to_dump } #{ tables_to_skip }"
|
@@ -11,12 +11,23 @@ module Backup
|
|
11
11
|
include SSHKit::DSL
|
12
12
|
|
13
13
|
|
14
|
-
def
|
15
|
-
|
14
|
+
def self.build_sshkit_host(hostname, ssh_options)
|
15
|
+
puts "DEBUG: #{ssh_options}"
|
16
|
+
ssh_user = ssh_options[:user]
|
17
|
+
ssh_pass = ssh_options[:password]
|
18
|
+
ssh_key = ssh_options[:key]
|
16
19
|
|
17
|
-
#puts "run ssh cmd: #{hostname}, #{ssh_user}, #{ssh_pass}, #{cmd}"
|
18
20
|
host = SSHKit::Host.new({hostname: hostname, user: ssh_user})
|
19
|
-
host.
|
21
|
+
host.port = ssh_options[:port] || 22
|
22
|
+
host.key = ssh_key if ssh_key
|
23
|
+
host.password = ssh_pass if ssh_pass
|
24
|
+
|
25
|
+
host
|
26
|
+
end
|
27
|
+
|
28
|
+
def run_ssh_cmd(hostname, ssh_options, cmd)
|
29
|
+
#puts "run ssh cmd: #{hostname}, #{ssh_user}, #{ssh_pass}, #{cmd}"
|
30
|
+
host = Command.build_sshkit_host(hostname, ssh_options)
|
20
31
|
|
21
32
|
#srv = ssh_user+'@'+hostname
|
22
33
|
all_servers = [host]
|
@@ -43,7 +54,7 @@ module Backup
|
|
43
54
|
return { res: 1, output: output }
|
44
55
|
|
45
56
|
rescue => e
|
46
|
-
|
57
|
+
puts "ssh error: #{e.message}, #{e.backtrace}"
|
47
58
|
|
48
59
|
{
|
49
60
|
res: 0,
|
@@ -82,12 +93,17 @@ module Backup
|
|
82
93
|
|
83
94
|
|
84
95
|
|
85
|
-
def ssh_download_file(hostname,
|
86
|
-
return ssh_download_file_sshkit(hostname,
|
96
|
+
def ssh_download_file(hostname, ssh_options, remote_filename, dest_filename)
|
97
|
+
return ssh_download_file_sshkit(hostname, ssh_options, remote_filename, dest_filename)
|
87
98
|
#return ssh_download_file_scp(hostname, ssh_user, ssh_pass, remote_filename, dest_filename)
|
88
99
|
end
|
89
100
|
|
90
|
-
def ssh_download_file_scp(hostname,
|
101
|
+
def ssh_download_file_scp(hostname, ssh_options, remote_filename, dest_filename)
|
102
|
+
ssh_user = ssh_options[:ssh_user]
|
103
|
+
ssh_pass = ssh_options[:ssh_password]
|
104
|
+
ssh_key = ssh_options[:ssh_key]
|
105
|
+
|
106
|
+
# work
|
91
107
|
Net::SCP.download!(hostname, ssh_user, remote_filename, dest_filename, :ssh => { :password => ssh_pass })
|
92
108
|
|
93
109
|
#
|
@@ -101,9 +117,8 @@ module Backup
|
|
101
117
|
end
|
102
118
|
|
103
119
|
# !! NOT work on big files > 4Gb
|
104
|
-
def ssh_download_file_sshkit(hostname,
|
105
|
-
host =
|
106
|
-
host.password = ssh_pass
|
120
|
+
def ssh_download_file_sshkit(hostname, ssh_options, remote_filename, dest_filename)
|
121
|
+
host = Command.build_sshkit_host(hostname, ssh_options)
|
107
122
|
|
108
123
|
on host do |host|
|
109
124
|
download! remote_filename, dest_filename
|
@@ -119,9 +134,8 @@ module Backup
|
|
119
134
|
}
|
120
135
|
end
|
121
136
|
|
122
|
-
def ssh_upload_file(hostname,
|
123
|
-
host =
|
124
|
-
host.password = ssh_pass
|
137
|
+
def ssh_upload_file(hostname, ssh_options, source_file, dest_file, handler=nil)
|
138
|
+
host = Command.build_sshkit_host(hostname, ssh_options)
|
125
139
|
|
126
140
|
# scp
|
127
141
|
f_temp = "/tmp/#{SecureRandom.uuid}"
|
@@ -18,9 +18,7 @@ module Backup
|
|
18
18
|
|
19
19
|
# server options
|
20
20
|
attr_accessor :server_host
|
21
|
-
attr_accessor :
|
22
|
-
attr_accessor :server_ssh_password
|
23
|
-
attr_accessor :server_ssh_key
|
21
|
+
attr_accessor :server_ssh_options
|
24
22
|
attr_accessor :server_backup_path
|
25
23
|
|
26
24
|
|
@@ -29,7 +27,7 @@ module Backup
|
|
29
27
|
# Adds a new Archive to a Backup Model.
|
30
28
|
#
|
31
29
|
# Backup::Model.new(:my_backup, 'My Backup') do
|
32
|
-
#
|
30
|
+
# remote_archive :my_archive do |archive|
|
33
31
|
# archive.add 'path/to/archive'
|
34
32
|
# archive.add '/another/path/to/archive'
|
35
33
|
# archive.exclude 'path/to/exclude'
|
@@ -82,10 +80,23 @@ module Backup
|
|
82
80
|
|
83
81
|
DSL.new(@options).instance_eval(&block)
|
84
82
|
|
85
|
-
#
|
83
|
+
# server options
|
86
84
|
self.server_host = @options[:server_host]
|
87
|
-
|
88
|
-
|
85
|
+
ssh_options = {}
|
86
|
+
v = @options[:server_ssh_user]
|
87
|
+
ssh_options[:user] = v if v
|
88
|
+
|
89
|
+
v = @options[:server_ssh_password]
|
90
|
+
ssh_options[:password] = v if v
|
91
|
+
|
92
|
+
v = @options[:server_ssh_key]
|
93
|
+
ssh_options[:key] = v if v
|
94
|
+
|
95
|
+
v = @options[:server_ssh_port]
|
96
|
+
ssh_options[:port] = v if v
|
97
|
+
|
98
|
+
|
99
|
+
self.server_ssh_options = ssh_options
|
89
100
|
end
|
90
101
|
|
91
102
|
def perform!
|
@@ -102,7 +113,7 @@ module Backup
|
|
102
113
|
pipeline = Pipeline.new
|
103
114
|
with_files_from(paths_to_package) do |files_from|
|
104
115
|
# upload to server
|
105
|
-
res_upload = remote.ssh_upload_file(server_host,
|
116
|
+
res_upload = remote.ssh_upload_file(server_host, server_ssh_options, files_from, files_from)
|
106
117
|
|
107
118
|
if res_upload[:res]==0
|
108
119
|
raise "Cannot upload file to server - #{files_from}"
|
@@ -136,14 +147,14 @@ module Backup
|
|
136
147
|
#exit
|
137
148
|
|
138
149
|
|
139
|
-
res_generate = remote.run_ssh_cmd(server_host,
|
150
|
+
res_generate = remote.run_ssh_cmd(server_host, server_ssh_options, cmd_remote)
|
140
151
|
|
141
152
|
if res_generate[:res]==0
|
142
153
|
raise 'Cannot create backup on server'
|
143
154
|
end
|
144
155
|
|
145
156
|
# download backup
|
146
|
-
res_download = remote.ssh_download_file(server_host,
|
157
|
+
res_download = remote.ssh_download_file(server_host, server_ssh_options, remote_archive_file, archive_file)
|
147
158
|
|
148
159
|
#puts "res: #{res_download}"
|
149
160
|
|
@@ -152,7 +163,7 @@ module Backup
|
|
152
163
|
end
|
153
164
|
|
154
165
|
# delete archive on server
|
155
|
-
res_delete = remote.run_ssh_cmd(server_host,
|
166
|
+
res_delete = remote.run_ssh_cmd(server_host, server_ssh_options, "rm #{remote_archive_file}")
|
156
167
|
|
157
168
|
end
|
158
169
|
|
@@ -223,12 +234,19 @@ module Backup
|
|
223
234
|
@options[:server_host] = val
|
224
235
|
end
|
225
236
|
|
237
|
+
def server_ssh_port=(val = true)
|
238
|
+
@options[:server_ssh_port] = val
|
239
|
+
end
|
240
|
+
|
226
241
|
def server_ssh_user=(val = true)
|
227
242
|
@options[:server_ssh_user] = val
|
228
243
|
end
|
229
244
|
def server_ssh_password=(val = true)
|
230
245
|
@options[:server_ssh_password] = val
|
231
246
|
end
|
247
|
+
def server_ssh_key=(val = true)
|
248
|
+
@options[:server_ssh_key] = val
|
249
|
+
end
|
232
250
|
|
233
251
|
###
|
234
252
|
def use_sudo(val = true)
|
data/lib/backup/remote_data.rb
CHANGED
@@ -18,9 +18,8 @@ module Backup
|
|
18
18
|
|
19
19
|
# server options
|
20
20
|
attr_accessor :server_host
|
21
|
-
attr_accessor :
|
22
|
-
|
23
|
-
attr_accessor :server_ssh_key
|
21
|
+
attr_accessor :server_ssh_options
|
22
|
+
|
24
23
|
attr_accessor :server_path
|
25
24
|
attr_accessor :server_command
|
26
25
|
attr_accessor :script
|
@@ -43,10 +42,27 @@ module Backup
|
|
43
42
|
|
44
43
|
DSL.new(@options).instance_eval(&block)
|
45
44
|
|
46
|
-
#
|
45
|
+
# ssh options
|
47
46
|
self.server_host = @options[:server_host]
|
48
|
-
|
49
|
-
|
47
|
+
|
48
|
+
# server options
|
49
|
+
ssh_options = {}
|
50
|
+
v = @options[:server_ssh_user]
|
51
|
+
ssh_options[:user] = v if v
|
52
|
+
|
53
|
+
v = @options[:server_ssh_password]
|
54
|
+
ssh_options[:password] = v if v
|
55
|
+
|
56
|
+
v = @options[:server_ssh_key]
|
57
|
+
ssh_options[:key] = v if v
|
58
|
+
|
59
|
+
v = @options[:server_ssh_port]
|
60
|
+
ssh_options[:port] = v if v
|
61
|
+
|
62
|
+
|
63
|
+
self.server_ssh_options = ssh_options
|
64
|
+
|
65
|
+
# server options
|
50
66
|
self.server_path = @options[:server_path]
|
51
67
|
self.server_command = @options[:server_command]
|
52
68
|
self.script = @options[:script]
|
@@ -82,27 +98,23 @@ module Backup
|
|
82
98
|
|
83
99
|
Logger.info "upload script #{local_script_path} --> #{remote_script_path}"
|
84
100
|
|
85
|
-
remote.ssh_upload_file(server_host,
|
101
|
+
remote.ssh_upload_file(server_host, server_ssh_options, local_script_path, remote_script_path)
|
86
102
|
|
87
103
|
cmd_remote = "chmod +x #{remote_script_path} && sh #{remote_script_path}"
|
88
|
-
res_generate = remote.run_ssh_cmd(
|
89
|
-
server_host, server_ssh_user, server_ssh_password,
|
90
|
-
cmd_remote)
|
104
|
+
res_generate = remote.run_ssh_cmd(server_host, server_ssh_options, cmd_remote)
|
91
105
|
|
92
106
|
# delete temp script
|
93
107
|
cmd_delete = "rm -rf #{remote_script_path}"
|
94
|
-
res_delete = remote.run_ssh_cmd(server_host,
|
108
|
+
res_delete = remote.run_ssh_cmd(server_host, server_ssh_options, cmd_delete)
|
95
109
|
|
96
110
|
else
|
97
111
|
# use command
|
98
112
|
cmd_remote = server_command
|
99
|
-
res_generate = remote.run_ssh_cmd(
|
100
|
-
server_host, server_ssh_user, server_ssh_password,
|
101
|
-
cmd_remote)
|
113
|
+
res_generate = remote.run_ssh_cmd(server_host, server_ssh_options, cmd_remote)
|
102
114
|
end
|
103
115
|
|
104
116
|
if res_generate[:res]==0
|
105
|
-
raise
|
117
|
+
raise "Cannot create backup on server: #{res_generate[:error]}"
|
106
118
|
end
|
107
119
|
|
108
120
|
|
@@ -119,18 +131,14 @@ module Backup
|
|
119
131
|
# download backup
|
120
132
|
Logger.info "download from #{remote_archive_file} to #{temp_local_file}"
|
121
133
|
|
122
|
-
res_download = remote.ssh_download_file(
|
123
|
-
server_host, server_ssh_user, server_ssh_password,
|
124
|
-
remote_archive_file, temp_local_file)
|
134
|
+
res_download = remote.ssh_download_file(server_host, server_ssh_options, remote_archive_file, temp_local_file)
|
125
135
|
|
126
136
|
if res_download[:res]==0
|
127
137
|
raise 'Cannot download file from server'
|
128
138
|
end
|
129
139
|
|
130
140
|
# delete archive on server
|
131
|
-
res_delete = remote.run_ssh_cmd(
|
132
|
-
server_host, server_ssh_user, server_ssh_password,
|
133
|
-
"rm #{remote_archive_file}")
|
141
|
+
res_delete = remote.run_ssh_cmd(server_host, server_ssh_options, "rm #{remote_archive_file}")
|
134
142
|
|
135
143
|
|
136
144
|
# process archive locally
|
@@ -232,12 +240,20 @@ module Backup
|
|
232
240
|
@options[:server_host] = val
|
233
241
|
end
|
234
242
|
|
243
|
+
def server_ssh_port=(val = true)
|
244
|
+
@options[:server_ssh_port] = val
|
245
|
+
end
|
246
|
+
|
235
247
|
def server_ssh_user=(val = true)
|
236
248
|
@options[:server_ssh_user] = val
|
237
249
|
end
|
238
250
|
def server_ssh_password=(val = true)
|
239
251
|
@options[:server_ssh_password] = val
|
240
252
|
end
|
253
|
+
def server_ssh_key=(val = true)
|
254
|
+
@options[:server_ssh_key] = val
|
255
|
+
end
|
256
|
+
|
241
257
|
|
242
258
|
def server_command=(val = true)
|
243
259
|
@options[:server_command] = val
|
data/lib/backup/utilities.rb
CHANGED
@@ -226,16 +226,13 @@ module Backup
|
|
226
226
|
##
|
227
227
|
# Returns the full path to the specified utility.
|
228
228
|
# Raises an error if utility can not be found in the system's $PATH
|
229
|
-
def utility_remote(name
|
229
|
+
def utility_remote(name)
|
230
230
|
name = name.to_s.strip
|
231
231
|
raise Error, 'Utility Name Empty' if name.empty?
|
232
232
|
|
233
233
|
req = Backup::Remote::Command.new
|
234
|
-
#req.run_ssh_cmd(server_host, server_ssh_user, server_ssh_password, "whoami")
|
235
|
-
#req.run_ssh_cmd(server_host, server_ssh_user, server_ssh_password, "which ruby")
|
236
|
-
|
237
234
|
cmd = %Q(which '#{ name }' 2>/dev/null)
|
238
|
-
res = req.run_ssh_cmd(server_host,
|
235
|
+
res = req.run_ssh_cmd(server_host, server_ssh_options, cmd)
|
239
236
|
output = res[:output].chomp
|
240
237
|
|
241
238
|
raise Error, <<-EOS if res[:res]==0 || output.empty?
|
data/lib/backup/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: backup-remote
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.17
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Max Ivak, Michael van Rooijen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-05-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: CFPropertyList
|