Class: BackupFoundation::Item::PostgreSQL

Inherits:
Base
  • Object
show all
Defined in:
lib/backup_foundation/item/postgresql.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#decrypt_if_needed_and_restore, #dump_and_encrypt_if_needed, #initialize, #outfile_path, #output_to_file

Constructor Details

This class inherits a constructor from BackupFoundation::Item::Base

Class Method Details

.exist?(rails_env = nil) ⇒ Boolean



5
6
7
8
9
10
# File 'lib/backup_foundation/item/postgresql.rb', line 5

def exist?(rails_env=nil)
  defined?(ActiveRecord::Base) &&
  ActiveRecord::Base.configurations &&
  ActiveRecord::Base.configurations[rails_env] &&
  ActiveRecord::Base.configurations[rails_env]['adapter'] == 'postgresql'
end

.get_config(rails_env = nil) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/backup_foundation/item/postgresql.rb', line 12

def get_config(rails_env=nil)
  config = ActiveRecord::Base.configurations[rails_env]
  {
    host: config['host'] || config['socket'],
    port: config['port'],
    username: config['username'],
    password: config['password'],
    database: config['database']
  }
end

Instance Method Details

#command_paramsObject



28
29
30
31
32
33
# File 'lib/backup_foundation/item/postgresql.rb', line 28

def command_params
  [:host, :port, :username].map do |option|
    next if @options[option].blank?
    "--#{option}='#{@options[option]}'"
  end.compact.join ' '
end

#command_password_variableObject



35
36
37
# File 'lib/backup_foundation/item/postgresql.rb', line 35

def command_password_variable
  @options[:password].blank? ? '' : "PGPASSWORD='#{@options[:password]}'"
end

#load_dump(infile_path) ⇒ Object



39
40
41
# File 'lib/backup_foundation/item/postgresql.rb', line 39

def load_dump(infile_path)
  decrypt_if_needed_and_restore "#{command_password_variable} psql #{command_params} #{@options[:database]}", infile_path
end

#save_dump(tmpdir) ⇒ Object



24
25
26
# File 'lib/backup_foundation/item/postgresql.rb', line 24

def save_dump(tmpdir)
  dump_and_encrypt_if_needed "#{command_password_variable} pg_dump #{command_params} #{@options[:database]}"
end