Restore a Discourse backup manually for development

You’ve got yourself a Discourse backup file and want to load it into your development database, without using the web UI, or potentially with a different database name. Cool!

This will assume you already have a Postgres database server running, and you’ve already run the createdb command if appropriate.

Restoring the backup manually is easy, you just need a couple extra SQL statements on the end to switch the schema over.

$ tar zxvf backup-file.tar.gz
# you now have the dump.sql and meta.json files
$ DATABASE=discourse_development
$ psql $DATABASE < dump.sql
$ psql $DATABASE <<END
DROP SCHEMA IF EXISTS backup CASCADE;
ALTER SCHEMA public RENAME TO backup;
ALTER SCHEMA restore RENAME TO public;
END
$ bundle exec rake db:migrate

Guide based off this post.

Last edited by @hugh 2024-05-29T06:22:16Z

Check documentPerform check on document:
7 Likes

got the memory error while trying to run the psql $DATABASE < dump.sql command:

ERROR: out of memory DETAIL: Cannot enlarge string buffer containing 0 bytes by 1328821374 more bytes.

is there any way to run the psql command on some part of the database, e.g. only on the tag-table so that one can delete some duplicated tags therein?


the problem is that I have a corrupted backup, which has duplicated tags. we need to restore the backup, because of some upload-lost during the site migration.

I need this in order to be able to do the restoration of that corrupted backup via UI (explained shortly here).