s3_meta_sync 0.3.0 → 0.3.1
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
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/s3_meta_sync.rb +34 -19
- data/lib/s3_meta_sync/version.rb +1 -1
- metadata +2 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7e7e8df15d87392103c01db3a50028655bfaeee1
|
4
|
+
data.tar.gz: eb8535f78ac0c43e5446f24d940c40f927548e97
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16603033e2b2c25c91df705cb4ae1ecefcd94bf79f2cb5859986a828e980ae882a99c6bbb9643bdd219d335bf67a4caaea95d6e150bf87a6d85cc211c19dfa1b
|
7
|
+
data.tar.gz: 25154a729785baf27091469c2a08b735b80105d829f2e01368a6ad539212539a155ba6ca4edb6410f9cb1582c95ee3c2e3a9e672b42a4c868637b54e6b1660d8
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/s3_meta_sync.rb
CHANGED
@@ -19,6 +19,7 @@ module S3MetaSync
|
|
19
19
|
RemoteWithoutMeta = Class.new(Exception)
|
20
20
|
RemoteCorrupt = Class.new(Exception)
|
21
21
|
META_FILE = ".s3-meta-sync"
|
22
|
+
CORRUPT_FILES_LOG = "s3-meta-sync-corrupted.log"
|
22
23
|
|
23
24
|
class Syncer
|
24
25
|
def initialize(config)
|
@@ -40,15 +41,16 @@ module S3MetaSync
|
|
40
41
|
private
|
41
42
|
|
42
43
|
def upload(source, destination)
|
44
|
+
corrupted = consume_corrupted_files(source)
|
43
45
|
remote_info = begin
|
44
46
|
download_meta(destination)
|
45
47
|
rescue RemoteWithoutMeta
|
46
|
-
log "Remote has no .s3-meta-sync, uploading everything"
|
48
|
+
log "Remote has no .s3-meta-sync, uploading everything", true
|
47
49
|
{}
|
48
50
|
end
|
49
51
|
generate_meta(source)
|
50
52
|
local_info = read_meta(source)
|
51
|
-
upload = local_info.select { |path, md5| remote_info[path] != md5 }.map(&:first)
|
53
|
+
upload = local_info.select { |path, md5| remote_info[path] != md5 }.map(&:first) | corrupted
|
52
54
|
delete = remote_info.keys - local_info.keys
|
53
55
|
log "Uploading: #{upload.size} Deleting: #{delete.size}", true
|
54
56
|
|
@@ -67,14 +69,14 @@ module S3MetaSync
|
|
67
69
|
log "Downloading: #{download.size} Deleting: #{delete.size}", true
|
68
70
|
|
69
71
|
unless download.empty? && delete.empty?
|
70
|
-
Dir.mktmpdir do |
|
71
|
-
copy_content(destination,
|
72
|
-
download_files(source,
|
73
|
-
delete_local_files(
|
74
|
-
download_file(source, META_FILE,
|
75
|
-
verify_integrity!(
|
76
|
-
delete_empty_folders(
|
77
|
-
swap_in_directory(destination,
|
72
|
+
Dir.mktmpdir do |staging_area|
|
73
|
+
copy_content(destination, staging_area)
|
74
|
+
download_files(source, staging_area, download)
|
75
|
+
delete_local_files(staging_area, delete)
|
76
|
+
download_file(source, META_FILE, staging_area)
|
77
|
+
verify_integrity!(staging_area, destination)
|
78
|
+
delete_empty_folders(staging_area)
|
79
|
+
swap_in_directory(destination, staging_area)
|
78
80
|
end
|
79
81
|
end
|
80
82
|
end
|
@@ -89,17 +91,29 @@ module S3MetaSync
|
|
89
91
|
FileUtils.mkdir(dir) # make ensure in outside mktmpdir not blow up
|
90
92
|
end
|
91
93
|
|
92
|
-
def verify_integrity!(
|
93
|
-
file = "#{
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
if
|
98
|
-
|
94
|
+
def verify_integrity!(staging_area, destination)
|
95
|
+
file = "#{staging_area}/#{META_FILE}"
|
96
|
+
downloaded = YAML.load_file(file)
|
97
|
+
actual = meta_data(staging_area)
|
98
|
+
|
99
|
+
if downloaded != actual
|
100
|
+
corrupted = actual.select { |file, md5| downloaded[file] != md5 }.map(&:first)
|
101
|
+
File.write("#{destination}/#{CORRUPT_FILES_LOG}", corrupted.join("\n"))
|
102
|
+
log "corrupted files downloaded:\n#{corrupted.join("\n")}", true
|
99
103
|
raise RemoteCorrupt
|
100
104
|
end
|
101
|
-
|
102
|
-
|
105
|
+
end
|
106
|
+
|
107
|
+
def consume_corrupted_files(source)
|
108
|
+
log = "#{source}/#{CORRUPT_FILES_LOG}"
|
109
|
+
if File.exist?(log)
|
110
|
+
corrupted = File.read(log).split("\n")
|
111
|
+
log "force uploading #{corrupted.size} corrupted files", true
|
112
|
+
File.unlink log
|
113
|
+
corrupted
|
114
|
+
else
|
115
|
+
[]
|
116
|
+
end
|
103
117
|
end
|
104
118
|
|
105
119
|
def upload_file(source, path, destination)
|
@@ -236,6 +250,7 @@ module S3MetaSync
|
|
236
250
|
opts.on("-s", "--secret SECRET", "AWS secret key") { |c| options[:secret] = c }
|
237
251
|
opts.on("-r", "--region REGION", "AWS region if not us-standard") { |c| options[:region] = c }
|
238
252
|
opts.on("-p", "--parallel COUNT", Integer, "Use COUNT threads for download/upload default: 10") { |c| options[:parallel] = c }
|
253
|
+
opts.on("--log-corrupted-files", "Log corrupted files, they will be force uploaded on the next run") { |c| options[:log_corrupted_files] = true }
|
239
254
|
opts.on("--ssl-none", "Do not verify ssl certs") { |c| options[:ssl_none] = true }
|
240
255
|
opts.on("-V", "--verbose", "Verbose mode"){ options[:verbose] = true }
|
241
256
|
opts.on("-h", "--help", "Show this.") { puts opts; exit }
|
data/lib/s3_meta_sync/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: s3_meta_sync
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Grosser
|
@@ -30,7 +30,7 @@ cert_chain:
|
|
30
30
|
F5etKHZg0j3eHO31/i2HnswY04lqGImUu6aM5EnijFTB7PPW2KwKKM4+kKDYFdlw
|
31
31
|
/0WV1Ng2/Y6qsHwmqGg2VlYj2h4=
|
32
32
|
-----END CERTIFICATE-----
|
33
|
-
date: 2014-
|
33
|
+
date: 2014-03-01 00:00:00.000000000 Z
|
34
34
|
dependencies:
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: aws-sdk
|
metadata.gz.sig
CHANGED
Binary file
|