Sha256: 309df1af03ab788987950b3640ff4405c1ba2cd4592a7084b33874dff658e6b6
Contents?: true
Size: 1.5 KB
Versions: 6
Compression:
Stored size: 1.5 KB
Contents
module EY module Backup class Postgresql < Engine register 'postgresql' def dump(database_name, basename) file = basename + '.dump' command = "PGPASSWORD='#{password}' pg_dump -h #{host} --format=c -Upostgres #{database_name}" if gpg? command << " | " << GPGEncryptor.command_for(key_id) file << GPGEncryptor.extension end command << " > #{file}" run(command) file end def load(database_name, file) if database_exists?(database_name) cycle_database(database_name) else create_database(database_name) end command = "cat #{file}" if gpg? raise "Cannot load a GPG backup" end command << " | PGPASSWORD='#{password}' pg_restore -h #{host} --format=c -Upostgres -d #{database_name}" run(command) end def database_exists?(database_name) runs?("PGPASSWORD='#{password}' psql -l -h #{host} | grep '#{database_name}'") end def drop_database(database_name) spawn("PGPASSWORD='#{password}' dropdb -h #{host} -U#{username} #{database_name}") end def create_database(database_name) spawn("PGPASSWORD='#{password}' createdb -U#{username} -h #{host} #{database_name}") end def cycle_database(database_name) drop_database(database_name) create_database(database_name) end def suffix /\.(dump|gpz)$/ end end end end
Version data entries
6 entries across 6 versions & 1 rubygems