Class: Pgchief::Command::DatabaseBackup

Inherits:
Base
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/pgchief/command/database_backup.rb

Overview

Command object to back up a database

Instance Attribute Summary collapse

Attributes inherited from Base

#conn, #params

Instance Method Summary collapse

Methods inherited from Base

call

Constructor Details

#initialize(*params) ⇒ DatabaseBackup



15
16
17
18
19
# File 'lib/pgchief/command/database_backup.rb', line 15

def initialize(*params)
  super
  @database = params.first
  @uploader = Pgchief::Command::S3Upload.new(local_location)
end

Instance Attribute Details

#databaseObject (readonly)

Returns the value of attribute database.



13
14
15
# File 'lib/pgchief/command/database_backup.rb', line 13

def database
  @database
end

Instance Method Details

#callObject



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/pgchief/command/database_backup.rb', line 21

def call
  raise Pgchief::Errors::DatabaseMissingError unless db_exists?

  backup!
  check_backup!
  upload! if configured?

  "Database '#{database}' backed up to #{location}"
rescue PG::Error => e
  "Error: #{e.message}"
ensure
  conn.close
end