Creating a duplicate of production environment

Just to close the loop. Steps I followed.

On Production:

Get latest backup from /var/discourse/shared/standalone/backups/default

On New/Dev instance :

mkdir /srv/discourse
git clone https://github.com/discourse/discourse_docker.git /srv/discourse
cd /srv/discourse
# If you need a specific commit, do:
# git reset --hard git_commit_hash_goes_here

Copy the app.yml from your production server to new/dev instance. Update app.yml

new_hostname=$(hostname -f)
sudo sed -i "s/^  DISCOURSE_HOSTNAME:.*$/  DISCOURSE_HOSTNAME: $new_hostname/g" containers/app.yml
# If you need to duplicate a specific version of discourse, use the git commit hash, otherwise use the branch name. Below we are using stable branch
sudo sed -i 's/^  #version: .*$/  version: stable/g' containers/app.yml
sudo sed -i "s/^  DISCOURSE_DEVELOPER_EMAILS: .*$/  DISCOURSE_DEVELOPER_EMAILS: 'sysadmins@yourcompany.com'/g" containers/app.yml

Bootstrap, start the app container

sudo ./launcher bootstrap app
sudo ./launcher start app

Copy your backup to restore location

sudo mkdir /var/discourse/shared/standalone/backups/default -p
sudo cp /tmp/discourse-backup/lgtm* /var/discourse/shared/standalone/backups/default

Now we run commands in the container to prepare, and restore the backup, and fix the permissions.

backup=$(basename /var/discourse/shared/standalone/backups/default/*)
sudo /usr/bin/docker exec -i app discourse restore $backup
sudo /usr/bin/docker exec -i app chown discourse.www-data /var/www/discourse/public/backups/default/ -R 

If you get an error about SiteSettings not allowing restore. (I think it’s older version of discourse that needs this)

sudo /usr/bin/docker exec -i app rails runner "SiteSetting.allow_restore = true"

I tried using the Advanced, manual method of manually creating and restoring Discourse backups method for my restore, but it failed with rake db:migrate creating an empty db. Might work for you, I did not test further.

6 Likes