backup2qiniu 3.3.0 → 3.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 78535d0fd1b840a57fae29ce6f887fc0393be28b
4
- data.tar.gz: 0d479afc844dc61ba78e76d090f6af36e68ca966
3
+ metadata.gz: ac679001bd13064b0df2a18d3dfdea85b7ea2419
4
+ data.tar.gz: 1342954ffd07006565487872622c4f9514ed33fb
5
5
  SHA512:
6
- metadata.gz: efd3b0680c7c6fa1978ee95f4304010b29e443e55d6e5b78561a8474f933d3eb98bd64855964e715c9f466bc064326e58a199fcc1236581e864cdec5821fc728
7
- data.tar.gz: 4c3e336de94427c9c345f920c10a43914c89673814506e23806e32022d642fb17a433cbf531d5b0c513b1dbc85b00ce6aa2932c27fd4c086a2d70c5d55058cce
6
+ metadata.gz: 912c8d0d5e08fc175fb68fbe7f87a13a2d5b862a1c82d5a2a936c4cb1a278f9d0babdef977840325de48fdda93af1d71b3539ec4b2a37fa18abbfc906f816752
7
+ data.tar.gz: 036a0cc08a2dda489a18f64714da0c18ef35d1f330cf16076cbbea98a36baea163275419684c165298b6304e2d1b666eb594b0188178a587883eb281bd312974
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- backup2qiniu (3.3.0)
4
+ backup2qiniu (3.3.1)
5
5
  backup (~> 3.3.0)
6
6
  qiniu-rs (~> 3.1)
7
7
 
@@ -12,7 +12,7 @@ GEM
12
12
  open4 (~> 1.3.0)
13
13
  thor (>= 0.15.4, < 2)
14
14
  json (1.7.7)
15
- mime-types (1.22)
15
+ mime-types (1.23)
16
16
  open4 (1.3.0)
17
17
  qiniu-rs (3.4.2)
18
18
  json (~> 1.7)
data/NEWS.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # NEWS
2
2
 
3
+ ## 3.3.1 (2013-04-28)
4
+
5
+ * support backup with upload_token
6
+
3
7
  ## 3.3.0 (2013-04-19)
4
8
 
5
9
  * works for backup 3.3.X
data/README.md CHANGED
@@ -7,31 +7,56 @@
7
7
  * 运行 gem install backup2qiniu
8
8
  * 运行 backup generate:config
9
9
  * 运行 backup generate:model --trigger=mysql_backup_qiniu
10
- * 访问 https://dev.qiniutek.com/account/keys, 找到你的 "Access Key" 和 "Access Secret"
10
+ * 获取上传秘钥
11
+ * 运行 backup2qiniu gen_token
12
+ * 如果不担心黑客入侵后通过你的备份配置删除你的备份,那么可以直接访问 https://dev.qiniutek.com/account/keys, 找到你的 "Access Key" 和 "Access Secret"
11
13
  * 修改 ~/Backup/models/mysql_backup_qiniu.rb, 改为如下的形式
12
14
 
13
- ```
15
+ ```ruby
14
16
  require 'rubygems'
15
17
  gem 'backup2qiniu'
16
18
  require 'backup2qiniu'
17
19
 
18
20
  Backup::Model.new(:mysql_backup_qiniu, 'example backup to qiniu') do
19
- split_into_chunks_of 250
21
+ split_into_chunks_of 4
20
22
 
23
+ # more info: https://github.com/meskyanichi/backup/wiki/Databases
21
24
  database MySQL do |db|
22
- db.name = "for_backup"
23
- db.username = "my_username"
24
- db.password = "my_password"
25
+ db.name = "DATABASE_NAME"
26
+ db.username = "BACKUP_USERNAME"
27
+ db.password = "BACKUP_PASSWORD"
25
28
  db.host = "localhost"
26
29
  db.port = 3306
27
30
  db.socket = "/tmp/mysql.sock"
28
31
  end
29
32
 
