lib/backup/database/postgresql.rb in backup-3.2.0 vs lib/backup/database/postgresql.rb in backup-3.3.0
- old
+ new
@@ -26,120 +26,94 @@
##
# Additional "pg_dump" options
attr_accessor :additional_options
- ##
- # Path to pg_dump utility (optional)
- attr_accessor :pg_dump_utility
-
- attr_deprecate :utility_path, :version => '3.0.21',
- :message => 'Use PostgreSQL#pg_dump_utility instead.',
- :action => lambda {|klass, val| klass.pg_dump_utility = val }
-
- ##
- # 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
- def initialize(model, &block)
- super(model)
-
- @skip_tables ||= Array.new
- @only_tables ||= Array.new
- @additional_options ||= Array.new
-
+ def initialize(model, database_id = nil, &block)
+ super
instance_eval(&block) if block_given?
-
- @pg_dump_utility ||= utility(:pg_dump)
end
##
- # Performs the pgdump command and outputs the
- # data to the specified path based on the 'trigger'
+ # Performs the mysqldump command and outputs the dump file
+ # in the +dump_path+ using +dump_filename+.
+ #
+ # <trigger>/databases/PostgreSQL[-<database_id>].sql[.gz]
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
+ model.compressor.compress_with do |command, ext|
+ pipeline << command
+ dump_ext << ext
+ end if model.compressor
+
pipeline << "#{ utility(:cat) } > " +
- "'#{ File.join(@dump_path, name) }.#{ dump_ext }'"
+ "'#{ File.join(dump_path, dump_filename) }.#{ dump_ext }'"
+
pipeline.run
if pipeline.success?
- Logger.info "#{ database_name } Complete!"
+ log!(:finished)
else
raise Errors::Database::PipelineError,
- "#{ database_name } Dump Failed!\n" +
- pipeline.error_messages
+ "#{ database_name } Dump Failed!\n" + pipeline.error_messages
end
end
- ##
- # Builds the full pgdump string based on all attributes
def pgdump
- "#{password_options}" +
- "#{ pg_dump_utility } #{ username_options } #{ connectivity_options } " +
+ "#{ password_option }" +
+ "#{ utility(:pg_dump) } #{ username_option } #{ connectivity_options } " +
"#{ user_options } #{ tables_to_dump } #{ tables_to_skip } #{ name }"
end
- ##
- # Builds the password syntax PostgreSQL uses to authenticate the user
- # to perform database dumping
- def password_options
- password.to_s.empty? ? '' : "PGPASSWORD='#{password}' "
+ def password_option
+ "PGPASSWORD='#{ password }' " if password
end
- ##
- # Builds the credentials PostgreSQL syntax to authenticate the user
- # to perform the database dumping process
- def username_options
- username.to_s.empty? ? '' : "--username='#{username}'"
+ def username_option
+ "--username='#{ username }'" if username
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
def connectivity_options
- %w[host port socket].map do |option|
- next if send(option).to_s.empty?
- "--#{option}='#{send(option)}'".gsub('--socket=', '--host=')
- end.compact.join(' ')
+ return "--host='#{ socket }'" if socket
+
+ opts = []
+ opts << "--host='#{ host }'" if host
+ opts << "--port='#{ port }'" if port
+ opts.join(' ')
end
- ##
- # Builds a PostgreSQL compatible string for the additional options
- # specified by the user
def user_options
- additional_options.join(' ')
+ Array(additional_options).join(' ')
end
- ##
- # Builds the PostgreSQL syntax for specifying which tables to dump
- # during the dumping of the database
def tables_to_dump
- only_tables.map do |table|
- "--table='#{table}'"
+ Array(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
def tables_to_skip
- skip_tables.map do |table|
- "--exclude-table='#{table}'"
+ Array(skip_tables).map do |table|
+ "--exclude-table='#{ table }'"
end.join(' ')
end
+
+ attr_deprecate :utility_path, :version => '3.0.21',
+ :message => 'Use Backup::Utilities.configure instead.',
+ :action => lambda {|klass, val|
+ Utilities.configure { pg_dump val }
+ }
+
+ attr_deprecate :pg_dump_utility, :version => '3.3.0',
+ :message => 'Use Backup::Utilities.configure instead.',
+ :action => lambda {|klass, val|
+ Utilities.configure { pg_dump val }
+ }
end
end
end