Class: Dumpr::Driver::Postgres

Inherits:
Base
  • Object
show all
Defined in:
lib/dumpr/driver/postgres.rb

Instance Attribute Summary

Attributes inherited from Base

#database, #destination, #destination_dumpfile, #destination_host, #dumpdir, #dumpfile, #gzip, #gzip_options, #host, #import_options, #opts, #password, #tables, #user

Instance Method Summary collapse

Methods inherited from Base

#decompress, #dump, #import, #initialize, #logger, #remote_destination?

Constructor Details

This class inherits a constructor from Dumpr::Driver::Base

Instance Method Details

#configure(opts) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/dumpr/driver/postgres.rb', line 22

def configure(opts)
  super(opts)
  if @all_databases
    raise BadConfig.new "#{self.class} does not support --all-databases"
  elsif @databases
    raise BadConfig.new "#{self.class} does not support multiple --databases"
  elsif @database
    # supported
  else
    raise BadConfig.new "#{self.class} requires option --database"
  end
  if @tables
    raise BadConfig.new "#{self.class} does not support --tables"
  end
end

#dump_cmdObject



38
39
40
41
42
43
44
45
46
# File 'lib/dumpr/driver/postgres.rb', line 38

def dump_cmd
  if @all_databases
    "pg_dump -h #{host} -p #{port} -U #{user} --password #{password} #{dump_options}"
  elsif @databases
    # not supported
  else
    "pg_dump -h #{host} -p #{port} -U #{user} --password #{password} #{dump_options} #{database}"
  end
end

#dump_installed?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/dumpr/driver/postgres.rb', line 14

def dump_installed?
  system("which pg_dump") == true
end

#dump_optionsObject



10
11
12
# File 'lib/dumpr/driver/postgres.rb', line 10

def dump_options
  @dump_options || "-Fc" #"-Fc -v"
end

#import_cmdObject



48
49
50
51
52
53
54
# File 'lib/dumpr/driver/postgres.rb', line 48

def import_cmd
  if @database
    "pg_restore -h #{host} -p #{port} -U #{user} --password #{password} --verbose --clean --no-owner --no-acl -d #{database} #{dumpfile}"
  else
    "pg_restore -h #{host} -p #{port} -U #{user} --password #{password} --verbose --clean --no-owner --no-acl #{database} #{dumpfile}"
  end
end

#import_installed?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/dumpr/driver/postgres.rb', line 18

def import_installed?
  system("which pg_restore") == true
end

#portObject



6
7
8
# File 'lib/dumpr/driver/postgres.rb', line 6

def port
  @port || 5432
end