backup-remote 0.0.5 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +15 -13
- data/lib/backup/remote_archive.rb +1 -11
- data/lib/backup/remote_data.rb +36 -16
- 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: 1dc51aa59099a0bf9406f503155f31630759586e
|
4
|
+
data.tar.gz: cea4e466d787dad9e31bb7d34ebef3972f141295
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 246ae877464476b31e954cd8e0a0ef37e5ca737fd43094579427f095153364bf334b0e663d3692ed757b0044d5b2b12e46cfcbbfff320e59c8a4b98801b259ec
|
7
|
+
data.tar.gz: 3d97561e03e95b86a46c7491bd54518f271d6895586a3f966c284855e2e7de6da1bb06b85e8a87715fc2ee9449573db737814236a712226661f2b19f8b1295a3
|
data/README.md
CHANGED
@@ -98,9 +98,6 @@ end
|
|
98
98
|
|
99
99
|
```
|
100
100
|
|
101
|
-
Options:
|
102
|
-
* server_command - command to create archive file
|
103
|
-
|
104
101
|
|
105
102
|
# Databases
|
106
103
|
|
@@ -110,7 +107,7 @@ Options:
|
|
110
107
|
* RemoteMySQL
|
111
108
|
|
112
109
|
|
113
|
-
###
|
110
|
+
### Remote MySQL Database
|
114
111
|
|
115
112
|
```
|
116
113
|
Model.new(:my_backup, 'My Backup') do
|
@@ -137,7 +134,7 @@ end
|
|
137
134
|
|
138
135
|
* Run custom command on the remote server to create a backup archive
|
139
136
|
|
140
|
-
* Specify command to run to generate archive file on the remote server
|
137
|
+
* Specify command (or script) to run to generate archive file on the remote server
|
141
138
|
|
142
139
|
* This command should create an archive file with filename specified in server_path option.
|
143
140
|
|
@@ -152,12 +149,13 @@ Model.new(:my_server_data_backup, 'Backup data') do
|
|
152
149
|
|
153
150
|
|
154
151
|
archive.command = "--any command to generate backup archive file--"
|
152
|
+
archive.script = "--path to script to copy to server and run--"
|
153
|
+
archive.server_path = "/path/to/backup.tar.gz"
|
154
|
+
|
155
|
+
# example:
|
156
|
+
# archive.command = "/tmp/backup.txt"
|
155
157
|
# archive.command = "echo '1' > /tmp/backup.txt"
|
156
158
|
|
157
|
-
archive.server_path = "/path/to/archive.tar.gz"
|
158
|
-
# archive.command = "/tmp/backup.txt"
|
159
|
-
|
160
|
-
|
161
159
|
|
162
160
|
end
|
163
161
|
|
@@ -167,8 +165,12 @@ end
|
|
167
165
|
|
168
166
|
```
|
169
167
|
|
168
|
+
Options:
|
169
|
+
|
170
|
+
* command - command to run to generate backup on server. Not used if script is specified.
|
171
|
+
* script - path to script file to upload and run on server to generate backup. Script is stored locally nad is uploaded to server.
|
172
|
+
|
173
|
+
|
174
|
+
|
170
175
|
|
171
|
-
|
172
|
-
[Installation]: http://backup.github.io/backup/v4/installation
|
173
|
-
[Release Notes]: http://backup.github.io/backup/v4/release-notes
|
174
|
-
[Documentation]: http://backup.github.io/backup/v4
|
176
|
+
### Examples
|
@@ -185,14 +185,9 @@ module Backup
|
|
185
185
|
paths.each {|path| tmpfile.puts path }
|
186
186
|
tmpfile.close
|
187
187
|
|
188
|
-
puts "tmpfile #{tmpfile.path}"
|
189
|
-
|
190
|
-
puts "content: #{File.read(tmpfile.path)}"
|
191
188
|
#yield "-T '#{ tmpfile.path }'"
|
192
189
|
yield "#{ tmpfile.path }"
|
193
190
|
ensure
|
194
|
-
|
195
|
-
puts "delete file #{tmpfile.path}"
|
196
191
|
tmpfile.delete
|
197
192
|
end
|
198
193
|
|
@@ -203,12 +198,7 @@ module Backup
|
|
203
198
|
end
|
204
199
|
|
205
200
|
def prepare_path(path)
|
206
|
-
|
207
|
-
res = options[:root] ? path : File.expand_path(path)
|
208
|
-
|
209
|
-
puts "path #{path} ===> #{res}"
|
210
|
-
|
211
|
-
res
|
201
|
+
options[:root] ? path : File.expand_path(path)
|
212
202
|
end
|
213
203
|
|
214
204
|
def tar_options
|
data/lib/backup/remote_data.rb
CHANGED
@@ -23,6 +23,7 @@ module Backup
|
|
23
23
|
attr_accessor :server_ssh_key
|
24
24
|
attr_accessor :server_path
|
25
25
|
attr_accessor :server_command
|
26
|
+
attr_accessor :script
|
26
27
|
|
27
28
|
|
28
29
|
|
@@ -47,6 +48,7 @@ module Backup
|
|
47
48
|
self.server_ssh_password = @options[:server_ssh_password]
|
48
49
|
self.server_path = @options[:server_path]
|
49
50
|
self.server_command = @options[:server_command]
|
51
|
+
self.script = @options[:script]
|
50
52
|
end
|
51
53
|
|
52
54
|
def perform!
|
@@ -64,22 +66,46 @@ module Backup
|
|
64
66
|
|
65
67
|
Dir.mktmpdir do |temp_dir|
|
66
68
|
temp_local_file = File.join("#{temp_dir}", File.basename(server_path))
|
67
|
-
#temp_local_file = File.join(path, File.basename(server_path))
|
68
|
-
#temp_local_file = Tempfile.new("").path+"."+File.extname(server_path)
|
69
69
|
|
70
70
|
remote_archive_file = server_path
|
71
71
|
|
72
72
|
# generate backup on remote server
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
73
|
+
remote_script = script
|
74
|
+
|
75
|
+
if remote_script && remote_script!=""
|
76
|
+
# use script
|
77
|
+
# upload script
|
78
|
+
local_script_path = File.join(Config.root_path, remote_script)
|
79
|
+
|
80
|
+
f_remote = Tempfile.new('backup')
|
81
|
+
remote_script_path = f_remote.path+"."+File.extname(local_script_path)
|
82
|
+
|
83
|
+
#puts "upload script #{local_script_path} --> #{remote_script_path}"
|
84
|
+
remote.ssh_upload_file(server_host, server_ssh_user, server_ssh_password, local_script_path, remote_script_path)
|
85
|
+
|
86
|
+
cmd_remote = "chmod +x #{remote_script_path} && sh #{remote_script_path}"
|
87
|
+
res_generate = remote.run_ssh_cmd(
|
88
|
+
server_host, server_ssh_user, server_ssh_password,
|
89
|
+
cmd_remote)
|
90
|
+
|
91
|
+
# delete temp script
|
92
|
+
cmd_delete = "rm -rf #{remote_script_path}"
|
93
|
+
res_delete = remote.run_ssh_cmd(server_host, server_ssh_user, server_ssh_password, cmd_delete)
|
94
|
+
|
95
|
+
else
|
96
|
+
# use command
|
97
|
+
cmd_remote = server_command
|
98
|
+
res_generate = remote.run_ssh_cmd(
|
99
|
+
server_host, server_ssh_user, server_ssh_password,
|
100
|
+
cmd_remote)
|
101
|
+
end
|
77
102
|
|
78
103
|
if res_generate[:res]==0
|
79
104
|
raise 'Cannot create backup on server'
|
80
105
|
end
|
81
106
|
|
82
107
|
# download backup
|
108
|
+
#puts "download from #{remote_archive_file} to #{temp_local_file}"
|
83
109
|
res_download = remote.ssh_download_file(
|
84
110
|
server_host, server_ssh_user, server_ssh_password,
|
85
111
|
remote_archive_file, temp_local_file)
|
@@ -149,14 +175,10 @@ module Backup
|
|
149
175
|
paths.each {|path| tmpfile.puts path }
|
150
176
|
tmpfile.close
|
151
177
|
|
152
|
-
puts "tmpfile #{tmpfile.path}"
|
153
|
-
|
154
|
-
puts "content: #{File.read(tmpfile.path)}"
|
155
178
|
#yield "-T '#{ tmpfile.path }'"
|
156
179
|
yield "#{ tmpfile.path }"
|
157
180
|
ensure
|
158
181
|
|
159
|
-
puts "delete file #{tmpfile.path}"
|
160
182
|
tmpfile.delete
|
161
183
|
end
|
162
184
|
|
@@ -167,12 +189,7 @@ module Backup
|
|
167
189
|
end
|
168
190
|
|
169
191
|
def prepare_path(path)
|
170
|
-
|
171
|
-
res = options[:root] ? path : File.expand_path(path)
|
172
|
-
|
173
|
-
puts "path #{path} ===> #{res}"
|
174
|
-
|
175
|
-
res
|
192
|
+
options[:root] ? path : File.expand_path(path)
|
176
193
|
end
|
177
194
|
|
178
195
|
def tar_options
|
@@ -207,6 +224,9 @@ module Backup
|
|
207
224
|
def server_command=(val = true)
|
208
225
|
@options[:server_command] = val
|
209
226
|
end
|
227
|
+
def script=(val = true)
|
228
|
+
@options[:script] = val
|
229
|
+
end
|
210
230
|
def server_path=(val = true)
|
211
231
|
@options[:server_path] = val
|
212
232
|
end
|
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.7
|
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-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: CFPropertyList
|