s3rbsync 0.1.2 → 0.7.0
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/Gemfile +0 -3
- data/README.md +35 -3
- data/lib/s3rbsync/command.rb +15 -1
- data/lib/s3rbsync/configure.rb +7 -2
- data/lib/s3rbsync/synchronizer.rb +63 -11
- data/lib/s3rbsync/version.rb +5 -1
- data/s3rbsync.gemspec +3 -0
- metadata +30 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7dd4776953600f8c4d6bd227c213fc646dcb91ee
|
4
|
+
data.tar.gz: 067041d781ef4d1aad512ad6d3d713876a1d3116
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1f388e3d84625e92b6f3c40a704f78206cfcb1879cfa23c818178131eeba4967df85d111ee92f18a963c02d324078b9f442b867930f0b9dcda451053ff15db9
|
7
|
+
data.tar.gz: 5180f73c77c9c4e56097ecd4d9e07f92828377c9cf5d7cdf699ff0c59f6a942d4e1ce5418cbfd9f8f9dfe40f819bde1c14df42842592ebe9dcc01059f5496f74
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
-
#
|
1
|
+
# s3rbsync
|
2
2
|
|
3
|
-
|
3
|
+
このライブラリを使うことで、特定のディレクトリをS3に同期させることができます。
|
4
|
+
This library save to S3 in the AWS file in the directory specific.
|
4
5
|
|
5
6
|
## Installation
|
6
7
|
|
@@ -18,7 +19,38 @@ Or install it yourself as:
|
|
18
19
|
|
19
20
|
## Usage
|
20
21
|
|
21
|
-
|
22
|
+
### Overview
|
23
|
+
|
24
|
+
```bash
|
25
|
+
$ s3rbsync
|
26
|
+
Commands:
|
27
|
+
s3rbsync help [COMMAND] # Describe available commands or one specific command
|
28
|
+
s3rbsync init # Set up S3rbsync. (ganerate configure)
|
29
|
+
s3rbsync sync # Synchronize files to S3.
|
30
|
+
s3rbsync test # The connection test to AWS.
|
31
|
+
```
|
32
|
+
|
33
|
+
### First step
|
34
|
+
|
35
|
+
```bash
|
36
|
+
$ s3rbsync init
|
37
|
+
```
|
38
|
+
|
39
|
+
### Connection Test
|
40
|
+
|
41
|
+
```bash
|
42
|
+
$ s3rbsync test
|
43
|
+
```
|
44
|
+
|
45
|
+
### Sync
|
46
|
+
|
47
|
+
```bash
|
48
|
+
ex.)
|
49
|
+
$ s3rbsync sync -d /var/backups
|
50
|
+
|
51
|
+
# Options:
|
52
|
+
# -d, [--directory=DIRECTORY] # Default: ./ (current directory)
|
53
|
+
```
|
22
54
|
|
23
55
|
## Contributing
|
24
56
|
|
data/lib/s3rbsync/command.rb
CHANGED
@@ -24,6 +24,20 @@ module S3rbsync
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
+
desc 'sync', "Synchronize files to S3."
|
28
|
+
method_option :directory, :type => :string, :aliases => "-d", :default => "./"
|
29
|
+
def sync
|
30
|
+
conf = S3rbsync::Configure.new
|
31
|
+
unless conf.valid?
|
32
|
+
say "Sync failed!: configure is invalid.", :red
|
33
|
+
exit 1
|
34
|
+
end
|
35
|
+
synchronizer = S3rbsync::Synchronizer.new(conf, options[:directory])
|
36
|
+
say "Sync start...", :cyan
|
37
|
+
synchronizer.sync!
|
38
|
+
say "...finish.", :cyan
|
39
|
+
end
|
40
|
+
|
27
41
|
desc 'test', "The connection test to AWS."
|
28
42
|
def test
|
29
43
|
say "\nChecking config...\n", :cyan
|
@@ -40,7 +54,7 @@ module S3rbsync
|
|
40
54
|
print "Test connection: "
|
41
55
|
if conf.connected?
|
42
56
|
say "OK", :green
|
43
|
-
|
57
|
+
#]...
|
44
58
|
else
|
45
59
|
say "NG", :red
|
46
60
|
say " -> Connection falid: Chack config file, or 's3rbsync init'", :yellow
|
data/lib/s3rbsync/configure.rb
CHANGED
@@ -3,10 +3,10 @@ require 'yaml'
|
|
3
3
|
module S3rbsync
|
4
4
|
class Configure
|
5
5
|
CONF_FILE = "#{ENV["HOME"]}/.aws.yml"
|
6
|
-
attr_accessor :access_key, :secret_key, :bucket_name
|
6
|
+
attr_accessor :access_key, :secret_key, :bucket_name, :region
|
7
7
|
|
8
8
|
def initialize
|
9
|
-
@access_key = @secret_key = @bucket_name = @error_message = nil
|
9
|
+
@access_key = @secret_key = @bucket_name = @error_message = @region = nil
|
10
10
|
begin
|
11
11
|
@conf = YAML.load_file CONF_FILE
|
12
12
|
rescue => e
|
@@ -15,9 +15,14 @@ module S3rbsync
|
|
15
15
|
@access_key = @conf[:aws_access_key]
|
16
16
|
@secret_key = @conf[:aws_secret_access_key]
|
17
17
|
@bucket_name = @conf[:bucket_name]
|
18
|
+
@region = @conf[:region]
|
18
19
|
end
|
19
20
|
end
|
20
21
|
|
22
|
+
def valid?
|
23
|
+
valid_yaml_file? and connected?
|
24
|
+
end
|
25
|
+
|
21
26
|
def valid_yaml_file?
|
22
27
|
@error_message.nil? and @access_key and @secret_key and @bucket_name
|
23
28
|
end
|
@@ -3,21 +3,73 @@ require 'fog'
|
|
3
3
|
module S3rbsync
|
4
4
|
class Synchronizer
|
5
5
|
|
6
|
-
def initialize(configure)
|
6
|
+
def initialize(configure, directory = nil)
|
7
7
|
@configure = configure
|
8
|
-
@
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
@local_dir = directory
|
9
|
+
@s3 = Fog::Storage.new(:provider => 'AWS',
|
10
|
+
:aws_access_key_id => @configure.access_key,
|
11
|
+
:aws_secret_access_key => @configure.secret_key,
|
12
|
+
:region => (@configure.region || 'ap-northeast-1'),
|
13
|
+
:persistent => false )
|
14
|
+
@bucket = @s3.directories.get(@configure.bucket_name)
|
15
|
+
@queue = Queue.new
|
16
|
+
rescue => e
|
17
|
+
puts "----- Error -----"
|
18
|
+
puts e.message
|
19
|
+
exit 1
|
13
20
|
end
|
14
21
|
|
15
22
|
def connected?
|
16
|
-
|
17
|
-
rescue
|
18
|
-
false
|
19
|
-
else
|
20
|
-
true
|
23
|
+
!!@bucket
|
21
24
|
end
|
25
|
+
|
26
|
+
def sync!
|
27
|
+
# puts '...call sync!'
|
28
|
+
upload_files(@local_dir)
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def upload_files(dir)
|
35
|
+
upload_in_directory(dir)
|
36
|
+
recursive_upload
|
37
|
+
end
|
38
|
+
|
39
|
+
def recursive_upload
|
40
|
+
upload_in_directory(@queue.pop, :recursible => true) until @queue.empty?
|
41
|
+
end
|
42
|
+
|
43
|
+
def upload_in_directory(dir, options={})
|
44
|
+
Dir.entries(dir).each do |file|
|
45
|
+
next if file.start_with?('.')
|
46
|
+
|
47
|
+
file_name = options[:recursible] ? File.join(dir, file) : file
|
48
|
+
if File.directory?(file_name)
|
49
|
+
@queue.push(file_name)
|
50
|
+
else
|
51
|
+
upload!(file_name)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def upload!(file_name)
|
57
|
+
remote_file = get_remote_file(file_name)
|
58
|
+
return if remote_file && (not modified?(file_name, remote_file))
|
59
|
+
remote_file.destroy if remote_file && modified?(file_name, remote_file)
|
60
|
+
@bucket.files.create(:key => "#{file_name}", :body => open(file_name), :public => false)
|
61
|
+
puts "copied #{file_name}"
|
62
|
+
end
|
63
|
+
|
64
|
+
def get_remote_file(file_name)
|
65
|
+
@bucket.files.get(file_name)
|
66
|
+
end
|
67
|
+
|
68
|
+
def modified?(local_file, remote_file)
|
69
|
+
# puts "verifying file: #{local_file}"
|
70
|
+
return true unless remote_file
|
71
|
+
File.mtime(local_file) > remote_file.last_modified
|
72
|
+
end
|
73
|
+
|
22
74
|
end
|
23
75
|
end
|
data/lib/s3rbsync/version.rb
CHANGED
data/s3rbsync.gemspec
CHANGED
@@ -18,6 +18,9 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
+
spec.add_runtime_dependency "thor", "~> 0.18"
|
22
|
+
spec.add_runtime_dependency "fog", "~> 1.15"
|
23
|
+
|
21
24
|
spec.add_development_dependency "bundler", "~> 1.3"
|
22
25
|
spec.add_development_dependency "rake"
|
23
26
|
end
|
metadata
CHANGED
@@ -1,15 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: s3rbsync
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Naohiro Sakuma
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-09-
|
11
|
+
date: 2013-09-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: thor
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.18'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.18'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: fog
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.15'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.15'
|
13
41
|
- !ruby/object:Gem::Dependency
|
14
42
|
name: bundler
|
15
43
|
requirement: !ruby/object:Gem::Requirement
|