PostgreSQL database restoration problem

Created by: andrewwutw

I found PostgreSQL database restore procedure may have bug. In file:

lib/backup/database.rb

https://github.com/gitlabhq/gitlabhq/blob/master/lib/backup/database.rb

PostgreSQL database is dumped by executing pg_dump:

system("pg_dump #{config['database']} > #{db_file_name}")

According to PostgreSQL document, pg_dump outputs a plain-text SQL script file by default:

http://www.postgresql.org/docs/8.4/static/app-pgdump.html

Output a plain-text SQL script file (the default).

And PostgreSQL database is restored by executing pg_restore:

system("pg_restore #{config['database']} #{db_file_name}")

But according to PostgreSQL document, pg_restore can't restore a plain-text dump file:

http://www.postgresql.org/docs/9.2/static/app-pgrestore.html

pg_restore is a utility for restoring a PostgreSQL database from an archive created by pg_dump in one of the non-plain-text formats.

I tried to replace the pg_restore command line to psql like this:

system("psql #{config['database']} -f #{db_file_name}")

Then run:

sudo -u git -H bundle exec rake gitlab:backup:restore RAILS_ENV=production

The restore procedure seems to work, although it prints some warning/error messages. And GitLab database seems to be restored.

This issue should be the cause of #4055 (closed) .

Any ideas?