backup-remote 0.0.8 → 0.0.9
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/README.md +1 -0
- data/lib/backup/remote/command.rb +37 -17
- data/lib/backup/remote_data.rb +84 -67
- 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: c1856e1f2cc32e862113171f5795fc98bd8bb9b3
|
4
|
+
data.tar.gz: 2ebf39b7e07c93277ebbe1d3881feb462d221306
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6fb154ae61155636a143ae4cde53a7921d039daaec0ced5326a3ff5ba6f6e6c630682ce8d8acd7f16b57ae508f6ea71a9df294db09ba3b48ffc61beecd53e4fe
|
7
|
+
data.tar.gz: 353db081fe46b1792c7f3ccae5eb67a641d835156f470f3f67d041d396410b223ae435c90abea44f99cc6b3309a25a4ba2157bfc2aac7fe627adaa40c29ef743
|
data/README.md
CHANGED
@@ -71,6 +71,7 @@ Options for SSH connection:
|
|
71
71
|
* server_ssh_user - user name to connect by SSH
|
72
72
|
* server_ssh_password - not used if server_ssh-key is provided
|
73
73
|
* server_ssh_key - (optional) - path to ssh key
|
74
|
+
* temp_dir_path - (optional) - specify temporary directory path where backup files will be downloaded. By default, it is '/tmp'
|
74
75
|
|
75
76
|
|
76
77
|
|
@@ -59,23 +59,43 @@ module Backup
|
|
59
59
|
end
|
60
60
|
|
61
61
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
62
|
+
|
63
|
+
def ssh_download_file(hostname, ssh_user, ssh_pass, remote_filename, dest_filename)
|
64
|
+
return ssh_download_file_sshkit(hostname, ssh_user, ssh_pass, remote_filename, dest_filename)
|
65
|
+
#return ssh_download_file_scp(hostname, ssh_user, ssh_pass, remote_filename, dest_filename)
|
66
|
+
end
|
67
|
+
|
68
|
+
def ssh_download_file_scp(hostname, ssh_user, ssh_pass, remote_filename, dest_filename)
|
69
|
+
Net::SCP.download!(hostname, ssh_user, remote_filename, dest_filename, :ssh => { :password => ssh_pass })
|
70
|
+
|
71
|
+
#
|
72
|
+
return {res: 1, output: ""}
|
73
|
+
|
74
|
+
rescue => e
|
75
|
+
{
|
76
|
+
res: 0,
|
77
|
+
error: e.message
|
78
|
+
}
|
79
|
+
end
|
80
|
+
|
81
|
+
# !! NOT work on big files > 4Gb
|
82
|
+
def ssh_download_file_sshkit(hostname, ssh_user, ssh_pass, remote_filename, dest_filename)
|
83
|
+
host = SSHKit::Host.new("#{ssh_user}@#{hostname}")
|
84
|
+
host.password = ssh_pass
|
85
|
+
|
86
|
+
on host do |host|
|
87
|
+
download! remote_filename, dest_filename
|
88
|
+
end
|
89
|
+
|
90
|
+
#
|
91
|
+
return {res: 1, output: ""}
|
92
|
+
|
93
|
+
rescue => e
|
94
|
+
{
|
95
|
+
res: 0,
|
96
|
+
error: e.message
|
97
|
+
}
|
98
|
+
end
|
79
99
|
|
80
100
|
def ssh_upload_file(hostname, ssh_user, ssh_pass, source_file, dest_file, handler=nil)
|
81
101
|
host = SSHKit::Host.new("#{ssh_user}@#{hostname}")
|
data/lib/backup/remote_data.rb
CHANGED
@@ -24,6 +24,7 @@ module Backup
|
|
24
24
|
attr_accessor :server_path
|
25
25
|
attr_accessor :server_command
|
26
26
|
attr_accessor :script
|
27
|
+
attr_accessor :temp_dir_path
|
27
28
|
|
28
29
|
|
29
30
|
|
@@ -49,6 +50,7 @@ module Backup
|
|
49
50
|
self.server_path = @options[:server_path]
|
50
51
|
self.server_command = @options[:server_command]
|
51
52
|
self.script = @options[:script]
|
53
|
+
self.temp_dir_path = @options[:temp_dir_path] || '/tmp'
|
52
54
|
end
|
53
55
|
|
54
56
|
def perform!
|
@@ -64,99 +66,110 @@ module Backup
|
|
64
66
|
remote = Backup::Remote::Command.new
|
65
67
|
|
66
68
|
|
67
|
-
|
68
|
-
temp_local_file = File.join("#{temp_dir}", File.basename(server_path))
|
69
|
+
remote_archive_file = server_path
|
69
70
|
|
70
|
-
|
71
|
+
# generate backup on remote server
|
72
|
+
remote_script = script
|
71
73
|
|
72
|
-
|
73
|
-
|
74
|
+
if remote_script && remote_script!=""
|
75
|
+
# use script
|
76
|
+
# upload script
|
74
77
|
|
75
|
-
|
76
|
-
# use script
|
77
|
-
# upload script
|
78
|
+
local_script_path = File.join(Config.root_path, remote_script)
|
78
79
|
|
79
|
-
|
80
|
-
|
80
|
+
f_remote = Tempfile.new('backup')
|
81
|
+
remote_script_path = f_remote.path+"."+File.extname(local_script_path)
|
81
82
|
|
82
|
-
|
83
|
+
Logger.info "upload script #{local_script_path} --> #{remote_script_path}"
|
83
84
|
|
84
|
-
|
85
|
-
remote_script_path = f_remote.path+"."+File.extname(local_script_path)
|
85
|
+
remote.ssh_upload_file(server_host, server_ssh_user, server_ssh_password, local_script_path, remote_script_path)
|
86
86
|
|
87
|
-
|
88
|
-
|
87
|
+
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)
|
89
91
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
cmd_remote)
|
92
|
+
# delete temp script
|
93
|
+
cmd_delete = "rm -rf #{remote_script_path}"
|
94
|
+
res_delete = remote.run_ssh_cmd(server_host, server_ssh_user, server_ssh_password, cmd_delete)
|
94
95
|
|
95
|
-
|
96
|
-
|
97
|
-
|
96
|
+
else
|
97
|
+
# use command
|
98
|
+
cmd_remote = server_command
|
99
|
+
res_generate = remote.run_ssh_cmd(
|
100
|
+
server_host, server_ssh_user, server_ssh_password,
|
101
|
+
cmd_remote)
|
102
|
+
end
|
98
103
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
res_generate = remote.run_ssh_cmd(
|
103
|
-
server_host, server_ssh_user, server_ssh_password,
|
104
|
-
cmd_remote)
|
105
|
-
end
|
104
|
+
if res_generate[:res]==0
|
105
|
+
raise 'Cannot create backup on server'
|
106
|
+
end
|
106
107
|
|
107
|
-
if res_generate[:res]==0
|
108
|
-
raise 'Cannot create backup on server'
|
109
|
-
end
|
110
108
|
|
111
|
-
# download backup
|
112
|
-
#puts "download from #{remote_archive_file} to #{temp_local_file}"
|
113
|
-
res_download = remote.ssh_download_file(
|
114
|
-
server_host, server_ssh_user, server_ssh_password,
|
115
|
-
remote_archive_file, temp_local_file)
|
116
109
|
|
117
|
-
|
118
|
-
raise 'Cannot download file from server'
|
119
|
-
end
|
110
|
+
#Dir.mktmpdir do |temp_dir|
|
120
111
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
112
|
+
#temp_local_file = File.join("#{temp_dir}", File.basename(server_path))
|
113
|
+
|
114
|
+
temp_local_file = File.join("#{temp_dir_path}/#{Time.now.to_i}#{rand(1000)}/", File.basename(server_path))
|
115
|
+
|
116
|
+
#path = File.expand_path "#{Dir.tmpdir}/#{Time.now.to_i}#{rand(1000)}/"
|
117
|
+
FileUtils.mkdir_p File.dirname(temp_local_file)
|
118
|
+
|
119
|
+
# download backup
|
120
|
+
Logger.info "download from #{remote_archive_file} to #{temp_local_file}"
|
125
121
|
|
122
|
+
res_download = remote.ssh_download_file(
|
123
|
+
server_host, server_ssh_user, server_ssh_password,
|
124
|
+
remote_archive_file, temp_local_file)
|
126
125
|
|
127
|
-
|
126
|
+
if res_download[:res]==0
|
127
|
+
raise 'Cannot download file from server'
|
128
|
+
end
|
129
|
+
|
130
|
+
# 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}")
|
128
134
|
|
129
|
-
pipeline = Pipeline.new
|
130
135
|
|
131
|
-
|
132
|
-
temp_tar_root= temp_dir
|
133
|
-
pipeline.add(
|
134
|
-
"#{ tar_command } #{ tar_options } -cPf - -C #{temp_tar_root } #{ File.basename(temp_local_file) }",
|
135
|
-
tar_success_codes
|
136
|
-
)
|
136
|
+
# process archive locally
|
137
137
|
|
138
|
-
|
139
|
-
@model.compressor.compress_with do |command, ext|
|
140
|
-
pipeline << command
|
141
|
-
extension << ext
|
142
|
-
end if @model.compressor
|
138
|
+
pipeline = Pipeline.new
|
143
139
|
|
144
|
-
|
140
|
+
#temp_tar_root= tar_root
|
141
|
+
temp_tar_root= temp_dir_path
|
142
|
+
pipeline.add(
|
143
|
+
"#{ tar_command } #{ tar_options } -cPf - -C #{temp_tar_root } #{ File.basename(temp_local_file) }",
|
144
|
+
tar_success_codes
|
145
|
+
)
|
145
146
|
|
146
|
-
|
147
|
-
|
147
|
+
extension = 'tar'
|
148
|
+
@model.compressor.compress_with do |command, ext|
|
149
|
+
pipeline << command
|
150
|
+
extension << ext
|
151
|
+
end if @model.compressor
|
148
152
|
|
149
|
-
|
153
|
+
pipeline << "#{ utility(:cat) } > '#{ File.join(path, "#{ name }.#{ extension }") }'"
|
150
154
|
|
155
|
+
#puts "commands: #{pipeline.commands}"
|
156
|
+
#exit
|
151
157
|
|
152
|
-
|
153
|
-
Logger.info "Archive '#{ name }' Complete!"
|
154
|
-
else
|
155
|
-
raise Error, "Failed to Create Archive '#{ name }'\n" +
|
156
|
-
pipeline.error_messages
|
157
|
-
end
|
158
|
+
pipeline.run
|
158
159
|
|
160
|
+
|
161
|
+
if pipeline.success?
|
162
|
+
Logger.info "Archive '#{ name }' Complete!"
|
163
|
+
else
|
164
|
+
raise Error, "Failed to Create Archive '#{ name }'\n" +
|
165
|
+
pipeline.error_messages
|
159
166
|
end
|
167
|
+
|
168
|
+
if File.exists?(temp_local_file)
|
169
|
+
FileUtils.rm_rf(temp_local_file)
|
170
|
+
FileUtils.rm_rf(File.dirname(temp_local_file))
|
171
|
+
end
|
172
|
+
|
160
173
|
end
|
161
174
|
|
162
175
|
private
|
@@ -235,6 +248,10 @@ module Backup
|
|
235
248
|
@options[:server_path] = val
|
236
249
|
end
|
237
250
|
|
251
|
+
def temp_dir_path=(val = true)
|
252
|
+
@options[:temp_dir_path] = val
|
253
|
+
end
|
254
|
+
|
238
255
|
###
|
239
256
|
def use_sudo(val = true)
|
240
257
|
@options[:sudo] = val
|
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.9
|
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: 2016-12-
|
11
|
+
date: 2016-12-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: CFPropertyList
|