backup-aliyun 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 21cb25fe79fecd93f044681aa1bb2f368af90533
4
+ data.tar.gz: e82895729d58116f9de591b6f2f3920606e5eac6
5
+ SHA512:
6
+ metadata.gz: 58aa73262b0e85554041ab3d042c5aa81c1d097a068accc18c90da732e6be90cd163e5887478c14c8f7bd1118dac51eea785f91f240bc638228081fdc52779bf
7
+ data.tar.gz: ea984d49640e4a331811d3b56742a3fb823dac76ec68fc9c128b3c2a9e308e26bebf3d5780b022831a423c7a565f6680ff4a711b07785508d50b100e7074111b
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ doc/
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ bundler_args: --without development
3
+
4
+ rvm:
5
+ - 1.9.3
6
+ - 2.0.0
7
+
8
+ script: bundle exec rspec spec
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+ gem 'rspec'
5
+ gem 'mocha'
data/Gemfile.lock ADDED
@@ -0,0 +1,115 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ backup-aliyun (0.1.0)
5
+ backup (>= 3.7.0)
6
+ carrierwave-aliyun (>= 0.1.3)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activesupport (3.2.14)
12
+ i18n (~> 0.6, >= 0.6.4)
13
+ multi_json (~> 1.0)
14
+ backup (3.7.1)
15
+ builder (= 3.2.2)
16
+ dropbox-sdk (= 1.5.1)
17
+ excon (= 0.25.3)
18
+ faraday (= 0.8.7)
19
+ fog (= 1.13.0)
20
+ formatador (= 0.2.4)
21
+ hipchat (= 0.11.0)
22
+ httparty (= 0.11.0)
23
+ json (= 1.8.0)
24
+ mail (= 2.5.4)
25
+ mime-types (= 1.23)
26
+ multi_json (= 1.7.7)
27
+ multi_xml (= 0.5.4)
28
+ multipart-post (= 1.2.0)
29
+ net-scp (= 1.1.2)
30
+ net-sftp (= 2.1.2)
31
+ net-ssh (= 2.6.8)
32
+ nokogiri (= 1.5.10)
33
+ open4 (= 1.3.0)
34
+ polyglot (= 0.3.3)
35
+ ruby-hmac (= 0.4.0)
36
+ simple_oauth (= 0.2.0)
37
+ thor (= 0.18.1)
38
+ treetop (= 1.4.14)
39
+ twitter (= 4.8.1)
40
+ builder (3.2.2)
41
+ carrierwave (0.5.8)
42
+ activesupport (~> 3.0)
43
+ carrierwave-aliyun (0.2.0)
44
+ carrierwave (>= 0.5.7)
45
+ rest-client (>= 1.6.7)
46
+ diff-lcs (1.2.4)
47
+ dropbox-sdk (1.5.1)
48
+ json
49
+ excon (0.25.3)
50
+ faraday (0.8.7)
51
+ multipart-post (~> 1.1)
52
+ fog (1.13.0)
53
+ builder
54
+ excon (~> 0.25.0)
55
+ formatador (~> 0.2.0)
56
+ mime-types
57
+ multi_json (~> 1.0)
58
+ net-scp (~> 1.1)
59
+ net-ssh (>= 2.1.3)
60
+ nokogiri (~> 1.5.0)
61
+ ruby-hmac
62
+ formatador (0.2.4)
63
+ hipchat (0.11.0)
64
+ httparty
65
+ httparty (0.11.0)
66
+ multi_json (~> 1.0)
67
+ multi_xml (>= 0.5.2)
68
+ i18n (0.6.5)
69
+ json (1.8.0)
70
+ mail (2.5.4)
71
+ mime-types (~> 1.16)
72
+ treetop (~> 1.4.8)
73
+ metaclass (0.0.1)
74
+ mime-types (1.23)
75
+ mocha (0.14.0)
76
+ metaclass (~> 0.0.1)
77
+ multi_json (1.7.7)
78
+ multi_xml (0.5.4)
79
+ multipart-post (1.2.0)
80
+ net-scp (1.1.2)
81
+ net-ssh (>= 2.6.5)
82
+ net-sftp (2.1.2)
83
+ net-ssh (>= 2.6.5)
84
+ net-ssh (2.6.8)
85
+ nokogiri (1.5.10)
86
+ open4 (1.3.0)
87
+ polyglot (0.3.3)
88
+ rest-client (1.6.7)
89
+ mime-types (>= 1.16)
90
+ rspec (2.14.1)
91
+ rspec-core (~> 2.14.0)
92
+ rspec-expectations (~> 2.14.0)
93
+ rspec-mocks (~> 2.14.0)
94
+ rspec-core (2.14.5)
95
+ rspec-expectations (2.14.2)
96
+ diff-lcs (>= 1.1.3, < 2.0)
97
+ rspec-mocks (2.14.3)
98
+ ruby-hmac (0.4.0)
99
+ simple_oauth (0.2.0)
100
+ thor (0.18.1)
101
+ treetop (1.4.14)
102
+ polyglot
103
+ polyglot (>= 0.3.1)
104
+ twitter (4.8.1)
105
+ faraday (~> 0.8, < 0.10)
106
+ multi_json (~> 1.0)
107
+ simple_oauth (~> 0.2)
108
+
109
+ PLATFORMS
110
+ ruby
111
+
112
+ DEPENDENCIES
113
+ backup-aliyun!
114
+ mocha
115
+ rspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2013 Jason Lee
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,34 @@
1
+ ## Backup to Aliyun OSS
2
+
3
+ 此 Gem 是 [Backup](https://github.com/meskyanichi/backup) 的辅助插件,目的是让 Backup 支持存储到 [Aliyun OSS](http://oss.aliyun.com)。
4
+
5
+ ## 安装
6
+
7
+ ```bash
8
+ $ gem install backup-aliyun
9
+ ```
10
+ ## 配置
11
+
12
+ 你需要在你的 Backup models 文件里面单独引用 `backup-aliyun`,比如:
13
+
14
+ ~/Backup/models/foo.rb
15
+
16
+ ```ruby
17
+ require "backup-aliyun" # 引用 backup-aliyun
18
+
19
+ Backup::Model.new(:foo, 'Description for foo') do
20
+
21
+ # 配置阿里云 OSS 作为备份存储方式
22
+ store_with Aliyun do |aliyun|
23
+ aliyun.access_key_id = 'my_access_id'
24
+ aliyun.access_key_secret = 'my_access_key'
25
+ aliyun.bucket = 'bucket-name'
26
+ aliyun.path = '/path/to/my/backups'
27
+ aliyun.keep = 10
28
+ end
29
+ end
30
+ ```
31
+
32
+ 然后你就可以用 Backup 把你的备份文件存储到 Aliyun OSS 上面了。
33
+
34
+ 至于 Backup 的使用方法请参见 [Backup](https://github.com/meskyanichi/backup) 的文档。
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "backup-aliyun"
6
+ s.version = "0.1.0"
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = ["Jason Lee"]
9
+ s.email = ["huacnlee@gmail.com"]
10
+ s.homepage = "https://github.com/huacnlee/backup-aliyun"
11
+ s.summary = %q{Aliyun OSS Storage support for Backup}
12
+ s.description = %q{Aliyun OSS Storage support for Backup}
13
+ s.files = `git ls-files`.split("\n")
14
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
16
+ s.require_paths = ["lib"]
17
+ s.license = 'MIT'
18
+
19
+ s.add_dependency "backup", ">= 3.7.0"
20
+ s.add_dependency "carrierwave-aliyun", ["~> 0.2.0"]
21
+ end
@@ -0,0 +1,3 @@
1
+ require "backup"
2
+
3
+ Backup::Storage.send(:autoload, :Aliyun, File.join(File.dirname(__FILE__),"backup/storage/aliyun"))
Binary file
@@ -0,0 +1,50 @@
1
+ require "carrierwave-aliyun"
2
+ require "base64"
3
+
4
+ module Backup
5
+ module Storage
6
+ class Aliyun < Base
7
+ attr_accessor :bucket,:access_key_id,:access_key_secret,:aliyun_internal, :path
8
+
9
+ def initialize(model, storage_id = nil, &block)
10
+ super(model, storage_id)
11
+
12
+ @path ||= 'backups'
13
+
14
+ instance_eval(&block) if block_given?
15
+ end
16
+
17
+ private
18
+
19
+ def connection
20
+ return @connection if @connection
21
+ opts = {
22
+ :aliyun_access_id => self.access_key_id,
23
+ :aliyun_access_key => self.access_key_secret,
24
+ :aliyun_bucket => self.bucket,
25
+ :aliyun_internal => self.aliyun_internal || false
26
+ }
27
+ @connection = CarrierWave::Storage::Aliyun::Connection.new(opts)
28
+ end
29
+
30
+ def transfer!
31
+ remote_path = remote_path_for(@package)
32
+
33
+ @package.filenames.each do |filename|
34
+ src = File.join(Config.tmp_path, filename)
35
+ dest = File.join(remote_path, filename)
36
+ Logger.info "#{storage_name} uploading '#{ dest }'..."
37
+ File.open(src, 'r') do |file|
38
+ connection.put(dest, file.read)
39
+ end
40
+ end
41
+ end
42
+
43
+ def remove!(package)
44
+ remote_path = remote_path_for(package)
45
+ Logger.info "#{storage_name} removing '#{remote_path}'..."
46
+ connection.delete(remote_path)
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,172 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path('../spec_helper.rb', __FILE__)
4
+
5
+ describe Backup::Storage::Aliyun do
6
+ let(:model) { Backup::Model.new(:test_trigger, 'test label') }
7
+ let(:storage) do
8
+ Backup::Storage::Aliyun.new(model) do |db|
9
+ db.access_key_id = 'my_access_id'
10
+ db.access_key_secret = 'my_access_key'
11
+ db.bucket = 'foo'
12
+ db.keep = 5
13
+ end
14
+ end
15
+
16
+ it 'should be a subclass of Storage::Base' do
17
+ Backup::Storage::Aliyun.
18
+ superclass.should == Backup::Storage::Base
19
+ end
20
+
21
+ describe '#initialize' do
22
+ after { Backup::Storage::Aliyun.clear_defaults! }
23
+
24
+ it 'should load pre-configured defaults through Base' do
25
+ Backup::Storage::Aliyun.any_instance.expects(:load_defaults!)
26
+ storage
27
+ end
28
+
29
+ it 'should pass the model reference to Base' do
30
+ storage.instance_variable_get(:@model).should == model
31
+ end
32
+
33
+ it 'should pass the storage_id to Base' do
34
+ storage = Backup::Storage::Aliyun.new(model, 'my_storage_id')
35
+ storage.storage_id.should == 'my_storage_id'
36
+ end
37
+
38
+ context 'when no pre-configured defaults have been set' do
39
+ it 'should use the values given' do
40
+ storage.access_key_id.should == 'my_access_id'
41
+ storage.access_key_secret.should == 'my_access_key'
42
+ storage.bucket.should == "foo"
43
+ storage.path.should == 'backups'
44
+
45
+ storage.storage_id.should be_nil
46
+ storage.keep.should == 5
47
+ end
48
+
49
+ it 'should use default values if none are given' do
50
+ storage = Backup::Storage::Aliyun.new(model)
51
+ storage.access_key_id.should be_nil
52
+ storage.access_key_secret.should be_nil
53
+ storage.bucket.should be_nil
54
+ storage.path.should == 'backups'
55
+
56
+ storage.storage_id.should be_nil
57
+ storage.keep.should be_nil
58
+ end
59
+ end # context 'when no pre-configured defaults have been set'
60
+
61
+ context 'when pre-configured defaults have been set' do
62
+ before do
63
+ Backup::Storage::Aliyun.defaults do |s|
64
+ s.access_key_id = 'some_api_key'
65
+ s.access_key_secret = 'some_api_secret'
66
+ s.bucket = 'some_bucket'
67
+ s.path = 'some_path'
68
+ s.keep = 15
69
+ end
70
+ end
71
+
72
+ it 'should use pre-configured defaults' do
73
+ storage = Backup::Storage::Aliyun.new(model)
74
+
75
+ storage.access_key_id.should == 'some_api_key'
76
+ storage.access_key_secret.should == 'some_api_secret'
77
+ storage.bucket.should == 'some_bucket'
78
+ storage.path.should == 'some_path'
79
+
80
+ storage.storage_id.should be_nil
81
+ storage.keep.should == 15
82
+ end
83
+
84
+ it 'should override pre-configured defaults' do
85
+ storage = Backup::Storage::Aliyun.new(model) do |s|
86
+ s.access_key_id = 'new_api_key'
87
+ s.access_key_secret = 'new_api_secret'
88
+ s.bucket = 'new_bucket'
89
+ s.path = 'new_path'
90
+ s.keep = 10
91
+ end
92
+
93
+ storage.access_key_id.should == 'new_api_key'
94
+ storage.access_key_secret.should == 'new_api_secret'
95
+ storage.bucket.should == 'new_bucket'
96
+ storage.path.should == 'new_path'
97
+
98
+ storage.storage_id.should be_nil
99
+ storage.keep.should == 10
100
+ end
101
+ end # context 'when pre-configured defaults have been set'
102
+ end # describe '#initialize'
103
+
104
+ describe '#transfer!' do
105
+ let(:connection) { mock }
106
+ let(:package) { mock }
107
+ let(:file) { mock }
108
+ let(:s) { sequence '' }
109
+
110
+ before do
111
+ storage.instance_variable_set(:@package, package)
112
+ storage.stubs(:storage_name).returns('Storage::Aliyun')
113
+ Backup::Config.stubs(:tmp_path).returns('/local/path')
114
+ storage.stubs(:connection).returns(connection)
115
+ file.stubs(:read).returns("foo")
116
+ end
117
+
118
+ it 'should transfer the package files' do
119
+
120
+ storage.expects(:remote_path_for).in_sequence(s).with(package).
121
+ returns('remote/path')
122
+ package.stubs(:filenames).returns(["backup.tar.enc-aa","backup.tar.enc-ab"])
123
+ # first yield
124
+ Backup::Logger.expects(:info).in_sequence(s).with(
125
+ "Storage::Aliyun uploading 'remote/path/backup.tar.enc-aa'..."
126
+ )
127
+ File.expects(:open).in_sequence(s).with(
128
+ File.join('/local/path', 'backup.tar.enc-aa'), 'r'
129
+ ).yields(file)
130
+ connection.expects(:put).in_sequence(s).with(
131
+ File.join('remote/path', 'backup.tar.enc-aa'), file.read
132
+ )
133
+ # second yield
134
+ Backup::Logger.expects(:info).in_sequence(s).with(
135
+ "Storage::Aliyun uploading 'remote/path/backup.tar.enc-ab'..."
136
+ )
137
+ File.expects(:open).in_sequence(s).with(
138
+ File.join('/local/path', 'backup.tar.enc-ab'), 'r'
139
+ ).yields(file)
140
+ connection.expects(:put).in_sequence(s).with(
141
+ File.join('remote/path', 'backup.tar.enc-ab'), file.read
142
+ )
143
+
144
+ storage.send(:transfer!)
145
+ end
146
+ end # describe '#transfer!'
147
+
148
+ describe '#remove!' do
149
+ let(:package) { mock }
150
+ let(:connection) { mock }
151
+ let(:s) { sequence '' }
152
+
153
+ before do
154
+ storage.stubs(:storage_name).returns('Storage::Aliyun')
155
+ storage.stubs(:connection).returns(connection)
156
+ end
157
+
158
+ it 'should remove the package files' do
159
+ storage.expects(:remote_path_for).in_sequence(s).with(package).
160
+ returns('remote/path')
161
+ # after both yields
162
+ Backup::Logger.expects(:info).in_sequence(s).with(
163
+ "Storage::Aliyun removing 'remote/path'..."
164
+ )
165
+ connection.expects(:delete).in_sequence(s).with('remote/path')
166
+
167
+ storage.send(:remove!, package)
168
+ end
169
+ end # describe '#remove!'
170
+
171
+
172
+ end
@@ -0,0 +1,37 @@
1
+ require 'rubygems' if RUBY_VERSION < '1.9'
2
+ require 'bundler/setup'
3
+ require 'backup'
4
+ require 'backup-aliyun'
5
+
6
+
7
+ require 'rspec/autorun'
8
+ RSpec.configure do |config|
9
+ ##
10
+ # Use Mocha to mock with RSpec
11
+ config.mock_with :mocha
12
+
13
+ ##
14
+ # Example Helpers
15
+ # config.include Backup::ExampleHelpers
16
+
17
+ config.filter_run :focus => true
18
+ config.run_all_when_everything_filtered = true
19
+ config.treat_symbols_as_metadata_keys_with_true_values = true
20
+
21
+
22
+ config.before(:each) do
23
+ # ::FileUtils will always be either SandboxFileUtils or FileUtils::NoWrite.
24
+ # SandboxFileUtils.deactivate!(:noop)
25
+
26
+ # prevent system calls
27
+ Backup::Utilities.stubs(:gnu_tar?).returns(true)
28
+ Backup::Utilities.stubs(:utility)
29
+ Backup::Utilities.stubs(:run)
30
+ Backup::Pipeline.any_instance.stubs(:run)
31
+
32
+ Backup::Utilities.send(:reset!)
33
+ Backup::Config.send(:reset!)
34
+ # Logger only queues messages received until Logger.start! is called.
35
+ Backup::Logger.send(:reset!)
36
+ end
37
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: backup-aliyun
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jason Lee
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: backup
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 3.7.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 3.7.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: carrierwave-aliyun
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 0.2.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 0.2.0
41
+ description: Aliyun OSS Storage support for Backup
42
+ email:
43
+ - huacnlee@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - .travis.yml
50
+ - Gemfile
51
+ - Gemfile.lock
52
+ - LICENSE
53
+ - README.md
54
+ - backup-aliyun.gemspec
55
+ - lib/backup-aliyun.rb
56
+ - lib/backup/.DS_Store
57
+ - lib/backup/storage/aliyun.rb
58
+ - spec/aliyun_spec.rb
59
+ - spec/spec_helper.rb
60
+ homepage: https://github.com/huacnlee/backup-aliyun
61
+ licenses:
62
+ - MIT
63
+ metadata: {}
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubyforge_project:
80
+ rubygems_version: 2.0.3
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: Aliyun OSS Storage support for Backup
84
+ test_files:
85
+ - spec/aliyun_spec.rb
86
+ - spec/spec_helper.rb
87
+ has_rdoc: