backup2everbox 0.0.3 → 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.
- data/Gemfile.lock +16 -63
- data/History.rdoc +3 -0
- data/README.rdoc +28 -33
- data/backup2everbox.gemspec +2 -2
- data/lib/backup/config/everbox.rb +6 -0
- data/lib/backup/connection/everbox.rb +12 -14
- data/lib/backup/storage/everbox.rb +35 -3
- data/lib/backup2everbox.rb +1 -21
- data/lib/backup2everbox/cli.rb +6 -6
- data/lib/backup2everbox/version.rb +1 -1
- metadata +20 -20
- data/lib/backup/record/everbox.rb +0 -23
data/Gemfile.lock
CHANGED
@@ -1,93 +1,45 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
backup2everbox (0.0
|
4
|
+
backup2everbox (0.1.0)
|
5
5
|
activesupport
|
6
|
-
backup (~>
|
6
|
+
backup (~> 3.0)
|
7
7
|
launchy
|
8
8
|
oauth
|
9
9
|
rest-client
|
10
|
-
sqlite3
|
11
10
|
|
12
11
|
GEM
|
13
12
|
remote: http://rubygems.org/
|
14
13
|
specs:
|
15
|
-
activemodel (3.2.6)
|
16
|
-
activesupport (= 3.2.6)
|
17
|
-
builder (~> 3.0.0)
|
18
|
-
activerecord (3.2.6)
|
19
|
-
activemodel (= 3.2.6)
|
20
|
-
activesupport (= 3.2.6)
|
21
|
-
arel (~> 3.0.2)
|
22
|
-
tzinfo (~> 0.3.29)
|
23
14
|
activesupport (3.2.6)
|
24
15
|
i18n (~> 0.6)
|
25
16
|
multi_json (~> 1.0)
|
26
17
|
addressable (2.2.8)
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
pony (>= 0.5)
|
39
|
-
builder (3.0.0)
|
40
|
-
cloudfiles (1.5.0.1)
|
41
|
-
json
|
42
|
-
dropbox (1.3.0)
|
43
|
-
json (>= 1.2.0)
|
44
|
-
multipart-post (>= 1.1.0)
|
45
|
-
oauth (>= 0.3.6)
|
46
|
-
excon (0.14.1)
|
47
|
-
fog (0.3.34)
|
48
|
-
builder
|
49
|
-
excon (>= 0.3.6)
|
50
|
-
formatador (>= 0.0.16)
|
51
|
-
json
|
52
|
-
mime-types
|
53
|
-
net-ssh (>= 2.0.23)
|
54
|
-
nokogiri (>= 1.4.4)
|
55
|
-
ruby-hmac
|
56
|
-
formatador (0.2.3)
|
57
|
-
hirb (0.6.2)
|
18
|
+
backup (3.0.24)
|
19
|
+
open4 (~> 1.3.0)
|
20
|
+
thor (~> 0.14.6)
|
21
|
+
columnize (0.3.6)
|
22
|
+
debugger (1.1.4)
|
23
|
+
columnize (>= 0.3.1)
|
24
|
+
debugger-linecache (~> 1.1.1)
|
25
|
+
debugger-ruby_core_source (~> 1.1.3)
|
26
|
+
debugger-linecache (1.1.1)
|
27
|
+
debugger-ruby_core_source (>= 1.1.1)
|
28
|
+
debugger-ruby_core_source (1.1.3)
|
58
29
|
i18n (0.6.0)
|
59
30
|
json (1.6.6)
|
60
|
-
json_pure (1.4.6)
|
61
31
|
launchy (2.1.0)
|
62
32
|
addressable (~> 2.2.6)
|
63
|
-
mail (2.4.4)
|
64
|
-
i18n (>= 0.4.0)
|
65
|
-
mime-types (~> 1.16)
|
66
|
-
treetop (~> 1.4.8)
|
67
33
|
mime-types (1.19)
|
68
34
|
multi_json (1.3.6)
|
69
|
-
multipart-post (1.1.5)
|
70
|
-
net-scp (1.0.4)
|
71
|
-
net-ssh (>= 1.99.1)
|
72
|
-
net-sftp (2.0.5)
|
73
|
-
net-ssh (>= 2.0.9)
|
74
|
-
net-ssh (2.5.2)
|
75
|
-
nokogiri (1.5.4)
|
76
35
|
oauth (0.4.6)
|
77
|
-
|
78
|
-
pony (1.4)
|
79
|
-
mail (> 2.0)
|
36
|
+
open4 (1.3.0)
|
80
37
|
rake (0.8.7)
|
81
38
|
rdoc (3.12)
|
82
39
|
json (~> 1.4)
|
83
40
|
rest-client (1.6.7)
|
84
41
|
mime-types (>= 1.16)
|
85
|
-
|
86
|
-
sqlite3 (1.3.6)
|
87
|
-
treetop (1.4.10)
|
88
|
-
polyglot
|
89
|
-
polyglot (>= 0.3.1)
|
90
|
-
tzinfo (0.3.33)
|
42
|
+
thor (0.14.6)
|
91
43
|
|
92
44
|
PLATFORMS
|
93
45
|
ruby
|
@@ -95,5 +47,6 @@ PLATFORMS
|
|
95
47
|
DEPENDENCIES
|
96
48
|
backup2everbox!
|
97
49
|
bundler (>= 1.0.0)
|
50
|
+
debugger
|
98
51
|
rake (= 0.8.7)
|
99
52
|
rdoc
|
data/History.rdoc
CHANGED
data/README.rdoc
CHANGED
@@ -11,55 +11,50 @@
|
|
11
11
|
1. 注册一个 EverBox 帐号: http://www.everbox.com/ , 注意必须注册盛大通行证帐号,
|
12
12
|
如果需要邀请码,请到 http://www.douban.com/group/topic/17242955/
|
13
13
|
|
14
|
-
2. 运行
|
14
|
+
2. 运行 gem install backup2everbox
|
15
15
|
|
16
|
-
3. 运行
|
16
|
+
3. 运行 backup generate:config
|
17
17
|
|
18
|
-
4. 运行
|
18
|
+
4. 运行 backup generate:model --trigger=mysql_backup_everbox
|
19
|
+
|
20
|
+
5. 运行 backup2everbox, 得到认证码,输出如下所示
|
19
21
|
|
20
22
|
open url in your browser: http://account.everbox.com/...
|
21
23
|
please input the verification code: 123456
|
22
|
-
|
24
|
+
|
25
|
+
add following code to your ~/Backup/models/foo.rb
|
23
26
|
##################################################
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
end
|
27
|
+
store_with Everbox do |eb|
|
28
|
+
eb.token = '1234567890abcdefgh'
|
29
|
+
eb.secret = 'hgfedcba0987654321'
|
30
|
+
end
|
29
31
|
##################################################
|
30
32
|
|
33
|
+
6. 修改 ~/Backup/models/mysql_backup_everbox.rb, 改为如下的形式
|
31
34
|
|
32
|
-
|
33
|
-
|
35
|
+
require 'rubygems'
|
34
36
|
gem 'backup2everbox'
|
35
37
|
require 'backup2everbox'
|
36
38
|
|
37
|
-
|
38
|
-
|
39
|
-
adapter :mysql do
|
40
|
-
user 'USERNAME'
|
41
|
-
password 'PASSWORD'
|
42
|
-
database 'DBNAME'
|
43
|
-
skip_tables ['django_session']
|
44
|
-
options do
|
45
|
-
host '127.0.0.1'
|
46
|
-
port '3306'
|
47
|
-
end
|
48
|
-
end
|
39
|
+
Backup::Model.new(:mysql_backup_everbox, 'Description for mysql_backup_everbox') do
|
40
|
+
split_into_chunks_of 250
|
49
41
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
42
|
+
database MySQL do |db|
|
43
|
+
db.name = "giga_development"
|
44
|
+
db.username = "my_username"
|
45
|
+
db.password = "my_password"
|
46
|
+
db.host = "localhost"
|
47
|
+
db.port = 3306
|
48
|
+
db.socket = "/tmp/mysql.sock"
|
54
49
|
end
|
55
50
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
51
|
+
store_with Everbox do |eb|
|
52
|
+
eb.token = '1234567890abcdefgh'
|
53
|
+
eb.secret = 'hgfedcba0987654321'
|
54
|
+
end
|
60
55
|
end
|
61
56
|
|
62
|
-
6. 运行 sudo backup -
|
57
|
+
6. 运行 sudo backup perform -t mysql_backup_everbox
|
63
58
|
|
64
59
|
7. backup 支持备份目录,数据库等多种源,并且支持非对称密钥加密来保护数据安全,
|
65
|
-
具体可以参考 backup 的文档: https://github.com/meskyanichi/backup
|
60
|
+
具体可以参考 backup 的文档: https://github.com/meskyanichi/backup
|
data/backup2everbox.gemspec
CHANGED
@@ -17,15 +17,15 @@ Gem::Specification.new do |s|
|
|
17
17
|
'--charset' << 'UTF-8'
|
18
18
|
s.extra_rdoc_files = ['README.rdoc', 'History.rdoc']
|
19
19
|
|
20
|
-
s.add_dependency 'backup', '~>
|
20
|
+
s.add_dependency 'backup', '~> 3.0'
|
21
21
|
s.add_dependency 'activesupport'
|
22
22
|
s.add_dependency 'oauth'
|
23
23
|
s.add_dependency 'rest-client'
|
24
24
|
s.add_dependency 'launchy'
|
25
|
-
s.add_dependency 'sqlite3'
|
26
25
|
s.add_development_dependency "bundler", ">= 1.0.0"
|
27
26
|
s.add_development_dependency 'rake', "0.8.7"
|
28
27
|
s.add_development_dependency 'rdoc'
|
28
|
+
s.add_development_dependency 'debugger'
|
29
29
|
|
30
30
|
s.files = `git ls-files`.split("\n")
|
31
31
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
@@ -25,6 +25,8 @@ module Backup
|
|
25
25
|
|
26
26
|
def authorize!
|
27
27
|
@access_token = OAuth::AccessToken.from_hash(@consumer, {:oauth_token => authorizing_token, :oauth_token_secret => authorizing_secret})
|
28
|
+
raise "@access_token.token is nil" if @access_token.token.nil?
|
29
|
+
raise "@access_token.secret is nil" if @access_token.secret.nil?
|
28
30
|
puts @access_token.inspect
|
29
31
|
end
|
30
32
|
|
@@ -43,6 +45,7 @@ module Backup
|
|
43
45
|
end
|
44
46
|
|
45
47
|
def upload(filename, remote_path, opts={})
|
48
|
+
raise TypeError, "filename should be string, but #{filename.class}" unless filename.is_a?(String)
|
46
49
|
remote_path = find_real_remote_path(remote_path)
|
47
50
|
stat = path_stat(remote_path)
|
48
51
|
if stat == :not_exist
|
@@ -63,6 +66,7 @@ module Backup
|
|
63
66
|
:base => ''
|
64
67
|
}
|
65
68
|
info = JSON.parse(access_token.post(fs(:prepare_put), JSON.dump(params), {'Content-Type' => 'text/plain' }).body)
|
69
|
+
raise "prepare_put failed:\n#{info}" unless info["required"].is_a?(Array)
|
66
70
|
File.open(filename) do |f|
|
67
71
|
info["required"].each do |x|
|
68
72
|
puts "uploading block ##{x["index"]}"
|
@@ -181,17 +185,11 @@ module Backup
|
|
181
185
|
end
|
182
186
|
end
|
183
187
|
|
184
|
-
attr_accessor :
|
188
|
+
attr_accessor :token, :secret
|
185
189
|
|
186
|
-
def initialize(
|
187
|
-
|
188
|
-
|
189
|
-
self.procedure = adapter.procedure
|
190
|
-
self.final_file = adapter.final_file
|
191
|
-
self.tmp_path = adapter.tmp_path.gsub('\ ', ' ')
|
192
|
-
|
193
|
-
load_storage_configuration_attributes
|
194
|
-
end
|
190
|
+
def initialize(token, secret)
|
191
|
+
@token = token
|
192
|
+
@secret = secret
|
195
193
|
end
|
196
194
|
|
197
195
|
def static_initialize(procedure)
|
@@ -201,12 +199,12 @@ module Backup
|
|
201
199
|
|
202
200
|
def session
|
203
201
|
opts = {}
|
204
|
-
opts[:api_key] =
|
205
|
-
opts[:secret_access_key] =
|
202
|
+
opts[:api_key] = token unless token.nil?
|
203
|
+
opts[:secret_access_key] = secret unless secret.nil?
|
206
204
|
@session ||= Session.new(opts)
|
207
205
|
unless @session.authorized?
|
208
|
-
@session.authorizing_token =
|
209
|
-
@session.authorizing_secret =
|
206
|
+
@session.authorizing_token = token
|
207
|
+
@session.authorizing_secret = secret
|
210
208
|
@session.authorize!
|
211
209
|
end
|
212
210
|
|
@@ -1,12 +1,44 @@
|
|
1
1
|
require 'backup/connection/everbox'
|
2
|
+
require 'debugger'
|
2
3
|
|
3
4
|
module Backup
|
4
5
|
module Storage
|
5
6
|
class Everbox < Base
|
6
|
-
|
7
|
-
|
8
|
-
|
7
|
+
|
8
|
+
attr_accessor :token, :secret
|
9
|
+
attr_accessor :path
|
10
|
+
|
11
|
+
def initialize(model, storage_id = nil, &block)
|
12
|
+
super(model, storage_id)
|
13
|
+
|
14
|
+
@path ||= 'backups'
|
15
|
+
|
16
|
+
instance_eval(&block) if block_given?
|
9
17
|
end
|
18
|
+
|
19
|
+
def transfer!
|
20
|
+
remote_path = remote_path_for(@package)
|
21
|
+
|
22
|
+
connection = Backup::Connection::Everbox.new(token, secret)
|
23
|
+
|
24
|
+
files_to_transfer_for(@package) do |local_file, remote_file|
|
25
|
+
Logger.message "#{storage_name} started transferring " +
|
26
|
+
"'#{ local_file }'."
|
27
|
+
connection.session.upload(
|
28
|
+
File.join(local_path, local_file),
|
29
|
+
File.join(remote_path, remote_file),
|
30
|
+
:mode => :dropbox
|
31
|
+
)
|
32
|
+
|
33
|
+
|
34
|
+
#File.open(File.join(local_path, local_file), 'r') do |file|
|
35
|
+
# connection.put_object(
|
36
|
+
# bucket, File.join(remote_path, remote_file), file
|
37
|
+
# )
|
38
|
+
#end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
10
42
|
end
|
11
43
|
end
|
12
44
|
end
|
data/lib/backup2everbox.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'backup/config/everbox'
|
2
2
|
|
3
3
|
module Backup
|
4
4
|
module Connection
|
@@ -10,24 +10,4 @@ module Backup
|
|
10
10
|
module Record
|
11
11
|
autoload :Everbox, 'backup/record/everbox'
|
12
12
|
end
|
13
|
-
module Configuration
|
14
|
-
class Base
|
15
|
-
def storage_class_with_everbox
|
16
|
-
res = storage_class_without_everbox
|
17
|
-
if res.nil? and @storage_name == :everbox
|
18
|
-
res = Backup::Storage::Everbox
|
19
|
-
end
|
20
|
-
res
|
21
|
-
end
|
22
|
-
def record_class_with_everbox
|
23
|
-
res = record_class_without_everbox
|
24
|
-
if res.nil? and @storage_name == :everbox
|
25
|
-
res = Backup::Record::Everbox
|
26
|
-
end
|
27
|
-
res
|
28
|
-
end
|
29
|
-
alias_method_chain :storage_class, :everbox
|
30
|
-
alias_method_chain :record_class, :everbox
|
31
|
-
end
|
32
|
-
end
|
33
13
|
end
|
data/lib/backup2everbox/cli.rb
CHANGED
@@ -29,13 +29,13 @@ module Backup2everbox
|
|
29
29
|
STDOUT.flush
|
30
30
|
verification_code = STDIN.readline.strip
|
31
31
|
access_token = request_token.get_access_token :oauth_verifier => verification_code
|
32
|
-
puts
|
32
|
+
puts
|
33
|
+
puts "add following code to your ~/Backup/models/foo.rb"
|
33
34
|
puts "#" * 50
|
34
|
-
puts "
|
35
|
-
puts "
|
36
|
-
puts "
|
37
|
-
puts "
|
38
|
-
puts "end"
|
35
|
+
puts " store_with Everbox do |eb|"
|
36
|
+
puts " eb.token = '#{access_token.token}'"
|
37
|
+
puts " eb.secret = '#{access_token.secret}'"
|
38
|
+
puts " end"
|
39
39
|
puts "#" * 50
|
40
40
|
end
|
41
41
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: backup2everbox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-06-
|
12
|
+
date: 2012-06-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: backup
|
@@ -18,7 +18,7 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: '
|
21
|
+
version: '3.0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: '
|
29
|
+
version: '3.0'
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: activesupport
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -92,55 +92,55 @@ dependencies:
|
|
92
92
|
- !ruby/object:Gem::Version
|
93
93
|
version: '0'
|
94
94
|
- !ruby/object:Gem::Dependency
|
95
|
-
name:
|
95
|
+
name: bundler
|
96
96
|
requirement: !ruby/object:Gem::Requirement
|
97
97
|
none: false
|
98
98
|
requirements:
|
99
99
|
- - ! '>='
|
100
100
|
- !ruby/object:Gem::Version
|
101
|
-
version:
|
102
|
-
type: :
|
101
|
+
version: 1.0.0
|
102
|
+
type: :development
|
103
103
|
prerelease: false
|
104
104
|
version_requirements: !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
106
106
|
requirements:
|
107
107
|
- - ! '>='
|
108
108
|
- !ruby/object:Gem::Version
|
109
|
-
version:
|
109
|
+
version: 1.0.0
|
110
110
|
- !ruby/object:Gem::Dependency
|
111
|
-
name:
|
111
|
+
name: rake
|
112
112
|
requirement: !ruby/object:Gem::Requirement
|
113
113
|
none: false
|
114
114
|
requirements:
|
115
|
-
- -
|
115
|
+
- - '='
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version:
|
117
|
+
version: 0.8.7
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
none: false
|
122
122
|
requirements:
|
123
|
-
- -
|
123
|
+
- - '='
|
124
124
|
- !ruby/object:Gem::Version
|
125
|
-
version:
|
125
|
+
version: 0.8.7
|
126
126
|
- !ruby/object:Gem::Dependency
|
127
|
-
name:
|
127
|
+
name: rdoc
|
128
128
|
requirement: !ruby/object:Gem::Requirement
|
129
129
|
none: false
|
130
130
|
requirements:
|
131
|
-
- - '
|
131
|
+
- - ! '>='
|
132
132
|
- !ruby/object:Gem::Version
|
133
|
-
version: 0
|
133
|
+
version: '0'
|
134
134
|
type: :development
|
135
135
|
prerelease: false
|
136
136
|
version_requirements: !ruby/object:Gem::Requirement
|
137
137
|
none: false
|
138
138
|
requirements:
|
139
|
-
- - '
|
139
|
+
- - ! '>='
|
140
140
|
- !ruby/object:Gem::Version
|
141
|
-
version: 0
|
141
|
+
version: '0'
|
142
142
|
- !ruby/object:Gem::Dependency
|
143
|
-
name:
|
143
|
+
name: debugger
|
144
144
|
requirement: !ruby/object:Gem::Requirement
|
145
145
|
none: false
|
146
146
|
requirements:
|
@@ -175,8 +175,8 @@ files:
|
|
175
175
|
- TODO
|
176
176
|
- backup2everbox.gemspec
|
177
177
|
- bin/backup2everbox
|
178
|
+
- lib/backup/config/everbox.rb
|
178
179
|
- lib/backup/connection/everbox.rb
|
179
|
-
- lib/backup/record/everbox.rb
|
180
180
|
- lib/backup/storage/everbox.rb
|
181
181
|
- lib/backup2everbox.rb
|
182
182
|
- lib/backup2everbox/cli.rb
|
@@ -1,23 +0,0 @@
|
|
1
|
-
require 'backup/connection/everbox'
|
2
|
-
|
3
|
-
module Backup
|
4
|
-
module Record
|
5
|
-
class Everbox < Backup::Record::Base
|
6
|
-
def load_specific_settings(adapter)
|
7
|
-
end
|
8
|
-
|
9
|
-
private
|
10
|
-
|
11
|
-
def self.destroy_backups(procedure, backups)
|
12
|
-
everbox = Backup::Connection::Everbox.new
|
13
|
-
everbox.static_initialize(procedure)
|
14
|
-
session = everbox.session
|
15
|
-
backups.each do |backup|
|
16
|
-
puts "\nDestroying backup \"#{backup.filename}\"."
|
17
|
-
path_to_file = File.join(everbox.path, backup.filename)
|
18
|
-
session.delete(path_to_file, :mode => :everbox)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|