Class: Railscluster::PostgresqlDatabase

Inherits:
Database
  • Object
show all
Defined in:
lib/railscluster/capistrano/backup.rb

Instance Attribute Summary

Attributes inherited from Database

#config

Instance Method Summary collapse

Methods inherited from Database

build, #initialize

Constructor Details

This class inherits a constructor from Railscluster::Database

Instance Method Details

#backup_command(local_port, application) ⇒ Object



30
31
32
33
34
# File 'lib/railscluster/capistrano/backup.rb', line 30

def backup_command local_port, application
  filename = "#{application}.pgdump.#{Time.now.to_i}.pgz"
  
  "PGPASSWORD='#{config['password']}' pg_dump -Fc --no-owner --no-privileges -hlocalhost --port=#{local_port} -U#{config['username']} #{config['database']} -f backups/#{filename}"
end

#find_local_backupObject



36
37
38
# File 'lib/railscluster/capistrano/backup.rb', line 36

def find_local_backup
  `ls -tr backups/*pgdump* | tail -n 1`.chomp
end

#restore_command(file) ⇒ Object



40
41
42
43
44
45
# File 'lib/railscluster/capistrano/backup.rb', line 40

def restore_command file
  user = "-U #{config['username']}" if config['username']
  password = "PGPASSWORD='#{config['password']}' " if config['password']
  
  "#{password}pg_restore #{user} -d #{config['database']} -c -O -hlocalhost #{file}; true" 
end

#server_portObject



26
27
28
# File 'lib/railscluster/capistrano/backup.rb', line 26

def server_port
  config['port'] || 5432
end