s3_meta_sync 0.10.0 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/s3_meta_sync.rb +1 -0
- data/lib/s3_meta_sync/syncer.rb +41 -18
- data/lib/s3_meta_sync/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e68ff7b84c212d7cc29205287b35c9fa181303c1
|
4
|
+
data.tar.gz: ed8e7d21833f827d6e10e092d6a257fb3b03e29e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b0e3edc1923c29beed3247808673e97d805f674564ab2ff1bf4133d2035f04d5af6b7e7a6ea374d8191342a327b8c55414e09a4f5ce01a2fc0282a5a6d174cf4
|
7
|
+
data.tar.gz: 0b2ebf35c1eb061fc6d3ff6bb47ce9b8818cba8622142e739bdc6f8601946262a74b77213dc5c9c10b8fbc8928cc75d53a607cfccc8ba8953123171a89bc853e
|
data/lib/s3_meta_sync.rb
CHANGED
@@ -42,6 +42,7 @@ module S3MetaSync
|
|
42
42
|
opts.on("--ssl-none", "Do not verify ssl certs") { options[:ssl_none] = true }
|
43
43
|
opts.on("-z", "--zip", "Zip when uploading to save bandwidth") { options[:zip] = true }
|
44
44
|
opts.on("--no-local-changes", "Do not md5 all the local files, they did not change") { options[:no_local_changes] = true }
|
45
|
+
opts.on("--retries MAX", Integer, "MAX number of times retrying failed http requests default: 2") { |c| options[:max_retries] = c }
|
45
46
|
opts.on("-V", "--verbose", "Verbose mode"){ options[:verbose] = true }
|
46
47
|
opts.on("-h", "--help", "Show this.") { puts opts; exit }
|
47
48
|
opts.on("-v", "--version", "Show Version") { puts VERSION; exit}
|
data/lib/s3_meta_sync/syncer.rb
CHANGED
@@ -11,6 +11,7 @@ require "s3_meta_sync/zip"
|
|
11
11
|
module S3MetaSync
|
12
12
|
class Syncer
|
13
13
|
DEFAULT_REGION = 'us-east-1'
|
14
|
+
STAGING_AREA_PREFIX = "s3ms_"
|
14
15
|
|
15
16
|
def initialize(config)
|
16
17
|
@config = config
|
@@ -59,6 +60,8 @@ module S3MetaSync
|
|
59
60
|
end
|
60
61
|
|
61
62
|
def download(source, destination)
|
63
|
+
delete_old_temp_folders
|
64
|
+
|
62
65
|
remote_meta = download_meta(source)
|
63
66
|
local_files = ((@config[:no_local_changes] && read_meta(destination)) || meta_data(destination))[:files]
|
64
67
|
|
@@ -68,7 +71,8 @@ module S3MetaSync
|
|
68
71
|
log "Downloading: #{download.size} Deleting: #{delete.size}", true
|
69
72
|
|
70
73
|
if download.any? || delete.any?
|
71
|
-
Dir.mktmpdir do |staging_area|
|
74
|
+
Dir.mktmpdir(STAGING_AREA_PREFIX) do |staging_area|
|
75
|
+
log "Staging area: #{staging_area}"
|
72
76
|
FileUtils.mkdir_p(destination)
|
73
77
|
copy_content(destination, staging_area)
|
74
78
|
download_files(source, staging_area, download, remote_meta[:zip])
|
@@ -83,7 +87,21 @@ module S3MetaSync
|
|
83
87
|
end
|
84
88
|
end
|
85
89
|
|
90
|
+
# Sometimes SIGTERM causes Dir.mktmpdir to not properly delete the temp folder
|
91
|
+
# Remove 1 day old folders
|
92
|
+
def delete_old_temp_folders
|
93
|
+
path = File.join(Dir.tmpdir, STAGING_AREA_PREFIX + '*')
|
94
|
+
|
95
|
+
day = 24 * 60 * 60
|
96
|
+
dirs = Dir.glob(path)
|
97
|
+
dirs.select! { |dir| Time.now.utc - File.ctime(dir).utc > day } # only stale ones
|
98
|
+
removed = dirs.each { |dir| FileUtils.rm_rf(dir) }
|
99
|
+
|
100
|
+
log "Removed #{removed} old temp folder(s)" if removed.count > 0
|
101
|
+
end
|
102
|
+
|
86
103
|
def copy_content(destination, dir)
|
104
|
+
log "Copying content from #{destination} to #{dir}"
|
87
105
|
system "cp -R #{destination}/* #{dir} 2>/dev/null"
|
88
106
|
end
|
89
107
|
|
@@ -209,13 +227,13 @@ module S3MetaSync
|
|
209
227
|
content = download_content("#{destination}/#{META_FILE}") { |io| io.read }
|
210
228
|
parse_yaml_content(content)
|
211
229
|
rescue OpenURI::HTTPError
|
212
|
-
retries ||=
|
213
|
-
|
214
|
-
|
215
|
-
else
|
216
|
-
retries += 1
|
230
|
+
retries ||= 0
|
231
|
+
retries += 1
|
232
|
+
if retries <= 1
|
217
233
|
sleep 1 # maybe the remote meta was just updated ... give aws a second chance ...
|
218
234
|
retry
|
235
|
+
else
|
236
|
+
raise RemoteWithoutMeta
|
219
237
|
end
|
220
238
|
end
|
221
239
|
|
@@ -244,22 +262,27 @@ module S3MetaSync
|
|
244
262
|
"https://s3#{"-#{region}" if region}.amazonaws.com/#{@bucket}/#{path}"
|
245
263
|
end
|
246
264
|
options = (@config[:ssl_none] ? {:ssl_verify_mode => OpenSSL::SSL::VERIFY_NONE} : {})
|
247
|
-
open(url, options)
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
265
|
+
retry_downloads(url: url) { open(url, options) }
|
266
|
+
end
|
267
|
+
|
268
|
+
def retry_downloads(url:)
|
269
|
+
yield
|
270
|
+
rescue OpenURI::HTTPError, Errno::ECONNRESET => e
|
271
|
+
max_retries = @config[:max_retries] || 2
|
272
|
+
http_error_retries ||= 0
|
273
|
+
http_error_retries += 1
|
274
|
+
if http_error_retries <= max_retries
|
275
|
+
log "#{e.class} error downloading #{url}, retrying #{http_error_retries}/#{max_retries}"
|
276
|
+
retry
|
277
|
+
else
|
252
278
|
$!.message << " -- while trying to download #{url}"
|
253
279
|
raise
|
254
|
-
else
|
255
|
-
log "HTTP Error downloading #{path}, retrying"
|
256
|
-
retry
|
257
280
|
end
|
258
281
|
rescue OpenSSL::SSL::SSLError
|
259
|
-
|
260
|
-
|
261
|
-
if
|
262
|
-
log "SSL error downloading #{
|
282
|
+
ssl_error_retries ||= 0
|
283
|
+
ssl_error_retries += 1
|
284
|
+
if ssl_error_retries == 1
|
285
|
+
log "SSL error downloading #{url}, retrying"
|
263
286
|
retry
|
264
287
|
else
|
265
288
|
raise
|
data/lib/s3_meta_sync/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: s3_meta_sync
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Grosser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-08-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk-core
|
@@ -56,7 +56,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
56
56
|
version: '0'
|
57
57
|
requirements: []
|
58
58
|
rubyforge_project:
|
59
|
-
rubygems_version: 2.
|
59
|
+
rubygems_version: 2.6.11
|
60
60
|
signing_key:
|
61
61
|
specification_version: 4
|
62
62
|
summary: Sync folders with s3 using a metadata file and md5 diffs
|