backup2everbox 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/Gemfile.lock +1 -1
- data/History.rdoc +7 -0
- data/README.rdoc +49 -0
- data/Rakefile +7 -0
- data/TODO +0 -1
- data/backup2everbox.gemspec +3 -0
- data/lib/backup/connection/everbox.rb +19 -7
- data/lib/backup2everbox/version.rb +1 -1
- metadata +16 -11
- data/README +0 -41
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
data/History.rdoc
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
= 简介
|
2
|
+
|
3
|
+
备份你的数据、文件到 EverBox
|
4
|
+
|
5
|
+
= 使用方法
|
6
|
+
|
7
|
+
1. 注册一个 EverBox 帐号: http://www.everbox.com/ , 注意必须注册盛大通行证帐号,
|
8
|
+
如果需要邀请码,请到 http://www.douban.com/group/topic/17242955/
|
9
|
+
|
10
|
+
2. 运行 sudo gem install backup2everbox
|
11
|
+
|
12
|
+
3. 运行 sudo backup --setup
|
13
|
+
|
14
|
+
4. 修改 /opt/backup/config/backup.rb, 改为如下的形式
|
15
|
+
|
16
|
+
gem 'backup2everbox'
|
17
|
+
require 'backup2everbox'
|
18
|
+
|
19
|
+
backup 'mysql-backup-everbox' do
|
20
|
+
|
21
|
+
adapter :mysql do
|
22
|
+
user 'USERNAME'
|
23
|
+
password 'PASSWORD'
|
24
|
+
database 'DBNAME'
|
25
|
+
skip_tables ['django_session']
|
26
|
+
options do
|
27
|
+
host '127.0.0.1'
|
28
|
+
port '3306'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
storage :everbox do
|
33
|
+
username 'YOUR SDO USERNAME'
|
34
|
+
password 'YOUR SDO PASSWORD'
|
35
|
+
path '/backups'
|
36
|
+
end
|
37
|
+
|
38
|
+
keep_backups 10
|
39
|
+
encrypt_with_password false
|
40
|
+
notify false
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
5. 运行 sudo backup -r mysql-backup-everbox
|
45
|
+
|
46
|
+
6. backup 支持备份目录,数据库等多种源,并且支持非对称密钥加密来保护数据安全,
|
47
|
+
具体可以参考 backup 的文档: https://github.com/meskyanichi/backup
|
48
|
+
|
49
|
+
|
data/Rakefile
CHANGED
@@ -1,2 +1,9 @@
|
|
1
1
|
require 'bundler'
|
2
2
|
Bundler::GemHelper.install_tasks
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
ENV["RDOC_OPTS"] ||= "-c UTF-8"
|
5
|
+
Rake::RDocTask.new do |rd|
|
6
|
+
rd.main = "README.rdoc"
|
7
|
+
rd.rdoc_files.include("README.rdoc", "History.rdoc", "lib/**/*.rb")
|
8
|
+
rd.options << "--charset" << "UTF-8"
|
9
|
+
end
|
data/backup2everbox.gemspec
CHANGED
@@ -13,6 +13,9 @@ Gem::Specification.new do |s|
|
|
13
13
|
s.description = %q{backup to EverBox}
|
14
14
|
|
15
15
|
s.rubyforge_project = "backup2everbox"
|
16
|
+
s.rdoc_options << '--main' << 'README.rdoc' <<
|
17
|
+
'--charset' << 'UTF-8'
|
18
|
+
s.extra_rdoc_files = ['README.rdoc', 'History.rdoc']
|
16
19
|
|
17
20
|
s.add_dependency 'backup'
|
18
21
|
s.add_dependency 'activesupport'
|
@@ -3,7 +3,6 @@ require 'cgi'
|
|
3
3
|
require 'oauth'
|
4
4
|
require 'json'
|
5
5
|
require 'rest_client'
|
6
|
-
require 'pp'
|
7
6
|
|
8
7
|
|
9
8
|
module Backup
|
@@ -43,9 +42,26 @@ module Backup
|
|
43
42
|
!!@access_token
|
44
43
|
end
|
45
44
|
|
45
|
+
def path_stat(real_remote_path)
|
46
|
+
response = access_token.post(fs(:get), JSON.dump({:path => real_remote_path}), {'Content-Type' => 'text/plain'})
|
47
|
+
return :not_exist if response.code.to_i == 404
|
48
|
+
info = JSON.parse(response.body)
|
49
|
+
return :not_exist if info["type"] & 0x8000 != 0
|
50
|
+
return :file if info["type"] & 0x1 != 0
|
51
|
+
return :dir if info["type"] & 0x2 != 0
|
52
|
+
raise "unknown type: #{info["type"]}"
|
53
|
+
end
|
54
|
+
|
46
55
|
def upload(filename, remote_path, opts={})
|
47
56
|
remote_path = find_real_remote_path(remote_path)
|
48
|
-
|
57
|
+
stat = path_stat(remote_path)
|
58
|
+
if stat == :not_exist
|
59
|
+
puts "remote dir not exist, try to create it"
|
60
|
+
mkdir_p(remote_path)
|
61
|
+
elsif stat == :file
|
62
|
+
raise "remote path is a file, failed to backup"
|
63
|
+
end
|
64
|
+
|
49
65
|
basename = File.basename(filename)
|
50
66
|
target_path = File.expand_path(basename, remote_path)
|
51
67
|
keys = calc_digests(filename)
|
@@ -56,12 +72,10 @@ module Backup
|
|
56
72
|
:fileSize => File.open(filename).stat.size,
|
57
73
|
:base => ''
|
58
74
|
}
|
59
|
-
pp params
|
60
75
|
info = JSON.parse(access_token.post(fs(:prepare_put), JSON.dump(params), {'Content-Type' => 'text/plain' }).body)
|
61
|
-
pp info
|
62
76
|
File.open(filename) do |f|
|
63
77
|
info["required"].each do |x|
|
64
|
-
puts "
|
78
|
+
puts "uploading block ##{x["index"]}"
|
65
79
|
f.seek(x["index"] * @options[:chunk_size])
|
66
80
|
code, response = http_request x['url'], f.read(@options[:chunk_size]), :method => :put
|
67
81
|
if code != 200
|
@@ -73,9 +87,7 @@ module Backup
|
|
73
87
|
|
74
88
|
ftime = (Time.now.to_i * 1000 * 1000 * 10).to_s
|
75
89
|
params = params.merge :editTime => ftime, :mimeType => 'application/octet-stream'
|
76
|
-
pp access_token
|
77
90
|
code, response = access_token.post(fs(:commit_put), params.to_json, {'Content-Type' => 'text/plain'})
|
78
|
-
pp code, response
|
79
91
|
end
|
80
92
|
|
81
93
|
def delete(remote_path, opts={})
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: backup2everbox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- LI Daobing
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-02-02 00:00:00 +08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -81,13 +81,15 @@ executables: []
|
|
81
81
|
|
82
82
|
extensions: []
|
83
83
|
|
84
|
-
extra_rdoc_files:
|
85
|
-
|
84
|
+
extra_rdoc_files:
|
85
|
+
- README.rdoc
|
86
|
+
- History.rdoc
|
86
87
|
files:
|
87
88
|
- .gitignore
|
88
89
|
- Gemfile
|
89
90
|
- Gemfile.lock
|
90
|
-
-
|
91
|
+
- History.rdoc
|
92
|
+
- README.rdoc
|
91
93
|
- Rakefile
|
92
94
|
- TODO
|
93
95
|
- backup2everbox.gemspec
|
@@ -101,8 +103,11 @@ homepage: http://rubygems.org/gems/backup2everbox
|
|
101
103
|
licenses: []
|
102
104
|
|
103
105
|
post_install_message:
|
104
|
-
rdoc_options:
|
105
|
-
|
106
|
+
rdoc_options:
|
107
|
+
- --main
|
108
|
+
- README.rdoc
|
109
|
+
- --charset
|
110
|
+
- UTF-8
|
106
111
|
require_paths:
|
107
112
|
- lib
|
108
113
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -126,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
126
131
|
requirements: []
|
127
132
|
|
128
133
|
rubyforge_project: backup2everbox
|
129
|
-
rubygems_version: 1.
|
134
|
+
rubygems_version: 1.3.7
|
130
135
|
signing_key:
|
131
136
|
specification_version: 3
|
132
137
|
summary: backup to EverBox
|
data/README
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
使用方法
|
2
|
-
========
|
3
|
-
|
4
|
-
1. 注册一个 EverBox 帐号: http://www.everbox.com/ , 注意必须注册盛大通行证帐号,
|
5
|
-
如果需要邀请码,请到 http://www.douban.com/group/topic/17242955/
|
6
|
-
|
7
|
-
2. 运行 sudo gem install backup2everbox
|
8
|
-
|
9
|
-
3. 运行 sudo backup --setup
|
10
|
-
|
11
|
-
4. 修改 /opt/backup/config/backup.rb, 改为如下的形式
|
12
|
-
|
13
|
-
# ----8<----------
|
14
|
-
gem 'backup2everbox'
|
15
|
-
require 'backup2everbox'
|
16
|
-
|
17
|
-
backup 'archive-backup-everbox' do
|
18
|
-
|
19
|
-
adapter :archive do
|
20
|
-
files ["/path/to/dir/need/backup"]
|
21
|
-
end
|
22
|
-
|
23
|
-
storage :everbox do
|
24
|
-
username 'YOUR SDO USERNAME'
|
25
|
-
password 'YOUR SDO PASSWORD'
|
26
|
-
path '/backups'
|
27
|
-
end
|
28
|
-
|
29
|
-
keep_backups 10
|
30
|
-
encrypt_with_password false
|
31
|
-
notify false
|
32
|
-
|
33
|
-
end
|
34
|
-
# ----8<----------
|
35
|
-
|
36
|
-
5. 运行 sudo backup -r archive-backup-everbox
|
37
|
-
|
38
|
-
6. backup 支持备份目录,数据库等多种源,具体可以参考 backup 的文档:
|
39
|
-
https://github.com/meskyanichi/backup
|
40
|
-
|
41
|
-
|