webtranslateit-safe 0.4.4 → 0.4.6
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/CHANGELOG +8 -0
- data/README.markdown +128 -115
- data/bin/webtranslateit-safe +1 -3
- data/lib/{webtranslateit → web_translate_it}/safe/cloudfiles.rb +2 -2
- data/lib/{webtranslateit → web_translate_it}/safe/config/builder.rb +2 -2
- data/lib/{webtranslateit → web_translate_it}/safe/config/node.rb +4 -5
- data/lib/{webtranslateit → web_translate_it}/safe/ftp.rb +5 -3
- data/lib/{webtranslateit → web_translate_it}/safe/local.rb +2 -2
- data/lib/{webtranslateit → web_translate_it}/safe/mongodump.rb +1 -1
- data/lib/{webtranslateit → web_translate_it}/safe/s3.rb +4 -2
- data/lib/web_translate_it/safe/scp.rb +109 -0
- data/lib/{webtranslateit → web_translate_it}/safe/sftp.rb +4 -2
- data/lib/{webtranslateit → web_translate_it}/safe/sink.rb +2 -2
- data/lib/{webtranslateit → web_translate_it}/safe/tmp_file.rb +0 -1
- data/lib/web_translate_it/safe.rb +69 -0
- metadata +37 -22
- data/lib/webtranslateit/safe.rb +0 -67
- /data/lib/{webtranslateit → web_translate_it}/safe/archive.rb +0 -0
- /data/lib/{webtranslateit → web_translate_it}/safe/backup.rb +0 -0
- /data/lib/{webtranslateit → web_translate_it}/safe/gpg.rb +0 -0
- /data/lib/{webtranslateit → web_translate_it}/safe/gzip.rb +0 -0
- /data/lib/{webtranslateit → web_translate_it}/safe/mysqldump.rb +0 -0
- /data/lib/{webtranslateit → web_translate_it}/safe/pgdump.rb +0 -0
- /data/lib/{webtranslateit → web_translate_it}/safe/pipe.rb +0 -0
- /data/lib/{webtranslateit → web_translate_it}/safe/source.rb +0 -0
- /data/lib/{webtranslateit → web_translate_it}/safe/stream.rb +0 -0
- /data/lib/{webtranslateit → web_translate_it}/safe/svndump.rb +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b87215e582012cb8e81e826fa3447c65c0b30a36940840d0e49114832c705fff
|
4
|
+
data.tar.gz: e93d445482019f3e864599b8df34506463edaf2b2bb864dfee4d3d0b44cb559c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '08678656aeb78fdd500dd26209ac86859517e2a828773b2ec0c9e2d9b3262b0e322c5a75618029cd49566d60a11f69861336c63101a9b42230bece81a3ffce50'
|
7
|
+
data.tar.gz: dcb82c4237e64d83393bc22de543dd6ba599abae7dbb0a57202dce73ef112da0e59f8a2fac7b6f1016dfcb91430fc7ada1da6cac160c7917f33992c85be0d623
|
data/CHANGELOG
CHANGED
data/README.markdown
CHANGED
@@ -83,7 +83,7 @@ We recommend also pringing the hard paper copy of your GPG key 'just in case'.
|
|
83
83
|
|
84
84
|
The procedure to create and transfer the key is as follows:
|
85
85
|
|
86
|
-
1. run
|
86
|
+
1. run `gpg --gen-key` on your local machine and follow onscreen instructions to create the key
|
87
87
|
(you can accept all the defaults).
|
88
88
|
|
89
89
|
2. extract your public key into a file (assuming you used test@example.com as your key email):
|
@@ -94,135 +94,148 @@ The procedure to create and transfer the key is as follows:
|
|
94
94
|
|
95
95
|
4. import public key on the remote system:
|
96
96
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
97
|
+
``` bash
|
98
|
+
$ gpg --import test@example.com.pub
|
99
|
+
gpg: key 45CA9403: public key "Test Backup <test@example.com>" imported
|
100
|
+
gpg: Total number processed: 1
|
101
|
+
gpg: imported: 1
|
102
|
+
```
|
101
103
|
|
102
104
|
5. since we don't keep the secret part of the key on the remote server, gpg has
|
103
105
|
no way to know its yours and can be trusted.
|
104
106
|
To fix that we can sign it with other trusted key, or just directly modify its
|
105
107
|
trust level in gpg (use level 5):
|
106
108
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
109
|
+
``` bash
|
110
|
+
$ gpg --edit-key test@example.com
|
111
|
+
...
|
112
|
+
Command> trust
|
113
|
+
...
|
114
|
+
1 = I don't know or won't say
|
115
|
+
2 = I do NOT trust
|
116
|
+
3 = I trust marginally
|
117
|
+
4 = I trust fully
|
118
|
+
5 = I trust ultimately
|
119
|
+
m = back to the main menu
|
120
|
+
|
121
|
+
Your decision? 5
|
122
|
+
...
|
123
|
+
Command> quit
|
124
|
+
```
|
121
125
|
|
122
126
|
6. export your secret key for backup
|
123
127
|
(we recommend to print it on paper and burn to a CD/DVD and store in a safe place):
|
124
128
|
|
125
|
-
|
129
|
+
``` bash
|
130
|
+
$ gpg -a --export-secret-key test@example.com > test@example.com.key
|
131
|
+
```
|
132
|
+
## Example configuration
|
126
133
|
|
134
|
+
``` ruby
|
135
|
+
safe do
|
136
|
+
verbose true
|
137
|
+
|
138
|
+
local path: "/backup/:kind/:id"
|
139
|
+
|
140
|
+
s3 do
|
141
|
+
key "...................."
|
142
|
+
secret "........................................"
|
143
|
+
bucket "backup.astrails.com"
|
144
|
+
path "servers/alpha/:kind/:id"
|
145
|
+
end
|
146
|
+
|
147
|
+
cloudfiles do
|
148
|
+
user "..........."
|
149
|
+
api_key "................................."
|
150
|
+
container "safe_backup"
|
151
|
+
path ":kind/" # this is default
|
152
|
+
service_net false
|
153
|
+
end
|
154
|
+
|
155
|
+
sftp do
|
156
|
+
host "sftp.astrails.com"
|
157
|
+
user "astrails"
|
158
|
+
# port 8023
|
159
|
+
password "ssh password for sftp"
|
160
|
+
end
|
161
|
+
|
162
|
+
sftp do
|
163
|
+
host "sftp.astrails.com"
|
164
|
+
user "astrails"
|
165
|
+
# port 8023
|
166
|
+
password "ssh password for scp"
|
167
|
+
end
|
168
|
+
|
169
|
+
gpg do
|
170
|
+
command "/usr/local/bin/gpg"
|
171
|
+
options "--no-use-agent"
|
172
|
+
# symmetric encryption key
|
173
|
+
# password "qwe"
|
174
|
+
|
175
|
+
# public GPG key (must be known to GPG, i.e. be on the keyring)
|
176
|
+
key "backup@astrails.com"
|
177
|
+
end
|
178
|
+
|
179
|
+
keep do
|
180
|
+
local 20
|
181
|
+
s3 100
|
182
|
+
cloudfiles 100
|
183
|
+
sftp 100
|
184
|
+
scp 100
|
185
|
+
end
|
186
|
+
|
187
|
+
mysqldump do
|
188
|
+
options "-ceKq --single-transaction --create-options"
|
189
|
+
|
190
|
+
user "root"
|
191
|
+
password "............"
|
192
|
+
socket "/var/run/mysqld/mysqld.sock"
|
193
|
+
|
194
|
+
database :blog
|
195
|
+
database :servershape
|
196
|
+
database :astrails_com
|
197
|
+
database :secret_project_com do
|
198
|
+
skip_tables "foo"
|
199
|
+
skip_tables ["bar", "baz"]
|
200
|
+
end
|
127
201
|
|
202
|
+
end
|
128
203
|
|
129
|
-
|
204
|
+
svndump do
|
205
|
+
repo :my_repo do
|
206
|
+
repo_path "/home/svn/my_repo"
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
pgdump do
|
211
|
+
options "-i -x -O" # -i => ignore version, -x => do not dump privileges (grant/revoke), -O => skip restoration of object ownership in plain text format
|
212
|
+
|
213
|
+
user "username"
|
214
|
+
password "............" # shouldn't be used, instead setup ident. Current functionality exports a password env to the shell which pg_dump uses - untested!
|
215
|
+
|
216
|
+
database :blog
|
217
|
+
database :stateofflux_com
|
218
|
+
end
|
219
|
+
|
220
|
+
tar do
|
221
|
+
options "-h" # dereference symlinks
|
222
|
+
archive "git-repositories", files: "/home/git/repositories"
|
223
|
+
archive "dot-configs", files: "/home/*/.[^.]*"
|
224
|
+
archive "etc", files: "/etc", exclude: "/etc/puppet/other"
|
225
|
+
|
226
|
+
archive "blog-astrails-com" do
|
227
|
+
files "/var/www/blog.astrails.com/"
|
228
|
+
exclude "/var/www/blog.astrails.com/log"
|
229
|
+
exclude "/var/www/blog.astrails.com/tmp"
|
230
|
+
end
|
130
231
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
local :path => "/backup/:kind/:id"
|
135
|
-
|
136
|
-
s3 do
|
137
|
-
key "...................."
|
138
|
-
secret "........................................"
|
139
|
-
bucket "backup.astrails.com"
|
140
|
-
path "servers/alpha/:kind/:id"
|
141
|
-
end
|
142
|
-
|
143
|
-
cloudfiles do
|
144
|
-
user "..........."
|
145
|
-
api_key "................................."
|
146
|
-
container "safe_backup"
|
147
|
-
path ":kind/" # this is default
|
148
|
-
service_net false
|
149
|
-
end
|
150
|
-
|
151
|
-
sftp do
|
152
|
-
host "sftp.astrails.com"
|
153
|
-
user "astrails"
|
154
|
-
# port 8023
|
155
|
-
password "ssh password for sftp"
|
156
|
-
end
|
157
|
-
|
158
|
-
gpg do
|
159
|
-
command "/usr/local/bin/gpg"
|
160
|
-
options "--no-use-agent"
|
161
|
-
# symmetric encryption key
|
162
|
-
# password "qwe"
|
163
|
-
|
164
|
-
# public GPG key (must be known to GPG, i.e. be on the keyring)
|
165
|
-
key "backup@astrails.com"
|
166
|
-
end
|
167
|
-
|
168
|
-
keep do
|
169
|
-
local 20
|
170
|
-
s3 100
|
171
|
-
cloudfiles 100
|
172
|
-
sftp 100
|
173
|
-
end
|
174
|
-
|
175
|
-
mysqldump do
|
176
|
-
options "-ceKq --single-transaction --create-options"
|
177
|
-
|
178
|
-
user "root"
|
179
|
-
password "............"
|
180
|
-
socket "/var/run/mysqld/mysqld.sock"
|
181
|
-
|
182
|
-
database :blog
|
183
|
-
database :servershape
|
184
|
-
database :astrails_com
|
185
|
-
database :secret_project_com do
|
186
|
-
skip_tables "foo"
|
187
|
-
skip_tables ["bar", "baz"]
|
188
|
-
end
|
189
|
-
|
190
|
-
end
|
191
|
-
|
192
|
-
svndump do
|
193
|
-
repo :my_repo do
|
194
|
-
repo_path "/home/svn/my_repo"
|
195
|
-
end
|
196
|
-
end
|
197
|
-
|
198
|
-
pgdump do
|
199
|
-
options "-i -x -O" # -i => ignore version, -x => do not dump privileges (grant/revoke), -O => skip restoration of object ownership in plain text format
|
200
|
-
|
201
|
-
user "username"
|
202
|
-
password "............" # shouldn't be used, instead setup ident. Current functionality exports a password env to the shell which pg_dump uses - untested!
|
203
|
-
|
204
|
-
database :blog
|
205
|
-
database :stateofflux_com
|
206
|
-
end
|
207
|
-
|
208
|
-
tar do
|
209
|
-
options "-h" # dereference symlinks
|
210
|
-
archive "git-repositories", :files => "/home/git/repositories"
|
211
|
-
archive "dot-configs", :files => "/home/*/.[^.]*"
|
212
|
-
archive "etc", :files => "/etc", :exclude => "/etc/puppet/other"
|
213
|
-
|
214
|
-
archive "blog-astrails-com" do
|
215
|
-
files "/var/www/blog.astrails.com/"
|
216
|
-
exclude "/var/www/blog.astrails.com/log"
|
217
|
-
exclude "/var/www/blog.astrails.com/tmp"
|
218
|
-
end
|
219
|
-
|
220
|
-
archive "astrails-com" do
|
221
|
-
files "/var/www/astrails.com/"
|
222
|
-
exclude ["/var/www/astrails.com/log", "/var/www/astrails.com/tmp"]
|
223
|
-
end
|
224
|
-
end
|
232
|
+
archive "astrails-com" do
|
233
|
+
files "/var/www/astrails.com/"
|
234
|
+
exclude ["/var/www/astrails.com/log", "/var/www/astrails.com/tmp"]
|
225
235
|
end
|
236
|
+
end
|
237
|
+
end
|
238
|
+
```
|
226
239
|
|
227
240
|
## Contributing
|
228
241
|
|
data/bin/webtranslateit-safe
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require 'rubygems'
|
4
|
-
|
5
3
|
require 'webtranslateit/safe'
|
6
4
|
|
7
5
|
include WebTranslateIt::Safe
|
@@ -31,7 +29,7 @@ OPTS = [
|
|
31
29
|
'-n', '--dry-run', '--not-dry-run',
|
32
30
|
'-L', '--local', '--not-local'
|
33
31
|
].freeze
|
34
|
-
def main
|
32
|
+
def main # rubocop:todo Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity
|
35
33
|
opts = ARGV & OPTS
|
36
34
|
args = ARGV - OPTS
|
37
35
|
|
@@ -23,7 +23,7 @@ module WebTranslateIt
|
|
23
23
|
File.stat(path).size
|
24
24
|
end
|
25
25
|
|
26
|
-
def save
|
26
|
+
def save # rubocop:todo Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity
|
27
27
|
raise 'pipe-streaming not supported for S3.' unless @backup.path
|
28
28
|
|
29
29
|
# needed in cleanup even on dry run
|
@@ -44,7 +44,7 @@ module WebTranslateIt
|
|
44
44
|
puts("Upload took #{format('%.2f', benchmark)} second(s).") if verbose?
|
45
45
|
end
|
46
46
|
|
47
|
-
def cleanup
|
47
|
+
def cleanup # rubocop:todo Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/PerceivedComplexity
|
48
48
|
return if local_only?
|
49
49
|
|
50
50
|
return unless keep = config[:keep, :cloudfiles]
|
@@ -42,7 +42,7 @@ module WebTranslateIt
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
-
def mixed_value(*names)
|
45
|
+
def mixed_value(*names) # rubocop:todo Metrics/MethodLength
|
46
46
|
names.each do |m|
|
47
47
|
define_method(m) do |data = {}, &block|
|
48
48
|
ensure_uniq(m)
|
@@ -77,7 +77,7 @@ module WebTranslateIt
|
|
77
77
|
:api_key, :container, :socket, :service_net, :repo_path
|
78
78
|
multi_value :skip_tables, :exclude, :files
|
79
79
|
mixed_value :s3, :local, :cloudfiles, :sftp, :mysqldump, :tar, :gpg, :keep, :pgdump, :tar, :svndump,
|
80
|
-
:ftp, :mongodump
|
80
|
+
:ftp, :mongodump, :scp
|
81
81
|
collection :database, :archive, :repo
|
82
82
|
|
83
83
|
private
|
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'webtranslateit/safe/config/builder'
|
2
1
|
module WebTranslateIt
|
3
2
|
|
4
3
|
module Safe
|
@@ -9,10 +8,10 @@ module WebTranslateIt
|
|
9
8
|
|
10
9
|
attr_reader :parent, :data
|
11
10
|
|
12
|
-
def initialize(parent = nil, data = {}, &
|
11
|
+
def initialize(parent = nil, data = {}, &)
|
13
12
|
@parent = parent
|
14
13
|
@data = {}
|
15
|
-
merge
|
14
|
+
merge(data, &)
|
16
15
|
end
|
17
16
|
|
18
17
|
def merge(data = {}, &block)
|
@@ -47,8 +46,8 @@ module WebTranslateIt
|
|
47
46
|
end
|
48
47
|
alias []= set
|
49
48
|
|
50
|
-
def each(&
|
51
|
-
@data.each(&
|
49
|
+
def each(&)
|
50
|
+
@data.each(&)
|
52
51
|
end
|
53
52
|
include Enumerable
|
54
53
|
|
@@ -14,7 +14,7 @@ module WebTranslateIt
|
|
14
14
|
@path ||= expand(config[:ftp, :path] || config[:local, :path] || ':kind/:id')
|
15
15
|
end
|
16
16
|
|
17
|
-
def save
|
17
|
+
def save # rubocop:todo Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity
|
18
18
|
raise 'pipe-streaming not supported for FTP.' unless @backup.path
|
19
19
|
|
20
20
|
puts "Uploading #{host}:#{full_path} via FTP" if verbose? || dry_run?
|
@@ -35,7 +35,8 @@ module WebTranslateIt
|
|
35
35
|
puts '...done' if verbose?
|
36
36
|
end
|
37
37
|
|
38
|
-
|
38
|
+
# rubocop:todo Metrics/PerceivedComplexity
|
39
|
+
def cleanup # rubocop:todo Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/AbcSize, Metrics/MethodLength
|
39
40
|
return if local_only? || dry_run?
|
40
41
|
|
41
42
|
return unless keep = config[:keep, :ftp]
|
@@ -48,7 +49,7 @@ module WebTranslateIt
|
|
48
49
|
files = ftp.nlst(path)
|
49
50
|
pattern = File.basename(base.to_s)
|
50
51
|
files = files.select { |x| x.start_with?(pattern) }
|
51
|
-
puts
|
52
|
+
puts(files.collect { |x| x }) if verbose?
|
52
53
|
|
53
54
|
files = files
|
54
55
|
.collect { |x| x }
|
@@ -61,6 +62,7 @@ module WebTranslateIt
|
|
61
62
|
end
|
62
63
|
end
|
63
64
|
end
|
65
|
+
# rubocop:enable Metrics/PerceivedComplexity
|
64
66
|
|
65
67
|
def host
|
66
68
|
config[:ftp, :host]
|
@@ -16,7 +16,7 @@ module WebTranslateIt
|
|
16
16
|
@path ||= File.expand_path(expand(config[:local, :path] || raise('missing :local/:path')))
|
17
17
|
end
|
18
18
|
|
19
|
-
def save
|
19
|
+
def save # rubocop:todo Metrics/AbcSize
|
20
20
|
puts "command: #{@backup.command}" if verbose?
|
21
21
|
|
22
22
|
# FIXME: probably need to change this to smth like @backup.finalize!
|
@@ -31,7 +31,7 @@ module WebTranslateIt
|
|
31
31
|
puts("command took #{format('%.2f', benchmark)} second(s).") if verbose?
|
32
32
|
end
|
33
33
|
|
34
|
-
def cleanup
|
34
|
+
def cleanup # rubocop:todo Metrics/CyclomaticComplexity, Metrics/AbcSize
|
35
35
|
return unless keep = config[:keep, :local]
|
36
36
|
|
37
37
|
puts "listing files #{base}" if verbose?
|
@@ -16,7 +16,7 @@ module WebTranslateIt
|
|
16
16
|
@path ||= expand(config[:s3, :path] || config[:local, :path] || ':kind/:id')
|
17
17
|
end
|
18
18
|
|
19
|
-
def save
|
19
|
+
def save # rubocop:todo Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity
|
20
20
|
# FIXME: user friendly error here :)
|
21
21
|
raise 'pipe-streaming not supported for S3.' unless @backup.path
|
22
22
|
|
@@ -40,7 +40,8 @@ module WebTranslateIt
|
|
40
40
|
puts("Upload took #{format('%.2f', benchmark)} second(s).") if verbose?
|
41
41
|
end
|
42
42
|
|
43
|
-
|
43
|
+
# rubocop:todo Metrics/PerceivedComplexity
|
44
|
+
def cleanup # rubocop:todo Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/AbcSize, Metrics/MethodLength
|
44
45
|
return if local_only?
|
45
46
|
|
46
47
|
return unless keep = config[:keep, :s3]
|
@@ -58,6 +59,7 @@ module WebTranslateIt
|
|
58
59
|
AWS::S3::Bucket.objects(bucket, prefix: f)[0].delete unless dry_run? || local_only?
|
59
60
|
end
|
60
61
|
end
|
62
|
+
# rubocop:enable Metrics/PerceivedComplexity
|
61
63
|
|
62
64
|
def bucket
|
63
65
|
config[:s3, :bucket]
|
@@ -0,0 +1,109 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module WebTranslateIt
|
4
|
+
|
5
|
+
module Safe
|
6
|
+
|
7
|
+
class Scp < Sink
|
8
|
+
|
9
|
+
MAX_RETRIES = 5
|
10
|
+
|
11
|
+
protected
|
12
|
+
|
13
|
+
def active?
|
14
|
+
host && user
|
15
|
+
end
|
16
|
+
|
17
|
+
def path
|
18
|
+
@path ||= expand(config[:scp, :path] || config[:local, :path] || ':kind/:id')
|
19
|
+
end
|
20
|
+
|
21
|
+
def save # rubocop:todo Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/MethodLength
|
22
|
+
raise 'pipe-streaming not supported for SCP.' unless @backup.path
|
23
|
+
|
24
|
+
puts "Uploading #{host}:#{full_path} via SCP" if verbose? || dry_run?
|
25
|
+
|
26
|
+
return if dry_run? || local_only?
|
27
|
+
|
28
|
+
retries = 0
|
29
|
+
opts = {}
|
30
|
+
opts[:password] = password if password
|
31
|
+
opts[:port] = port if port
|
32
|
+
Net::SCP.start(host, user, opts) do |scp|
|
33
|
+
puts "Sending #{@backup.path} to #{full_path}" if verbose?
|
34
|
+
begin
|
35
|
+
scp.upload! @backup.path, full_path
|
36
|
+
rescue IO::TimeoutError
|
37
|
+
puts 'Upload timed out, retrying'
|
38
|
+
retries += 1
|
39
|
+
if retries >= MAX_RETRIES
|
40
|
+
puts "Tried #{retries} times. Giving up."
|
41
|
+
else
|
42
|
+
retry unless retries >= MAX_RETRIES
|
43
|
+
end
|
44
|
+
rescue Net::SCP::Error
|
45
|
+
puts "Ensuring remote path (#{path}) exists" if verbose?
|
46
|
+
# mkdir -p
|
47
|
+
folders = path.split('/')
|
48
|
+
folders.each_index do |i|
|
49
|
+
folder = folders[0..i].join('/')
|
50
|
+
puts "Creating #{folder} on remote" if verbose?
|
51
|
+
begin
|
52
|
+
scp.mkdir!(folder)
|
53
|
+
rescue StandardError
|
54
|
+
Net::SCP::Error
|
55
|
+
end
|
56
|
+
end
|
57
|
+
retry
|
58
|
+
end
|
59
|
+
end
|
60
|
+
puts '...done' if verbose?
|
61
|
+
end
|
62
|
+
|
63
|
+
# rubocop:todo Metrics/PerceivedComplexity
|
64
|
+
def cleanup # rubocop:todo Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/AbcSize, Metrics/MethodLength
|
65
|
+
return if local_only? || dry_run?
|
66
|
+
|
67
|
+
return unless (keep = config[:keep, :scp])
|
68
|
+
|
69
|
+
puts "listing files: #{host}:#{base}*" if verbose?
|
70
|
+
opts = {}
|
71
|
+
opts[:password] = password if password
|
72
|
+
opts[:port] = port if port
|
73
|
+
Net::SFTP.start(host, user, opts) do |sftp|
|
74
|
+
files = sftp.dir.glob(path, File.basename("#{base}*"))
|
75
|
+
|
76
|
+
puts files.collect(&:name) if verbose?
|
77
|
+
|
78
|
+
files = files.collect(&:name).sort
|
79
|
+
|
80
|
+
cleanup_with_limit(files, keep) do |f|
|
81
|
+
file = File.join(path, f)
|
82
|
+
puts "removing sftp file #{host}:#{file}" if dry_run? || verbose?
|
83
|
+
sftp.remove!(file) unless dry_run? || local_only?
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
# rubocop:enable Metrics/PerceivedComplexity
|
88
|
+
|
89
|
+
def host
|
90
|
+
config[:scp, :host]
|
91
|
+
end
|
92
|
+
|
93
|
+
def user
|
94
|
+
config[:scp, :user]
|
95
|
+
end
|
96
|
+
|
97
|
+
def password
|
98
|
+
config[:scp, :password]
|
99
|
+
end
|
100
|
+
|
101
|
+
def port
|
102
|
+
config[:scp, :port]
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
@@ -16,7 +16,7 @@ module WebTranslateIt
|
|
16
16
|
@path ||= expand(config[:sftp, :path] || config[:local, :path] || ':kind/:id')
|
17
17
|
end
|
18
18
|
|
19
|
-
def save # rubocop:todo Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
19
|
+
def save # rubocop:todo Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/MethodLength
|
20
20
|
raise 'pipe-streaming not supported for SFTP.' unless @backup.path
|
21
21
|
|
22
22
|
puts "Uploading #{host}:#{full_path} via SFTP" if verbose? || dry_run?
|
@@ -58,7 +58,8 @@ module WebTranslateIt
|
|
58
58
|
puts '...done' if verbose?
|
59
59
|
end
|
60
60
|
|
61
|
-
|
61
|
+
# rubocop:todo Metrics/PerceivedComplexity
|
62
|
+
def cleanup # rubocop:todo Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/AbcSize, Metrics/MethodLength
|
62
63
|
return if local_only? || dry_run?
|
63
64
|
|
64
65
|
return unless keep = config[:keep, :sftp]
|
@@ -81,6 +82,7 @@ module WebTranslateIt
|
|
81
82
|
end
|
82
83
|
end
|
83
84
|
end
|
85
|
+
# rubocop:enable Metrics/PerceivedComplexity
|
84
86
|
|
85
87
|
def host
|
86
88
|
config[:sftp, :host]
|
@@ -25,12 +25,12 @@ module WebTranslateIt
|
|
25
25
|
end
|
26
26
|
|
27
27
|
# call block on files to be removed (all except for the LAST 'limit' files
|
28
|
-
def cleanup_with_limit(files, limit, &
|
28
|
+
def cleanup_with_limit(files, limit, &)
|
29
29
|
return unless files.size > limit
|
30
30
|
|
31
31
|
to_remove = files[0..(files.size - limit - 1)]
|
32
32
|
# TODO: validate here
|
33
|
-
to_remove.each(&
|
33
|
+
to_remove.each(&)
|
34
34
|
end
|
35
35
|
|
36
36
|
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'aws/s3'
|
2
|
+
require 'cloudfiles'
|
3
|
+
require 'net/sftp'
|
4
|
+
require 'net/scp'
|
5
|
+
require 'tmpdir'
|
6
|
+
require 'fileutils'
|
7
|
+
require 'benchmark'
|
8
|
+
|
9
|
+
require 'tempfile'
|
10
|
+
|
11
|
+
require 'web_translate_it/safe/tmp_file'
|
12
|
+
|
13
|
+
require 'web_translate_it/safe/config/node'
|
14
|
+
require 'web_translate_it/safe/config/builder'
|
15
|
+
|
16
|
+
require 'web_translate_it/safe/stream'
|
17
|
+
|
18
|
+
require 'web_translate_it/safe/backup'
|
19
|
+
|
20
|
+
require 'web_translate_it/safe/source'
|
21
|
+
require 'web_translate_it/safe/mysqldump'
|
22
|
+
require 'web_translate_it/safe/pgdump'
|
23
|
+
require 'web_translate_it/safe/archive'
|
24
|
+
require 'web_translate_it/safe/svndump'
|
25
|
+
require 'web_translate_it/safe/mongodump'
|
26
|
+
|
27
|
+
require 'web_translate_it/safe/pipe'
|
28
|
+
require 'web_translate_it/safe/gpg'
|
29
|
+
require 'web_translate_it/safe/gzip'
|
30
|
+
|
31
|
+
require 'web_translate_it/safe/sink'
|
32
|
+
require 'web_translate_it/safe/local'
|
33
|
+
require 'web_translate_it/safe/s3'
|
34
|
+
require 'web_translate_it/safe/cloudfiles'
|
35
|
+
require 'web_translate_it/safe/scp'
|
36
|
+
require 'web_translate_it/safe/sftp'
|
37
|
+
require 'web_translate_it/safe/ftp'
|
38
|
+
|
39
|
+
module WebTranslateIt
|
40
|
+
|
41
|
+
module Safe
|
42
|
+
|
43
|
+
ROOT = File.join(File.dirname(__FILE__), '..', '..')
|
44
|
+
|
45
|
+
def safe(&)
|
46
|
+
Config::Node.new(&)
|
47
|
+
end
|
48
|
+
|
49
|
+
def process(config)
|
50
|
+
[[Mysqldump, %i[mysqldump databases]],
|
51
|
+
[Pgdump, %i[pgdump databases]],
|
52
|
+
[Mongodump, %i[mongodump databases]],
|
53
|
+
[Archive, %i[tar archives]],
|
54
|
+
[Svndump, %i[svndump repos]]].each do |klass, path|
|
55
|
+
next unless collection = config[*path]
|
56
|
+
|
57
|
+
collection.each do |name, c|
|
58
|
+
klass.new(name, c).backup.run(c, :gpg, :gzip, :local, :s3, :cloudfiles, :scp, :sftp, :ftp)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
WebTranslateIt::Safe::TmpFile.cleanup
|
63
|
+
end
|
64
|
+
module_function :safe
|
65
|
+
module_function :process
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: webtranslateit-safe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Edouard Briere
|
@@ -39,6 +39,20 @@ dependencies:
|
|
39
39
|
- - ">="
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: net-scp
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :runtime
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
42
56
|
- !ruby/object:Gem::Dependency
|
43
57
|
name: net-sftp
|
44
58
|
requirement: !ruby/object:Gem::Requirement
|
@@ -67,27 +81,28 @@ files:
|
|
67
81
|
- CHANGELOG
|
68
82
|
- README.markdown
|
69
83
|
- bin/webtranslateit-safe
|
70
|
-
- lib/
|
71
|
-
- lib/
|
72
|
-
- lib/
|
73
|
-
- lib/
|
74
|
-
- lib/
|
75
|
-
- lib/
|
76
|
-
- lib/
|
77
|
-
- lib/
|
78
|
-
- lib/
|
79
|
-
- lib/
|
80
|
-
- lib/
|
81
|
-
- lib/
|
82
|
-
- lib/
|
83
|
-
- lib/
|
84
|
-
- lib/
|
85
|
-
- lib/
|
86
|
-
- lib/
|
87
|
-
- lib/
|
88
|
-
- lib/
|
89
|
-
- lib/
|
90
|
-
- lib/
|
84
|
+
- lib/web_translate_it/safe.rb
|
85
|
+
- lib/web_translate_it/safe/archive.rb
|
86
|
+
- lib/web_translate_it/safe/backup.rb
|
87
|
+
- lib/web_translate_it/safe/cloudfiles.rb
|
88
|
+
- lib/web_translate_it/safe/config/builder.rb
|
89
|
+
- lib/web_translate_it/safe/config/node.rb
|
90
|
+
- lib/web_translate_it/safe/ftp.rb
|
91
|
+
- lib/web_translate_it/safe/gpg.rb
|
92
|
+
- lib/web_translate_it/safe/gzip.rb
|
93
|
+
- lib/web_translate_it/safe/local.rb
|
94
|
+
- lib/web_translate_it/safe/mongodump.rb
|
95
|
+
- lib/web_translate_it/safe/mysqldump.rb
|
96
|
+
- lib/web_translate_it/safe/pgdump.rb
|
97
|
+
- lib/web_translate_it/safe/pipe.rb
|
98
|
+
- lib/web_translate_it/safe/s3.rb
|
99
|
+
- lib/web_translate_it/safe/scp.rb
|
100
|
+
- lib/web_translate_it/safe/sftp.rb
|
101
|
+
- lib/web_translate_it/safe/sink.rb
|
102
|
+
- lib/web_translate_it/safe/source.rb
|
103
|
+
- lib/web_translate_it/safe/stream.rb
|
104
|
+
- lib/web_translate_it/safe/svndump.rb
|
105
|
+
- lib/web_translate_it/safe/tmp_file.rb
|
91
106
|
homepage: http://github.com/webtranslateit/safe
|
92
107
|
licenses:
|
93
108
|
- MIT
|
data/lib/webtranslateit/safe.rb
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
require 'aws/s3'
|
2
|
-
require 'cloudfiles'
|
3
|
-
require 'net/sftp'
|
4
|
-
# require 'net/ftp'
|
5
|
-
require 'fileutils'
|
6
|
-
require 'benchmark'
|
7
|
-
|
8
|
-
require 'tempfile'
|
9
|
-
|
10
|
-
require 'webtranslateit/safe/tmp_file'
|
11
|
-
|
12
|
-
require 'webtranslateit/safe/config/node'
|
13
|
-
require 'webtranslateit/safe/config/builder'
|
14
|
-
|
15
|
-
require 'webtranslateit/safe/stream'
|
16
|
-
|
17
|
-
require 'webtranslateit/safe/backup'
|
18
|
-
|
19
|
-
require 'webtranslateit/safe/source'
|
20
|
-
require 'webtranslateit/safe/mysqldump'
|
21
|
-
require 'webtranslateit/safe/pgdump'
|
22
|
-
require 'webtranslateit/safe/archive'
|
23
|
-
require 'webtranslateit/safe/svndump'
|
24
|
-
require 'webtranslateit/safe/mongodump'
|
25
|
-
|
26
|
-
require 'webtranslateit/safe/pipe'
|
27
|
-
require 'webtranslateit/safe/gpg'
|
28
|
-
require 'webtranslateit/safe/gzip'
|
29
|
-
|
30
|
-
require 'webtranslateit/safe/sink'
|
31
|
-
require 'webtranslateit/safe/local'
|
32
|
-
require 'webtranslateit/safe/s3'
|
33
|
-
require 'webtranslateit/safe/cloudfiles'
|
34
|
-
require 'webtranslateit/safe/sftp'
|
35
|
-
require 'webtranslateit/safe/ftp'
|
36
|
-
|
37
|
-
module WebTranslateIt
|
38
|
-
|
39
|
-
module Safe
|
40
|
-
|
41
|
-
ROOT = File.join(File.dirname(__FILE__), '..', '..')
|
42
|
-
|
43
|
-
def safe(&block)
|
44
|
-
Config::Node.new(&block)
|
45
|
-
end
|
46
|
-
|
47
|
-
def process(config)
|
48
|
-
[[Mysqldump, %i[mysqldump databases]],
|
49
|
-
[Pgdump, %i[pgdump databases]],
|
50
|
-
[Mongodump, %i[mongodump databases]],
|
51
|
-
[Archive, %i[tar archives]],
|
52
|
-
[Svndump, %i[svndump repos]]].each do |klass, path|
|
53
|
-
next unless collection = config[*path]
|
54
|
-
|
55
|
-
collection.each do |name, c|
|
56
|
-
klass.new(name, c).backup.run(c, :gpg, :gzip, :local, :s3, :cloudfiles, :sftp, :ftp)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
WebTranslateIt::Safe::TmpFile.cleanup
|
61
|
-
end
|
62
|
-
module_function :safe
|
63
|
-
module_function :process
|
64
|
-
|
65
|
-
end
|
66
|
-
|
67
|
-
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|