backup2sndacs 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/.gitignore +16 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +26 -0
- data/LICENSE.txt +22 -0
- data/README.md +49 -0
- data/Rakefile +1 -0
- data/backup2sndacs.gemspec +21 -0
- data/lib/backup/config/sndacs.rb +6 -0
- data/lib/backup/storage/sndacs.rb +59 -0
- data/lib/backup2sndacs/version.rb +3 -0
- data/lib/backup2sndacs.rb +11 -0
- metadata +89 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
backup2sndacs (0.1.0)
|
5
|
+
backup (~> 3.0)
|
6
|
+
sndacs (~> 0.2.0)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
backup (3.0.25)
|
12
|
+
open4 (~> 1.3.0)
|
13
|
+
thor (~> 0.15.4)
|
14
|
+
mime-types (1.19)
|
15
|
+
open4 (1.3.0)
|
16
|
+
proxies (0.2.1)
|
17
|
+
sndacs (0.2.4)
|
18
|
+
mime-types
|
19
|
+
proxies (~> 0.2.0)
|
20
|
+
thor (0.15.4)
|
21
|
+
|
22
|
+
PLATFORMS
|
23
|
+
ruby
|
24
|
+
|
25
|
+
DEPENDENCIES
|
26
|
+
backup2sndacs!
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 LI Daobing
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Backup2sndacs
|
2
|
+
|
3
|
+
备份你的数据、文件到[盛大云存储](http://www.grandcloud.cn/product/ecs)
|
4
|
+
|
5
|
+
## 使用方法
|
6
|
+
|
7
|
+
* 运行 gem install backup2sndacs
|
8
|
+
* 运行 backup generate:config
|
9
|
+
* 运行 backup generate:model --trigger=mysql_backup_sndacs
|
10
|
+
* 访问 https://cs-console.grandcloud.cn/, 找到你的 "Access Key" 和 "Access Secret"
|
11
|
+
* 修改 ~/Backup/models/mysql_backup_sndacs.rb, 改为如下的形式
|
12
|
+
|
13
|
+
```
|
14
|
+
require 'rubygems'
|
15
|
+
gem 'backup2sndacs'
|
16
|
+
require 'backup2sndacs'
|
17
|
+
|
18
|
+
Backup::Model.new(:mysql_backup_sndacs, 'example backup to sndacs') do
|
19
|
+
split_into_chunks_of 250
|
20
|
+
|
21
|
+
database MySQL do |db|
|
22
|
+
db.name = "for_backup"
|
23
|
+
db.username = "my_username"
|
24
|
+
db.password = "my_password"
|
25
|
+
db.host = "localhost"
|
26
|
+
db.port = 3306
|
27
|
+
db.socket = "/tmp/mysql.sock"
|
28
|
+
end
|
29
|
+
|
30
|
+
store_with Sndacs do |s|
|
31
|
+
s.keep = 7
|
32
|
+
s.access_key = 'replace with access key'
|
33
|
+
s.access_secret = 'replace with access secret'
|
34
|
+
s.bucket = 'backup2sndacs-test1'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
```
|
38
|
+
|
39
|
+
* 运行 backup perform -t mysql_backup_sndacs
|
40
|
+
* backup 支持备份目录,数据库等多种源,并且支持非对称密钥加密来保护数据安全,
|
41
|
+
具体可以参考 backup 的文档: https://github.com/meskyanichi/backup
|
42
|
+
|
43
|
+
## Contributing
|
44
|
+
|
45
|
+
1. Fork it
|
46
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
47
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
48
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
49
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'backup2sndacs/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "backup2sndacs"
|
8
|
+
gem.version = Backup2sndacs::VERSION
|
9
|
+
gem.authors = ["LI Daobing"]
|
10
|
+
gem.email = ["lidaobing@gmail.com"]
|
11
|
+
gem.description = %q{backup to http://www.grandcloud.cn/product/ecs}
|
12
|
+
gem.summary = %q{backup to http://www.grandcloud.cn/product/ecs}
|
13
|
+
gem.homepage = "https://github.com/lidaobing/backup2sndacs"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
gem.add_dependency 'backup', '~> 3.0'
|
20
|
+
gem.add_dependency 'sndacs', '~> 0.2.0'
|
21
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'backup/logger'
|
2
|
+
require 'sndacs'
|
3
|
+
|
4
|
+
module Backup
|
5
|
+
module Storage
|
6
|
+
class Sndacs < Base
|
7
|
+
|
8
|
+
attr_accessor :access_key, :access_secret
|
9
|
+
attr_accessor :bucket
|
10
|
+
|
11
|
+
def initialize(model, storage_id = nil, &block)
|
12
|
+
super(model, storage_id)
|
13
|
+
|
14
|
+
@bucket ||= 'backups'
|
15
|
+
|
16
|
+
instance_eval(&block) if block_given?
|
17
|
+
end
|
18
|
+
|
19
|
+
def path
|
20
|
+
''
|
21
|
+
end
|
22
|
+
|
23
|
+
def remove!(pkg)
|
24
|
+
remote_path = remote_path_for(pkg)
|
25
|
+
transferred_files_for(pkg) do |local_file, remote_file|
|
26
|
+
Logger.message "#{storage_name} started removing " +
|
27
|
+
"'#{ local_file }' from bucket '#{ bucket }'."
|
28
|
+
key = File.join(remote_path, remote_file)
|
29
|
+
res = bucket_service.objects.find(key).destroy
|
30
|
+
unless res == true
|
31
|
+
raise "delete '#{key}' failed"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def transfer!
|
37
|
+
remote_path = remote_path_for(@package)
|
38
|
+
files_to_transfer_for(@package) do |local_file, remote_file|
|
39
|
+
Logger.message "#{storage_name} started transferring " +
|
40
|
+
"'#{ local_file }'."
|
41
|
+
key = File.join(remote_path, remote_file)
|
42
|
+
o = bucket_service.objects.build(key)
|
43
|
+
o.content = open(File.join(local_path, local_file))
|
44
|
+
res = o.save
|
45
|
+
raise "upload '#{local_file}' failed" unless res == true
|
46
|
+
Logger.message "file uploaded to bucket:#{bucket}, key:#{key}"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
def bucket_service
|
52
|
+
@bucket_service ||= begin
|
53
|
+
service = ::Sndacs::Service.new(:access_key_id => @access_key, :secret_access_key => @access_secret)
|
54
|
+
service.buckets.find(@bucket)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: backup2sndacs
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- LI Daobing
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-09-23 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: backup
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '3.0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: sndacs
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 0.2.0
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.2.0
|
46
|
+
description: backup to http://www.grandcloud.cn/product/ecs
|
47
|
+
email:
|
48
|
+
- lidaobing@gmail.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- Gemfile
|
55
|
+
- Gemfile.lock
|
56
|
+
- LICENSE.txt
|
57
|
+
- README.md
|
58
|
+
- Rakefile
|
59
|
+
- backup2sndacs.gemspec
|
60
|
+
- lib/backup/config/sndacs.rb
|
61
|
+
- lib/backup/storage/sndacs.rb
|
62
|
+
- lib/backup2sndacs.rb
|
63
|
+
- lib/backup2sndacs/version.rb
|
64
|
+
homepage: https://github.com/lidaobing/backup2sndacs
|
65
|
+
licenses: []
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
78
|
+
requirements:
|
79
|
+
- - ! '>='
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
requirements: []
|
83
|
+
rubyforge_project:
|
84
|
+
rubygems_version: 1.8.23
|
85
|
+
signing_key:
|
86
|
+
specification_version: 3
|
87
|
+
summary: backup to http://www.grandcloud.cn/product/ecs
|
88
|
+
test_files: []
|
89
|
+
has_rdoc:
|