Module: HerokuMongoBackup

Defined in:
lib/heroku-mongo-backup.rb

Defined Under Namespace

Classes: Backup, Railtie

Class Method Summary collapse

Class Method Details

.remove_old_backup_files(directory, files_number_to_leave) ⇒ Object



42
43
44
45
# File 'lib/s3_helpers.rb', line 42

def HerokuMongoBackup::remove_old_backup_files(bucket, files_number_to_leave)
  excess = ( object_keys = bucket.objects.find_all(:prefix => "backups/").map { |o| o.key }.sort ).count - files_number_to_leave
  (0..excess-1).each { |i| bucket.objects.find(object_keys[i]).destroy } if excess > 0
end

.s3_connect(bucket, key, secret) ⇒ Object

Using ‘aws/s3’ gem as Amazon S3 interface

puts “Using 'aws/s3' gem as Amazon S3 interface.”



16
17
18
19
20
21
# File 'lib/s3_helpers.rb', line 16

def HerokuMongoBackup::s3_connect(bucket, key, secret)
  service = S3::Service.new(:access_key_id     => key,
                            :secret_access_key => secret)
  bucket  = service.buckets.find(bucket)
  return bucket
end

.s3_download(directory, filename) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/s3_helpers.rb', line 29

def HerokuMongoBackup::s3_download(bucket, filename)
  object  = bucket.objects.find("backups/#{filename}")
  content = object.content(reload=true)

  puts "Backup file:"
  puts "  name: #{filename}"
  puts "  type: #{object.content_type}"
  puts "  size: #{content.size} bytes"
  puts "\n"

  return content
end

.s3_upload(directory, filename) ⇒ Object



23
24
25
26
27
# File 'lib/s3_helpers.rb', line 23

def HerokuMongoBackup::s3_upload(bucket, filename)
  object = bucket.objects.build("backups/#{filename}")
  object.content = open(filename)
  object.save
end