Class: EY::Backup::Database

Inherits:
Object
  • Object
show all
Defined in:
lib/ey_backup/database.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(engine, base_path, keep, backend, environment, name) ⇒ Database

Returns a new instance of Database.



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/ey_backup/database.rb', line 4

def initialize(engine, base_path, keep, backend, environment, name)
  if name.nil? || name.empty?
    raise ArgumentError, "database name is blank"
  end
  @engine    = engine
  @base_path = base_path
  @keep      = keep
  @backend = backend
  @environment = environment
  @name = name
end

Instance Attribute Details

#base_pathObject (readonly)

Returns the value of attribute base_path.



15
16
17
# File 'lib/ey_backup/database.rb', line 15

def base_path
  @base_path
end

#engineObject (readonly)

Returns the value of attribute engine.



15
16
17
# File 'lib/ey_backup/database.rb', line 15

def engine
  @engine
end

#environmentObject (readonly)

Returns the value of attribute environment.



15
16
17
# File 'lib/ey_backup/database.rb', line 15

def environment
  @environment
end

#keepObject (readonly)

Returns the value of attribute keep.



15
16
17
# File 'lib/ey_backup/database.rb', line 15

def keep
  @keep
end

#nameObject (readonly)

Returns the value of attribute name.



15
16
17
# File 'lib/ey_backup/database.rb', line 15

def name
  @name
end

Instance Method Details

#backupsObject



21
22
23
24
# File 'lib/ey_backup/database.rb', line 21

def backups
  s3_objects = bucket_minder.list("#{@environment}.#{@name}").select { |o| o[:name] =~ @engine.suffix }
  s3_objects.map {|o| BackupSet.new(self, o[:name], nil, o[:keys]) }.sort
end

#bucket_minderObject



17
18
19
# File 'lib/ey_backup/database.rb', line 17

def bucket_minder
  @backend.bucket_minder
end

#dumpObject



26
27
28
29
30
31
32
33
# File 'lib/ey_backup/database.rb', line 26

def dump
  FileUtils.mkdir_p(@base_path)

  basename = generate_basename
  file = @engine.dump(@name, basename)

  BackupSet.from(self, basename, file)
end

#generate_basenameObject



39
40
41
# File 'lib/ey_backup/database.rb', line 39

def generate_basename
  "#{@base_path}/#{@name}.#{timestamp}"
end

#start_upload(filenames) ⇒ Object



35
36
37
# File 'lib/ey_backup/database.rb', line 35

def start_upload(filenames)
  @backend.start_upload(filenames, @environment, @name)
end

#timestampObject



43
44
45
# File 'lib/ey_backup/database.rb', line 43

def timestamp
  Time.now.strftime("%Y-%m-%dT%H-%M-%S")
end