s3simplesync 0.0.9 → 0.0.10
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/lib/s3sync/logger.rb +22 -0
- data/lib/s3sync/syncer.rb +16 -19
- data/lib/s3sync/version.rb +1 -1
- data/lib/s3sync.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 07f36aa09435a50d56ce957b0be9eb995279e6e6
|
4
|
+
data.tar.gz: ad085a9c9cb2869be6feb75c56d35fe2c7b4808a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 115f20bbc2331b3fb4e4c016e0058a297d244a9e2828b7670f46ff9f08b0527a90e0d5c9ed4fc90966fe766afeade80cf0a3a5ca2af75bb6d2f71b17670eabfa
|
7
|
+
data.tar.gz: ef1158237193fd6d3e9e56c2caa42d6d95c2a4a0d836e013fa5913984d99c283d6776642be5835de862b7b82b40c98f4df8834230efba710bc81c4c815c8d79c
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'syslog/logger'
|
2
|
+
|
3
|
+
module S3sync
|
4
|
+
|
5
|
+
class Logger
|
6
|
+
def initialize
|
7
|
+
@log = Syslog::Logger.new 'S3sync'
|
8
|
+
end
|
9
|
+
|
10
|
+
def info(message)
|
11
|
+
return puts message if ENV['DEBUG']
|
12
|
+
@log.info "INFO: #{message}"
|
13
|
+
end
|
14
|
+
|
15
|
+
def error(e)
|
16
|
+
message = "ERROR: #{e.message} #{e.backtrace.inspect}"
|
17
|
+
return puts message if ENV['DEBUG']
|
18
|
+
@log.error message
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
data/lib/s3sync/syncer.rb
CHANGED
@@ -1,21 +1,19 @@
|
|
1
1
|
require 'find'
|
2
2
|
require 'fileutils'
|
3
|
-
require 'syslog/logger'
|
4
3
|
|
5
4
|
module S3sync
|
6
5
|
|
7
6
|
class Syncer
|
8
7
|
def initialize
|
9
8
|
@s3 = AWS::S3.new
|
10
|
-
@log =
|
9
|
+
@log = S3sync::Logger.new
|
11
10
|
end
|
12
11
|
|
13
12
|
def upload(local_path, s3_url)
|
14
13
|
bucket_name, *folders = s3url_to_bucket_folder s3_url
|
15
14
|
|
16
|
-
log "Uploading files"
|
17
|
-
|
18
|
-
# as better performance than computing a diff of 2 complete directory listings
|
15
|
+
@log.info "Uploading files"
|
16
|
+
|
19
17
|
local_files = local_files(local_path)
|
20
18
|
remote_files(bucket_name, folders) do |s3|
|
21
19
|
source = local_files[s3[:key]]
|
@@ -24,37 +22,34 @@ module S3sync
|
|
24
22
|
|
25
23
|
local_files.each do |key,item|
|
26
24
|
s3_key = File.join folders, key
|
27
|
-
log "#{item[:file]} => s3://#{bucket_name}/#{s3_key}"
|
25
|
+
@log.info "#{item[:file]} => s3://#{bucket_name}/#{s3_key}"
|
28
26
|
s3_upload item, bucket_name, s3_key
|
29
27
|
end
|
30
|
-
log "
|
31
|
-
|
28
|
+
@log.info "Done"
|
29
|
+
rescue Exception => e
|
30
|
+
@log.error e
|
32
31
|
end
|
33
32
|
|
34
33
|
def download(s3_location, local_path)
|
35
34
|
bucket_name, *folders = s3url_to_bucket_folder s3_location
|
36
35
|
destination_folder = File.absolute_path(local_path)
|
37
36
|
|
38
|
-
log "Downloading"
|
39
|
-
|
40
|
-
# as better performance than computing a diff of 2 complete directory listings
|
37
|
+
@log.info "Downloading"
|
38
|
+
|
41
39
|
local_files = local_files(local_path)
|
42
40
|
remote_files(bucket_name, folders) do |s3|
|
43
41
|
next if FileDiff::same_file? s3, local_files[s3[:key]]
|
44
42
|
destination_file = File.join destination_folder, s3[:key]
|
45
|
-
log "#{s3[:file].public_url} => #{destination_file}"
|
43
|
+
@log.info "#{s3[:file].public_url} => #{destination_file}"
|
46
44
|
s3_download s3, destination_file
|
47
45
|
end
|
48
|
-
log "
|
46
|
+
@log.info "Done"
|
47
|
+
rescue Exception => e
|
48
|
+
@log.error e
|
49
49
|
end
|
50
50
|
|
51
51
|
private
|
52
52
|
|
53
|
-
def log(message)
|
54
|
-
return puts message if ENV['DEBUG']
|
55
|
-
@log.info message
|
56
|
-
end
|
57
|
-
|
58
53
|
def ensure_folder_exists(folder)
|
59
54
|
FileUtils.mkdir_p(folder) unless File.directory?(folder)
|
60
55
|
end
|
@@ -85,7 +80,7 @@ module S3sync
|
|
85
80
|
|
86
81
|
def s3url_to_bucket_folder(s3_location)
|
87
82
|
s3_path = s3_location.match(/s3:\/\/(.*)/)[1] rescue nil
|
88
|
-
|
83
|
+
raise 'Invalid S3 url must be s3://bucket form' unless s3_path
|
89
84
|
|
90
85
|
s3_path.split /\//
|
91
86
|
end
|
@@ -116,6 +111,8 @@ module S3sync
|
|
116
111
|
file:object }
|
117
112
|
end
|
118
113
|
|
114
|
+
# Yielding the remote s3 files and doing a 2 pass filter
|
115
|
+
# as better performance than computing a diff of 2 complete directory listings
|
119
116
|
def remote_files(bucket, folders)
|
120
117
|
objects = @s3.buckets[bucket].objects.with_prefix(File.join(folders))
|
121
118
|
objects.each do |object|
|
data/lib/s3sync/version.rb
CHANGED
data/lib/s3sync.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: s3simplesync
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christian Blunden
|
@@ -72,6 +72,7 @@ files:
|
|
72
72
|
- bin/s3sync-upload
|
73
73
|
- lib/s3sync.rb
|
74
74
|
- lib/s3sync/file_diff.rb
|
75
|
+
- lib/s3sync/logger.rb
|
75
76
|
- lib/s3sync/syncer.rb
|
76
77
|
- lib/s3sync/version.rb
|
77
78
|
- s3sync.gemspec
|