Class: WpBackup::S3
- Inherits:
-
Object
- Object
- WpBackup::S3
- Defined in:
- lib/wp_backup/s3.rb
Instance Method Summary collapse
- #delete_keys(keys) ⇒ Object
-
#initialize(aws_config, root_bucket) ⇒ S3
constructor
A new instance of S3.
- #keys ⇒ Object
- #read(key) ⇒ Object
- #store(file_name) ⇒ Object
Constructor Details
#initialize(aws_config, root_bucket) ⇒ S3
Returns a new instance of S3.
5 6 7 8 9 10 11 |
# File 'lib/wp_backup/s3.rb', line 5 def initialize(aws_config, root_bucket) AWS.config(aws_config) @s3 = AWS::S3.new @root_bucket = root_bucket @bucket = @s3.buckets.create(@root_bucket) end |
Instance Method Details
#delete_keys(keys) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/wp_backup/s3.rb', line 34 def delete_keys(keys) keys.each do |key| puts "Deleting #{key}" use_key = "wp-backup-#{key}.tar.gz" @bucket.objects[use_key].delete end end |
#keys ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/wp_backup/s3.rb', line 24 def keys [].tap do |keys| @bucket.objects.each do |obj| if obj.key =~ /wp-backup-(\d+).tar.gz/ keys << $1 end end end end |
#read(key) ⇒ Object
19 20 21 22 |
# File 'lib/wp_backup/s3.rb', line 19 def read(key) use_key = "wp-backup-#{key}.tar.gz" @bucket.objects[use_key].read end |
#store(file_name) ⇒ Object
13 14 15 16 17 |
# File 'lib/wp_backup/s3.rb', line 13 def store(file_name) basename = File.basename(file_name) object = @bucket.objects[basename] object.write(:file => file_name) end |