Class: Bosh::Director::DbBackup::Adapter::Postgres

Inherits:
Object
  • Object
show all
Defined in:
lib/bosh/director/db_backup/adapter/postgres.rb

Instance Method Summary collapse

Constructor Details

#initialize(db_config) ⇒ Postgres

Returns a new instance of Postgres.



8
9
10
# File 'lib/bosh/director/db_backup/adapter/postgres.rb', line 8

def initialize(db_config)
  @db_config = db_config
end

Instance Method Details

#export(path) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/bosh/director/db_backup/adapter/postgres.rb', line 12

def export(path)
  env = {}
  env['PGPASSWORD'] = @db_config['password'] if @db_config.has_key?('password')

  stdout, stderr, status = Open3.capture3(
    env,
    'pg_dump',
    '--host',     @db_config.fetch('host'),
    '--port',     @db_config.fetch('port').to_s,
    '--username', @db_config.fetch('user'),
    '--file',     path,
    @db_config.fetch('database'),
  )

  unless status.success?
    raise("pg_dump exited #{status.exitstatus}, output: '#{stdout}', error: '#{stderr}'")
  end

  path
end