gitlab-omnibus restore issues ERRORs on missing role git and postgres

When restoring a backup made on gitlab-ce 7.8.4 in gitlab-omnibus 7.8.4 I get the following errors:

psql:/var/opt/gitlab/backups/db/database.sql:50: ERROR:  role "git" does not exist (59 occurences with different line no's)
psql:/var/opt/gitlab/backups/db/database.sql:2979: ERROR:  role "postgres" does not exist
psql:/var/opt/gitlab/backups/db/database.sql:2980: WARNING:  no privileges were granted for "public"

This is maybe not so easy to reproduce. In short, what I have done is:

  1. Cloned gitlab-ce 7-7-stable to one host, A, running Ubuntu 12.04 server 64-bit following 7-7-stable/doc/install/installation.md using apache2 rather than nginx.
  2. Used that installation for some time, creating some projects.
  3. Upgraded host A to gitlab-ce 7-8-stable following 7-8-stable/doc/update/7.7-to-7.8.md
  4. Created a backup on host A, following Create a backup of the GitLab system for the non omnibus case.
  5. Installed gitlab_7.8.4-omnibus-1_amd64.deb on another host, B, running Ubuntu 14.04 server 64-bit.
  6. Restored the backup from host A on host B, following Restoring an application backup

The restore issued:

$ sudo gitlab-ctl stop unicorn
ok: down: unicorn: 1s, normally up
$ sudo gitlab-ctl stop sidekiq
ok: down: sidekiq: 0s, normally up
$ sudo gitlab-rake gitlab:backup:restore BACKUP=1234567890
Unpacking backup ... done
Restoring database ... 
Restoring PostgreSQL database gitlabhq_production ... SET
SET
SET
SET
SET
CREATE EXTENSION
psql:/var/opt/gitlab/backups/db/database.sql:22: ERROR:  must be owner of extension plpgsql
SET
SET
SET
CREATE TABLE
psql:/var/opt/gitlab/backups/db/database.sql:50: ERROR:  role "git" does not exist
CREATE SEQUENCE
psql:/var/opt/gitlab/backups/db/database.sql:64: ERROR:  role "git" does not exist
ALTER SEQUENCE
CREATE TABLE
psql:/var/opt/gitlab/backups/db/database.sql:90: ERROR:  role "git" does not exist
CREATE SEQUENCE
psql:/var/opt/gitlab/backups/db/database.sql:104: ERROR:  role "git" does not exist
ALTER SEQUENCE
CREATE TABLE
psql:/var/opt/gitlab/backups/db/database.sql:126: ERROR:  role "git" does not exist
CREATE SEQUENCE
psql:/var/opt/gitlab/backups/db/database.sql:140: ERROR:  role "git" does not exist
ALTER SEQUENCE
CREATE TABLE
psql:/var/opt/gitlab/backups/db/database.sql:162: ERROR:  role "git" does not exist
CREATE SEQUENCE
psql:/var/opt/gitlab/backups/db/database.sql:176: ERROR:  role "git" does not exist
ALTER SEQUENCE
CREATE TABLE
psql:/var/opt/gitlab/backups/db/database.sql:203: ERROR:  role "git" does not exist
CREATE SEQUENCE
psql:/var/opt/gitlab/backups/db/database.sql:217: ERROR:  role "git" does not exist
ALTER SEQUENCE
CREATE TABLE
psql:/var/opt/gitlab/backups/db/database.sql:239: ERROR:  role "git" does not exist
CREATE SEQUENCE
psql:/var/opt/gitlab/backups/db/database.sql:253: ERROR:  role "git" does not exist
ALTER SEQUENCE
CREATE TABLE
psql:/var/opt/gitlab/backups/db/database.sql:276: ERROR:  role "git" does not exist
CREATE SEQUENCE
psql:/var/opt/gitlab/backups/db/database.sql:290: ERROR:  role "git" does not exist
ALTER SEQUENCE
CREATE TABLE
psql:/var/opt/gitlab/backups/db/database.sql:320: ERROR:  role "git" does not exist
CREATE SEQUENCE
psql:/var/opt/gitlab/backups/db/database.sql:334: ERROR:  role "git" does not exist
ALTER SEQUENCE
CREATE TABLE
psql:/var/opt/gitlab/backups/db/database.sql:359: ERROR:  role "git" does not exist
CREATE SEQUENCE
psql:/var/opt/gitlab/backups/db/database.sql:373: ERROR:  role "git" does not exist
ALTER SEQUENCE
CREATE TABLE
psql:/var/opt/gitlab/backups/db/database.sql:396: ERROR:  role "git" does not exist
CREATE SEQUENCE
psql:/var/opt/gitlab/backups/db/database.sql:410: ERROR:  role "git" does not exist
ALTER SEQUENCE
CREATE TABLE
psql:/var/opt/gitlab/backups/db/database.sql:433: ERROR:  role "git" does not exist
CREATE SEQUENCE
psql:/var/opt/gitlab/backups/db/database.sql:447: ERROR:  role "git" does not exist
ALTER SEQUENCE
CREATE TABLE
psql:/var/opt/gitlab/backups/db/database.sql:473: ERROR:  role "git" does not exist
CREATE SEQUENCE
psql:/var/opt/gitlab/backups/db/database.sql:487: ERROR:  role "git" does not exist
ALTER SEQUENCE
CREATE TABLE
psql:/var/opt/gitlab/backups/db/database.sql:511: ERROR:  role "git" does not exist
CREATE SEQUENCE
psql:/var/opt/gitlab/backups/db/database.sql:525: ERROR:  role "git" does not exist
ALTER SEQUENCE
CREATE TABLE
psql:/var/opt/gitlab/backups/db/database.sql:559: ERROR:  role "git" does not exist
CREATE SEQUENCE
psql:/var/opt/gitlab/backups/db/database.sql:573: ERROR:  role "git" does not exist
ALTER SEQUENCE
CREATE TABLE
psql:/var/opt/gitlab/backups/db/database.sql:599: ERROR:  role "git" does not exist
CREATE SEQUENCE
psql:/var/opt/gitlab/backups/db/database.sql:613: ERROR:  role "git" does not exist
ALTER SEQUENCE
CREATE TABLE
psql:/var/opt/gitlab/backups/db/database.sql:639: ERROR:  role "git" does not exist
CREATE SEQUENCE
psql:/var/opt/gitlab/backups/db/database.sql:653: ERROR:  role "git" does not exist
ALTER SEQUENCE
CREATE TABLE
psql:/var/opt/gitlab/backups/db/database.sql:683: ERROR:  role "git" does not exist
CREATE SEQUENCE
psql:/var/opt/gitlab/backups/db/database.sql:697: ERROR:  role "git" does not exist
ALTER SEQUENCE
CREATE TABLE
psql:/var/opt/gitlab/backups/db/database.sql:723: ERROR:  role "git" does not exist
CREATE SEQUENCE
psql:/var/opt/gitlab/backups/db/database.sql:737: ERROR:  role "git" does not exist
ALTER SEQUENCE
CREATE TABLE
psql:/var/opt/gitlab/backups/db/database.sql:763: ERROR:  role "git" does not exist
CREATE SEQUENCE
psql:/var/opt/gitlab/backups/db/database.sql:777: ERROR:  role "git" does not exist
ALTER SEQUENCE
CREATE TABLE
psql:/var/opt/gitlab/backups/db/database.sql:804: ERROR:  role "git" does not exist
CREATE SEQUENCE
psql:/var/opt/gitlab/backups/db/database.sql:818: ERROR:  role "git" does not exist
ALTER SEQUENCE
CREATE TABLE
psql:/var/opt/gitlab/backups/db/database.sql:860: ERROR:  role "git" does not exist
CREATE SEQUENCE
psql:/var/opt/gitlab/backups/db/database.sql:874: ERROR:  role "git" does not exist
ALTER SEQUENCE
CREATE TABLE
psql:/var/opt/gitlab/backups/db/database.sql:897: ERROR:  role "git" does not exist
CREATE SEQUENCE
psql:/var/opt/gitlab/backups/db/database.sql:911: ERROR:  role "git" does not exist
ALTER SEQUENCE
CREATE TABLE
psql:/var/opt/gitlab/backups/db/database.sql:929: ERROR:  role "git" does not exist
CREATE TABLE
psql:/var/opt/gitlab/backups/db/database.sql:948: ERROR:  role "git" does not exist
CREATE SEQUENCE
psql:/var/opt/gitlab/backups/db/database.sql:962: ERROR:  role "git" does not exist
ALTER SEQUENCE
CREATE TABLE
psql:/var/opt/gitlab/backups/db/database.sql:990: ERROR:  role "git" does not exist
CREATE SEQUENCE
psql:/var/opt/gitlab/backups/db/database.sql:1004: ERROR:  role "git" does not exist
ALTER SEQUENCE
CREATE TABLE
psql:/var/opt/gitlab/backups/db/database.sql:1029: ERROR:  role "git" does not exist
CREATE SEQUENCE
psql:/var/opt/gitlab/backups/db/database.sql:1043: ERROR:  role "git" does not exist
ALTER SEQUENCE
CREATE TABLE
psql:/var/opt/gitlab/backups/db/database.sql:1062: ERROR:  role "git" does not exist
CREATE SEQUENCE
psql:/var/opt/gitlab/backups/db/database.sql:1076: ERROR:  role "git" does not exist
ALTER SEQUENCE
CREATE TABLE
psql:/var/opt/gitlab/backups/db/database.sql:1138: ERROR:  role "git" does not exist
CREATE SEQUENCE
psql:/var/opt/gitlab/backups/db/database.sql:1152: ERROR:  role "git" does not exist
ALTER SEQUENCE
CREATE TABLE
psql:/var/opt/gitlab/backups/db/database.sql:1174: ERROR:  role "git" does not exist
CREATE SEQUENCE
psql:/var/opt/gitlab/backups/db/database.sql:1188: ERROR:  role "git" does not exist
ALTER SEQUENCE
CREATE TABLE
psql:/var/opt/gitlab/backups/db/database.sql:1216: ERROR:  role "git" does not exist
CREATE SEQUENCE
psql:/var/opt/gitlab/backups/db/database.sql:1230: ERROR:  role "git" does not exist
ALTER SEQUENCE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
 setval 
--------
      1
(1 row)

 setval 
--------
      1
(1 row)

 setval 
--------
      1
(1 row)

 setval 
--------
      1
(1 row)

 setval 
--------
     30
(1 row)

 setval 
--------
      1
(1 row)

 setval 
--------
      1
(1 row)

 setval 
--------
      4
(1 row)

 setval 
--------
      1
(1 row)

 setval 
--------
      1
(1 row)

 setval 
--------
      1
(1 row)

 setval 
--------
      5
(1 row)

 setval 
--------
      1
(1 row)

 setval 
--------
      1
(1 row)

 setval 
--------
      1
(1 row)

 setval 
--------
      2
(1 row)

 setval 
--------
      3
(1 row)

 setval 
--------
      1
(1 row)

 setval 
--------
      1
(1 row)

 setval 
--------
      1
(1 row)

 setval 
--------
      5
(1 row)

 setval 
--------
      1
(1 row)

 setval 
--------
      3
(1 row)

 setval 
--------
      1
(1 row)

 setval 
--------
      1
(1 row)

 setval 
--------
      1
(1 row)

 setval 
--------
      2
(1 row)

 setval 
--------
      1
(1 row)

 setval 
--------
      1
(1 row)

ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
psql:/var/opt/gitlab/backups/db/database.sql:2977: WARNING:  no privileges could be revoked for "public"
REVOKE
psql:/var/opt/gitlab/backups/db/database.sql:2978: ERROR:  role "postgres" does not exist
psql:/var/opt/gitlab/backups/db/database.sql:2979: ERROR:  role "postgres" does not exist
psql:/var/opt/gitlab/backups/db/database.sql:2980: WARNING:  no privileges were granted for "public"
GRANT
[DONE]
done
Restoring repositories ...
 * janne/proj1 ... [DONE]
 * janne/proj1.wiki ...  [DONE]
 * janne/proj2 ... [DONE]
 * janne/proj2.wiki ...  [DONE]
 * janne/proj3 ... [DONE]
 * janne/proj3.wiki ...  [DONE]
 * janne/proj4 ... [DONE]
 * janne/proj5 ... [DONE]
Put GitLab hooks in repositories dirs [DONE]
done
Restoring uploads ... 
done
This will rebuild an authorized_keys file.
You will lose any data stored in authorized_keys file.
Do you want to continue (yes/no)? yes

.Deleting tmp directories ... done
$

Sanitize and info on host A outputs:

$ cd /home/git/gitlab
$ sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production SANITIZE=true
Checking Environment ...

Git configured for git user? ... yes

Checking Environment ... Finished

Checking GitLab Shell ...

GitLab Shell version >= 2.5.4 ? ... OK (2.5.4)
Repo base directory exists? ... yes
Repo base directory is a symlink? ... no
Repo base owned by git:git? ... yes
Repo base access is drwxrws---? ... yes
Satellites access is drwxr-x---? ... yes
hooks directories in repos are links: ... 
2/1 ... ok
2/2 ... repository is empty
2/3 ... repository is empty
2/4 ... ok
2/5 ... ok
Running /home/git/gitlab-shell/bin/check
Check GitLab API access: OK
Check directories and files: 
	/home/git/repositories/: OK
	/home/git/.ssh/authorized_keys: OK
Test redis-cli executable: redis-cli 2.8.19
Send ping to redis server: PONG
gitlab-shell self-check successful

Checking GitLab Shell ... Finished

Checking Sidekiq ...

Running? ... yes
Number of Sidekiq processes ... 1

Checking Sidekiq ... Finished

Checking LDAP ...

LDAP is disabled in config/gitlab.yml

Checking LDAP ... Finished

Checking GitLab ...

Database config exists? ... yes
Database is SQLite ... no
All migrations up? ... yes
Database contains orphaned GroupMembers? ... no
GitLab config exists? ... yes
GitLab config outdated? ... no
Log directory writable? ... yes
Tmp directory writable? ... yes
Init script exists? ... yes
Init script up-to-date? ... yes
projects have namespace: ... 
2/1 ... yes
2/2 ... yes
2/3 ... yes
2/4 ... yes
2/5 ... yes
Projects have satellites? ... 
2/1 ... yes
2/2 ... can't create, repository is empty
2/3 ... can't create, repository is empty
2/4 ... yes
2/5 ... yes
Redis version >= 2.0.0? ... yes
Ruby version >= 2.0.0 ? ... yes (2.1.5)
Your git bin path is "/usr/local/bin/git"
Git version >= 1.7.10 ? ... yes (2.1.2)

Checking GitLab ... Finished

$ sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production

System information
System:		Ubuntu 12.04
Current User:	git
Using RVM:	no
Ruby Version:	2.1.5p273
Gem Version:	2.2.2
Bundler Version:1.8.2
Rake Version:	10.3.2
Sidekiq Version:3.3.0

GitLab information
Version:	7.8.4
Revision:	35ee444
Directory:	/home/git/gitlab
DB Adapter:	postgresql
URL:		https://my.domain/dir/gitlab
HTTP Clone URL:	https://my.domain/dir/gitlab/some-project.git
SSH Clone URL:	git@my.domain:some-project.git
Using LDAP:	no
Using Omniauth:	no

GitLab Shell
Version:	2.5.4
Repositories:	/home/git/repositories/
Hooks:		/home/git/gitlab-shell/hooks/
Git:		/usr/local/bin/git
$