Base
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
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
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
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
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
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
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
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
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
Generated with the Darkfish Rdoc Generator 2.