Parent

Class/Module Index [+]

Quicksearch

Backup::Database::PostgreSQL

Attributes

additional_options[RW]

Additional "pg_dump" options

host[RW]

Connectivity options

name[RW]

Name of the database that needs to get dumped

only_tables[RW]

Tables to dump, tables that aren't specified won't get dumped

password[RW]

Credentials for the specified database

pg_dump_utility[RW]

Path to pg_dump utility (optional)

port[RW]

Connectivity options

skip_tables[RW]

Tables to skip while dumping the database

socket[RW]

Connectivity options

username[RW]

Credentials for the specified database

Public Class Methods

new(model, &block) click to toggle source

Creates a new instance of the PostgreSQL adapter object Sets the PGPASSWORD environment variable to the password so it doesn't prompt and hang in the process

# File lib/backup/database/postgresql.rb, line 42
def initialize(model, &block)
  super(model)

  @skip_tables        ||= Array.new
  @only_tables        ||= Array.new
  @additional_options ||= Array.new

  instance_eval(&block) if block_given?

  @pg_dump_utility ||= utility(:pg_dump)
end

Public Instance Methods

connectivity_options() click to toggle source

Builds the PostgreSQL connectivity options syntax to connect the user to perform the database dumping process, socket gets gsub'd to host since that's the option PostgreSQL takes for socket connections as well. In case both the host and the socket are specified, the socket will take priority over the host

# File lib/backup/database/postgresql.rb, line 109
def connectivity_options
  ]host port socket].map do |option|
    next if send(option).to_s.empty?
    "--#{option}='#{send(option)}'".gsub('--socket=', '--host=')
  end.compact.join(' ')
end
password_options() click to toggle source

Builds the password syntax PostgreSQL uses to authenticate the user to perform database dumping

# File lib/backup/database/postgresql.rb, line 93
def password_options
  password.to_s.empty? ? '' : "PGPASSWORD='#{password}' "
end
perform!() click to toggle source

Performs the pgdump command and outputs the data to the specified path based on the 'trigger'

# File lib/backup/database/postgresql.rb, line 57
def perform!
  super

  pipeline = Pipeline.new
  dump_ext = 'sql'

  pipeline << pgdump
  if @model.compressor
    @model.compressor.compress_with do |command, ext|
      pipeline << command
      dump_ext << ext
    end
  end
  pipeline << "cat > '#{ File.join(@dump_path, name) }.#{ dump_ext }'"

  pipeline.run
  if pipeline.success?
    Logger.message "#{ database_name } Complete!"
  else
    raise Errors::Database::PipelineError,
        "#{ database_name } Dump Failed!\n" +
        pipeline.error_messages
  end
end
pgdump() click to toggle source

Builds the full pgdump string based on all attributes

# File lib/backup/database/postgresql.rb, line 84
def pgdump
  "#{password_options}" +
  "#{ pg_dump_utility } #{ username_options } #{ connectivity_options } " +
  "#{ user_options } #{ tables_to_dump } #{ tables_to_skip } #{ name }"
end
tables_to_dump() click to toggle source

Builds the PostgreSQL syntax for specifying which tables to dump during the dumping of the database

# File lib/backup/database/postgresql.rb, line 126
def tables_to_dump
  only_tables.map do |table|
    "--table='#{table}'"
  end.join(' ')
end
tables_to_skip() click to toggle source

Builds the PostgreSQL syntax for specifying which tables to skip during the dumping of the database

# File lib/backup/database/postgresql.rb, line 135
def tables_to_skip
  skip_tables.map do |table|
    "--exclude-table='#{table}'"
  end.join(' ')
end
user_options() click to toggle source

Builds a PostgreSQL compatible string for the additional options specified by the user

# File lib/backup/database/postgresql.rb, line 119
def user_options
  additional_options.join(' ')
end
username_options() click to toggle source

Builds the credentials PostgreSQL syntax to authenticate the user to perform the database dumping process

# File lib/backup/database/postgresql.rb, line 100
def username_options
  username.to_s.empty? ? '' : "--username='#{username}'"
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.