class Backup::Storage::Qiniu
Attributes
access_key[RW]
Qiniu
API credentials
bucket[RW]
Qiniu
bucket name
secret_key[RW]
Qiniu
API credentials
Public Class Methods
new(model, storage_id = nil)
click to toggle source
Calls superclass method
Backup::Storage::Base::new
# File lib/backup/storage/qiniu.rb, line 18 def initialize(model, storage_id = nil) super @path ||= 'backups' check_configuration config_credentials end
Private Instance Methods
check_configuration()
click to toggle source
# File lib/backup/storage/qiniu.rb, line 51 def check_configuration required = %w{ access_key secret_key bucket } raise Error, <<-EOS if required.map {|name| send(name) }.any?(&:nil?) Configuration Error #{ required.map {|name| "##{ name }"}.join(', ') } are all required EOS end
config_credentials()
click to toggle source
# File lib/backup/storage/qiniu.rb, line 60 def config_credentials ::Qiniu.establish_connection!(access_key: access_key, secret_key: secret_key) end
remove!(package)
click to toggle source
Called by the Cycler
. Any error raised will be logged as a warning.
# File lib/backup/storage/qiniu.rb, line 43 def remove!(package) Logger.info "Removing backup package dated #{ package.time }..." remote_path = remote_path_for(package) package.filenames.each do |filename| ::Qiniu.delete(bucket, File.join(remote_path, filename)) end end
transfer!()
click to toggle source
# File lib/backup/storage/qiniu.rb, line 28 def transfer! package.filenames.each do |filename| src = File.join(Config.tmp_path, filename) dest = File.join(remote_path, filename) Logger.info "Storing '#{ dest }'..." ::Qiniu.upload_file(uptoken: ::Qiniu.generate_upload_token, bucket: bucket, file: src, key: dest) end end