class Backup::Storage::S3
Attributes
Amazon Simple Storage Service (S3) Credentials
Amazon S3 bucket name
Multipart chunk size, specified in MiB.
Each package file larger than chunk_size
will be uploaded
using S3 Multipart Upload.
Minimum: 5 (but may be disabled with 0) Maximum: 5120 Default: 5
Encryption algorithm to use for Amazon Server-Side Encryption
Supported values:
-
:aes256
Default: nil
Additional options to pass along to fog. e.g. Fog::Storage.new({ :provider => 'AWS' }.merge(fog_options))
Number of times to retry failed operations.
Default: 10
Region of the specified S3 bucket
Time in seconds to pause before each retry.
Default: 30
Amazon Simple Storage Service (S3) Credentials
Amazon Simple Storage Service (S3) Credentials
Public Class Methods
# File lib/backup/storage/s3.rb, line 71 def initialize(model, storage_id = nil) super @chunk_size ||= 5 # MiB @max_retries ||= 10 @retry_waitsec ||= 30 @path ||= 'backups' @storage_class ||= :standard @path = @path.sub(/^\//, '') check_configuration end
Private Instance Methods
# File lib/backup/storage/s3.rb, line 125 def check_configuration if use_iam_profile required = %w{ bucket } else required = %w{ access_key_id secret_access_key bucket } end raise Error, " Configuration Error #{ required.map {|name| "##{ name }"}.join(', ') } are all required " if required.map {|name| send(name) }.any?(&:nil?) raise Error, " Configuration Error #chunk_size must be between 5 and 5120 (or 0 to disable multipart) " if chunk_size > 0 && !chunk_size.between?(5, 5120) raise Error, " Configuration Error #encryption must be :aes256 or nil " if encryption && encryption.to_s.upcase != 'AES256' classes = ['STANDARD', 'STANDARD_IA', 'REDUCED_REDUNDANCY'] raise Error, " Configuration Error #storage_class must be :standard or :standard_ia or :reduced_redundancy " unless classes.include?(storage_class.to_s.upcase) end
# File lib/backup/storage/s3.rb, line 87 def cloud_io @cloud_io ||= CloudIO::S3.new( :access_key_id => access_key_id, :secret_access_key => secret_access_key, :use_iam_profile => use_iam_profile, :region => region, :bucket => bucket, :encryption => encryption, :storage_class => storage_class, :max_retries => max_retries, :retry_waitsec => retry_waitsec, :chunk_size => chunk_size, :fog_options => fog_options ) end
Called by the Cycler. Any error raised will be logged as a warning.
# File lib/backup/storage/s3.rb, line 114 def remove!(package) Logger.info "Removing backup package dated #{ package.time }..." remote_path = remote_path_for(package) objects = cloud_io.objects(remote_path) raise Error, "Package at '#{ remote_path }' not found" if objects.empty? cloud_io.delete(objects) end
# File lib/backup/storage/s3.rb, line 103 def transfer! package.filenames.each do |filename| src = File.join(Config.tmp_path, filename) dest = File.join(remote_path, filename) Logger.info "Storing '#{ bucket }/#{ dest }'..." cloud_io.upload(src, dest) end end