30
- store_with Qiniu do |eb|
31
- eb.keep = 7
32
- eb.access_key = 'replace with access key'
33
- eb.access_secret = 'replace with access secret'
34
- eb.bucket = 'backup'
33
+ store_with Qiniu do |q|
34
+ ## when using uploadToken, you can not delete the old backup (for security concern)
35
+ # q.keep = 7
36
+ q.upload_token = 'REPLACE WITH UPLOAD TOKEN'
37
+ q.bucket = 'BUCKET_NAME'
38
+ q.path = 'BACKUP_DIR1'
39
+ end
40
+
41
+ store_with Qiniu do |q|
42
+ q.keep = 7
43
+ q.access_key = 'REPLACE WITH ACCESS KEY'
44
+ q.access_secret = 'REPLACE WITH ACCESS SECRET'
45
+ q.bucket = 'BUCKET_NAME'
46
+ q.path = 'BACKUP_DIR2'
47
+ end
48
+
49
+ # more info: https://github.com/meskyanichi/backup/wiki/Encryptors
50
+ encrypt_with GPG do |encryption|
51
+ encryption.keys = {}
52
+ encryption.keys['YOUR EMAIL'] = <<-KEY
53
+ -----BEGIN PGP PUBLIC KEY BLOCK-----
54
+ Version: GnuPG v1.4.12 (Darwin)
55
+
56
+ YOUR KEY
57
+ -----END PGP PUBLIC KEY BLOCK-----
58
+ KEY
59
+ encryption.recipients = ['YOUR EMAIL']
35
60
  end
36
61
  end
