16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/rehabilitate/plugins/postgresql.rb', line 16
def restore(options)
options._backup_files.collect! do |backup_file|
log "Restoring database #{options.database}"
drop_table_sql = File.join(options.tmp, 'droptables.sql')
log %[psql -t -h #{options.host} -U #{options.user} -d #{options.database} -c "SELECT 'DROP TABLE ' || n.nspname || '.' || c.relname || ' CASCADE;' FROM pg_catalog.pg_class AS c LEFT JOIN pg_catalog.pg_namespace AS n ON n.oid = c.relnamespace WHERE relkind = 'r' AND n.nspname NOT IN ('pg_catalog', 'pg_toast') AND pg_catalog.pg_table_is_visible(c.oid)" > #{drop_table_sql} ]
log %x[psql -t -h #{options.host} -U #{options.user} -d #{options.database} -c "SELECT 'DROP TABLE ' || n.nspname || '.' || c.relname || ' CASCADE;' FROM pg_catalog.pg_class AS c LEFT JOIN pg_catalog.pg_namespace AS n ON n.oid = c.relnamespace WHERE relkind = 'r' AND n.nspname NOT IN ('pg_catalog', 'pg_toast') AND pg_catalog.pg_table_is_visible(c.oid)" > #{drop_table_sql} ]
log %[psql -h #{options.host} -U #{options.user} #{options.database} < #{drop_table_sql} #{"> /dev/null 2>&1" unless options.debug} ] unless $? == 256
log %x[psql -h #{options.host} -U #{options.user} #{options.database} < #{drop_table_sql} #{"> /dev/null 2>&1" unless options.debug} ] unless $? == 256
log %[psql -h #{options.host} -U #{options.user} #{options.database} < #{backup_file} #{"> /dev/null 2>&1" unless options.debug} ] unless $? == 256
log %x[psql -h #{options.host} -U #{options.user} #{options.database} < #{backup_file} #{"> /dev/null 2>&1" unless options.debug} ] unless $? == 256
options._tmp_files << drop_table_sql
options._failure = true if $? == 256
end
end
|