Backup restoration fails

I’m having the following problem. I’ve been running a Discourse forum for over 10 years, and since I haven’t been able to install updates for some time now, I wanted to set up a new server:

Old server is running: 3.4.0.beta4-dev

New server: Latest version

The backup is already 673.2 MB in size as a .gz file, excluding uploads

Unfortunately, the restoration keeps aborting. The log file contains this error

[2026-06-16 07:54:52] ERROR:  could not create unique index “index_incoming_referers_on_path_and_incoming_domain_id”
[2026-06-16 07:54:52] DETAIL:  Key (path, incoming_domain_id)=(//, 5) is duplicated.
[2026-06-16 07:54:52] EXCEPTION: psql failed: DETAIL:  Key (path, incoming_domain_id)=(//, 5) is duplicated.

[2026-06-16 07:54:52] /var/www/discourse/lib/backup_restore/database_restorer.rb:93:in 'BackupRestore::DatabaseRestorer#restore_dump'
/var/www/discourse/lib/backup_restore/database_restorer.rb:26:in ‘BackupRestore::DatabaseRestorer#restore’
/var/www/discourse/lib/backup_restore/restorer.rb:61:in 'BackupRestore::Restorer#run'
/var/www/discourse/script/spawn_backup_restore.rb:20:in ‘Object#restore’
/var/www/discourse/script/spawn_backup_restore.rb:33:in ‘block in ’
/var/www/discourse/script/spawn_backup_restore.rb:4:in 'Kernel#fork'
/var/www/discourse/script/spawn_backup_restore.rb:4:in ‘’
[2026-06-16 07:54:52] Trying to rollback...

What can I do to fix this problem and not lose the last 10 years of data?

Thank you in advance for any help!

Hello and wow, welcome back after 9 years!

Pretty cool to see such a long running forum.

I think this is the same index problem as talked about here: Can't restore due to corrupt indexes (with some clues on how to deal with corrupt indexes)

It’s something like this:

The incoming_referers table tracks the URL paths that referred visitors to your forum. It has a unique index, meaning no two rows can have the same path + domain combination.

Your database has two rows with path='//' and incoming_domain_id=5. When it tries to rebuild this unique index during restore, it finds the duplicate and aborts the entire restore transaction.

So you’ll need to find and cleanup that duplicate incoming_referers and then make a new backup to restore on the new server.

I found this topic with instructions that might help you

Thank you very much for the quick response; I’ll give that a try!

(post deleted by author)

Sorry to bother you, but I seem to be doing something wrong—after running the command “discourse=# select * from incoming_referers where path LIKE ‘%/search/’ ORDER BY incoming_domain_id;”, I’m getting a syntax error.

Did you type “discourse=#”? If so, try again without that

Then I get the error message “bash: syntax error near unexpected token `from’”

For reference, I’m currently at: root@community-app:/var/www/discourse#

Ah , you’re not in the DB yet.

First run psql -U discourse discourse (I think)

And then the prompt should change to discourse=#

Okay, I’ve now also installed “apt install postgresql-client-common.” However, I’m still getting the error “Error: You must install at least one postgresql-client- package.”

Okay that I don’t know.

Maybe try directly via the rails console then: rails c

with

ActiveRecord::Base.connection.execute(<<~SQL)
  SELECT id, path, incoming_domain_id 
  FROM incoming_referers 
  WHERE path = '//' 
  AND incoming_domain_id = 5
SQL

That may give you the same without going through the database.

Does that work?

I’m really, really sorry for acting so stupid.

I’ve now installed Rails, and it seems to have worked. I also ran it with “rails c”. That seems to work too, but when I enter the command, it looks like this:

“root@community:/var/discourse# ActiveRecord::Base.connection.execute(<<~SQL)
-bash: syntax error near unexpected token `<<’
root@community:/var/discourse# SELECT id, path, incoming_domain_id
SELECT: command not found
root@community:/var/discourse# FROM incoming_referers
FROM: command not found
root@community:/var/discourse# WHERE path = ‘//’
WHERE: command not found
root@community:/var/discourse# AND incoming_domain_id = 5
AND: command not found
root@community:/var/discourse# SQL”

Don’t worry, maybe my instructions are just not that good :slight_smile:

I will say I’m confused when you say you just installed Rails and can’t access your DB. Maybe it’s all different because it’s an older version, but I think I’m out of my depth now too.

Anyway, once you’re in rails, the prompt should be something different, so from your output, it looks like you aren’t in the rails console yet.

I don’t even think you’re in the actual container. Have you done ./launcher enter app?