class Backup::Storage::Aliyun
Attributes
access_key_id[RW]
access_key_secret[RW]
area[RW]
bucket[RW]
path[RW]
Public Class Methods
new(model, storage_id = nil, &block)
click to toggle source
Calls superclass method
# File lib/backup/storage/aliyun.rb, line 8 def initialize(model, storage_id = nil, &block) super(model, storage_id) @path ||= 'backups' @area ||= 'cn-hangzhou' instance_eval(&block) if block_given? end
Private Instance Methods
client()
click to toggle source
# File lib/backup/storage/aliyun.rb, line 19 def client return @client if defined? @client opts = { host: "oss-#{self.area}.aliyuncs.com", bucket: self.bucket } @client = ::Aliyun::Oss::Client.new(self.access_key_id, self.access_key_secret, opts) @client end
remove!(package)
click to toggle source
# File lib/backup/storage/aliyun.rb, line 42 def remove!(package) remote_path = remote_path_for(package) Logger.info "#{storage_name} removing '#{remote_path}'..." client.bucket_delete_object(remote_path) end
transfer!()
click to toggle source
# File lib/backup/storage/aliyun.rb, line 29 def transfer! remote_path = remote_path_for(@package) @package.filenames.each do |filename| src = File.join(Config.tmp_path, filename) dest = File.join(remote_path, filename) Logger.info "#{storage_name} uploading '#{ dest }'..." File.open(src, 'r') do |file| client.bucket_create_object(dest, file, {}) end end end