class PgUtils::Restore

Attributes

filename[RW]
local_database[RW]
local_database_password[RW]
local_database_username[RW]
local_folder[RW]

Public Class Methods

new() click to toggle source
# File lib/pg_utils/restore.rb, line 8
def initialize()
  PgUtils.configuration.instance_variables.each do |k|
    instance_variable_set(k, PgUtils.configuration.instance_variable_get(k))
  end
end

Public Instance Methods

run(filename = nil) click to toggle source
# File lib/pg_utils/restore.rb, line 14
def run(filename = nil)
  if filename && filename.include?(".sql.gz")
    backup_file = "#{local_folder}/#{filename}"
  elsif !filename.nil?
    backup_file = "#{local_folder}/#{filename}.sql.gz"
  else
    backup_file = Dir.glob("#{local_folder}/*").max_by {|f| File.mtime(f)}
  end
  puts "restoring backup: #{backup_file}"
  exec_cmd =  "PGPASSWORD=\"#{local_database_password}\" pg_restore -c -h localhost -U #{local_database_username} -Fc -d #{local_database} #{backup_file} --verbose"
  system(exec_cmd)
end