37
62
  ```
data/bin/backup2qiniu ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require 'backup2qiniu/cli'
3
+
4
+ Backup2qiniu::CLI.start
@@ -1,12 +1,16 @@
1
1
  require 'backup/logger'
2
2
  require 'qiniu/rs'
3
+ require 'rest_client'
4
+ require 'base64'
3
5
 
4
6
  module Backup
5
7
  module Storage
6
8
  class Qiniu < Base
7
9
 
8
10
  attr_accessor :access_key, :access_secret
11
+ attr_accessor :upload_token
9
12
  attr_accessor :bucket
13
+ attr_accessor :path
10
14
 
11
15
  def initialize(model, storage_id = nil, &block)
12
16
  super(model, storage_id)
@@ -16,10 +20,6 @@ module Backup
16
20
  instance_eval(&block) if block_given?
17
21
  end
18
22
 
19
- def path
20
- ''
21
- end
22
-
23
23
  def remove!(pkg)
24
24
  remote_path = remote_path_for(pkg)
25
25
  establish_connection!
@@ -34,10 +34,41 @@ module Backup
34
34
  end
35
35
 
36
36
  def transfer!
37
+ if access_key and access_secret
38
+ transfer_by_secret!
39
+ else
40
+ transfer_by_upload_token!
41
+ end
42
+ end
43
+
44
+ private
45
+
46
+ def transfer_by_upload_token!
47
+ raise "upload_token is not set" if upload_token.nil?
48
+ files_to_transfer_for(@package) do |local_file, remote_file|
49
+ Logger.info "[transfer_by_upload_token] #{storage_name} started transferring " +
50
+ "'#{ local_file }'."
51
+ key = File.join(remote_path, remote_file)
52
+ upload_file(File.join(local_path, local_file), key)
53
+ Logger.info "file uploaded to bucket:#{bucket}, key:#{key}"
54
+ end
55
+ end
56
+
57
+ def upload_file(local_file, key)
58
+ RestClient.post 'http://up.qbox.me/upload',
59
+ :auth => upload_token,
60
+ :action => action(bucket, key),
61
+ :file => File.open(local_file)
62
+ end
63
+
64
+ def remote_path
65
+ remote_path_for(@package)
66
+ end
67
+
68
+ def transfer_by_secret!
37
69
  establish_connection!
38
- remote_path = remote_path_for(@package)
39
70
  files_to_transfer_for(@package) do |local_file, remote_file|
40
- Logger.info "#{storage_name} started transferring " +
71
+ Logger.info "[transfer_by_secret] #{storage_name} started transferring " +
41
72
  "'#{ local_file }'."
42
73
  upload_token = ::Qiniu::RS.generate_upload_token :scope => bucket
43
74
  key = File.join(remote_path, remote_file)
@@ -51,11 +82,16 @@ module Backup
51
82
  end
52
83
  end
53
84
 
54
- private
55
85
  def establish_connection!
86
+ raise "access_key is nil" if access_key.nil?
87
+ raise "access_secret is nil" if access_secret.nil?
56
88
  ::Qiniu::RS.establish_connection! :access_key => access_key,
57
89
  :secret_key => access_secret
58
90
  end
91
+
92
+ def action(bucket, key)
93
+ "/rs-put/#{Base64.urlsafe_encode64("#{bucket}:#{key}")}"
94
+ end
59
95
  end
60
96
  end
61
97
  end
@@ -0,0 +1,64 @@
1
+ require 'thor'
2
+ require 'qiniu-rs'
3
+
4
+ module Backup2qiniu
5
+ class CLI < Thor
6
+ desc 'gen_token', 'Generate a Upload Token for backup'
7
+ def gen_token
8
+ puts 'input your keys (you can find them on https://dev.qiniutek.com/account/keys)'
9
+ token = get_param("Access Key")
10
+ secret = get_param("Secret Key")
11
+ Qiniu::RS.establish_connection! :access_key => token, :secret_key => secret
12
+ buckets = Qiniu::RS.buckets
13
+ unless buckets
14
+ puts 'Can not verify your key, wrong key?'
15
+ exit 1
16
+ end
17
+ bucket = get_bucket_name(buckets)
18
+ days = get_param("Token Valid Days (365)")
19
+ if days == ''
20
+ days = 365
21
+ else
22
+ days = days.to_i
23
+ end
24
+
25
+ print_params access_key: token, secret_key: secret, bucket: bucket, valid_days: days
26
+
27
+ print_token Qiniu::RS.generate_upload_token(:expires_in => 3600*24*days, :scope => bucket), bucket
28
+ end
29
+
30
+ private
31
+ def print_token(token, bucket)
32
+ puts %Q{
33
+ # Copy following lines to your config file
34
+ store_with Qiniu do |q|
35
+ q.upload_token = #{token.inspect}
36
+ q.bucket = #{bucket}.inspect
37
+ # q.path = 'BACKUP_DIR1'
38
+ end
39
+ }
40
+ end
41
+
42
+ def get_bucket_name(buckets)
43
+ puts "Your buckets: #{buckets.join(", ")}"
44
+ bucket = get_param("Select Bucket")
45
+ return bucket if buckets.include? bucket
46
+ puts 'ERROR: invalid bucket name'
47
+ puts
48
+ get_bucket_name(buckets)
49
+ end
50
+
51
+ def print_params(h)
52
+ puts
53
+ puts 'Params'
54
+ h.each do |k, v|
55
+ puts "#{k}: #{v}"
56
+ end
57
+ end
58
+
59
+ def get_param(hint)
60
+ STDOUT.write "#{hint}: "
61
+ STDIN.gets.chomp
62
+ end
63
+ end
64
+ end
@@ -1,3 +1,3 @@
1
1
  module Backup2qiniu
2
- VERSION = "3.3.0"
2
+ VERSION = "3.3.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: backup2qiniu
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.0
4
+ version: 3.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - LI Daobing
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-19 00:00:00.000000000 Z
11
+ date: 2013-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backup
@@ -41,7 +41,8 @@ dependencies:
41
41
  description: backup to qiniutek.com
42
42
  email:
43
43
  - lidaobing@gmail.com
44
- executables: []
44
+ executables:
45
+ - backup2qiniu
45
46
  extensions: []
46
47
  extra_rdoc_files: []
47
48
  files:
@@ -53,9 +54,11 @@ files:
53
54
  - README.md
54
55
  - Rakefile
55
56
  - backup2qiniu.gemspec
57
+ - bin/backup2qiniu
56
58
  - lib/backup/config/qiniu.rb
57
59
  - lib/backup/storage/qiniu.rb
58
60
  - lib/backup2qiniu.rb
61
+ - lib/backup2qiniu/cli.rb
59
62
  - lib/backup2qiniu/version.rb
60
63
  homepage: https://github.com/lidaobing/backup2qiniu
61
64
  licenses: []
@@ -76,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
76
79
  version: '0'
77
80
  requirements: []
78
81
  rubyforge_project:
79
- rubygems_version: 2.0.2
82
+ rubygems_version: 2.0.3
80
83
  signing_key:
81
84
  specification_version: 4
82
85
  summary: backup to qiniutek.com