Class: Backup::Database::PostgreSQL
- Defined in:
- lib/backup/database/postgresql.rb
Instance Attribute Summary collapse
-
#additional_options ⇒ Object
Additional “pg_dump” options.
-
#host ⇒ Object
Connectivity options.
-
#name ⇒ Object
Name of the database that needs to get dumped.
-
#only_tables ⇒ Object
Tables to dump, tables that aren’t specified won’t get dumped.
-
#password ⇒ Object
Credentials for the specified database.
-
#port ⇒ Object
Connectivity options.
-
#skip_tables ⇒ Object
Tables to skip while dumping the database.
-
#socket ⇒ Object
Connectivity options.
-
#username ⇒ Object
Credentials for the specified database.
Attributes inherited from Base
Instance Method Summary collapse
-
#connectivity_options ⇒ Object
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.
-
#credential_options ⇒ Object
Builds the credentials PostgreSQL syntax to authenticate the user to perform the database dumping process.
-
#initialize(&block) ⇒ PostgreSQL
constructor
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.
-
#options ⇒ Object
Builds a PostgreSQL compatible string for the additional options specified by the user.
-
#perform! ⇒ Object
Performs the pgdump command and outputs the data to the specified path based on the ‘trigger’ and resets the ‘PGPASSWORD’ environment variable to nil.
-
#pgdump ⇒ Object
Builds the full pgdump string based on all attributes.
-
#tables_to_dump ⇒ Object
Builds the PostgreSQL syntax for specifying which tables to dump during the dumping of the database.
-
#tables_to_skip ⇒ Object
Builds the PostgreSQL syntax for specifying which tables to skip during the dumping of the database.
Methods inherited from Base
Methods included from Configuration::Helpers
#clear_defaults!, #getter_methods, #load_defaults!, #setter_methods
Methods included from CLI
Constructor Details
#initialize(&block) ⇒ PostgreSQL
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
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/backup/database/postgresql.rb', line 35 def initialize(&block) load_defaults! @skip_tables ||= Array.new @only_tables ||= Array.new @additional_options ||= Array.new instance_eval(&block) prepare! ENV['PGPASSWORD'] = password end |
Instance Attribute Details
#additional_options ⇒ Object
Additional “pg_dump” options
29 30 31 |
# File 'lib/backup/database/postgresql.rb', line 29 def @additional_options end |
#host ⇒ Object
Connectivity options
17 18 19 |
# File 'lib/backup/database/postgresql.rb', line 17 def host @host end |
#name ⇒ Object
Name of the database that needs to get dumped
9 10 11 |
# File 'lib/backup/database/postgresql.rb', line 9 def name @name end |
#only_tables ⇒ Object
Tables to dump, tables that aren’t specified won’t get dumped
25 26 27 |
# File 'lib/backup/database/postgresql.rb', line 25 def only_tables @only_tables end |
#password ⇒ Object
Credentials for the specified database
13 14 15 |
# File 'lib/backup/database/postgresql.rb', line 13 def password @password end |
#port ⇒ Object
Connectivity options
17 18 19 |
# File 'lib/backup/database/postgresql.rb', line 17 def port @port end |
#skip_tables ⇒ Object
Tables to skip while dumping the database
21 22 23 |
# File 'lib/backup/database/postgresql.rb', line 21 def skip_tables @skip_tables end |
#socket ⇒ Object
Connectivity options
17 18 19 |
# File 'lib/backup/database/postgresql.rb', line 17 def socket @socket end |
#username ⇒ Object
Credentials for the specified database
13 14 15 |
# File 'lib/backup/database/postgresql.rb', line 13 def username @username end |
Instance Method Details
#connectivity_options ⇒ Object
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
78 79 80 81 82 83 |
# File 'lib/backup/database/postgresql.rb', line 78 def %w[host port socket].map do |option| next if send(option).nil? or (send(option).respond_to?(:empty?) and send(option).empty?) "--#{option}='#{send(option)}'".gsub('--socket=', '--host=') end.compact.join("\s") end |
#credential_options ⇒ Object
Builds the credentials PostgreSQL syntax to authenticate the user to perform the database dumping process
68 69 70 71 |
# File 'lib/backup/database/postgresql.rb', line 68 def return '' unless username.is_a?(String) and not username.empty? "--username='#{username}'" end |
#options ⇒ Object
Builds a PostgreSQL compatible string for the additional options specified by the user
88 89 90 |
# File 'lib/backup/database/postgresql.rb', line 88 def .join("\s") end |
#perform! ⇒ Object
Performs the pgdump command and outputs the data to the specified path based on the ‘trigger’ and resets the ‘PGPASSWORD’ environment variable to nil
103 104 105 106 107 |
# File 'lib/backup/database/postgresql.rb', line 103 def perform! log! run("#{pgdump} > '#{File.join(dump_path, name)}.sql'") ENV['PGPASSWORD'] = nil end |
#pgdump ⇒ Object
Builds the full pgdump string based on all attributes
94 95 96 97 |
# File 'lib/backup/database/postgresql.rb', line 94 def pgdump "#{ utility(:pg_dump) } #{ } #{ } " + "#{ } #{ tables_to_dump } #{ tables_to_skip } #{ name }" end |
#tables_to_dump ⇒ Object
Builds the PostgreSQL syntax for specifying which tables to dump during the dumping of the database
59 60 61 62 63 |
# File 'lib/backup/database/postgresql.rb', line 59 def tables_to_dump only_tables.map do |table| "--table='#{table}'" end.join("\s") end |
#tables_to_skip ⇒ Object
Builds the PostgreSQL syntax for specifying which tables to skip during the dumping of the database
50 51 52 53 54 |
# File 'lib/backup/database/postgresql.rb', line 50 def tables_to_skip skip_tables.map do |table| "--exclude-table='#{table}'" end.join("\s") end |