# Creating a duplicate of production environment

**URL:** https://meta.discourse.org/t/creating-a-duplicate-of-production-environment/61966
**Category:** Self-hosting
**Created:** [02.Май.2017 15:38:05 UTC](https://meta.discourse.org/t/creating-a-duplicate-of-production-environment/61966 "2017-05-02T15:38:05Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![Henti\_Smith](https://avatars.discourse-cdn.com/v4/letter/h/ebca7d/32.png) [@Henti\_Smith](https://meta.discourse.org/u/Henti_Smith)
#### Post date: [02.Май.2017 15:38:05 UTC](https://meta.discourse.org/t/creating-a-duplicate-of-production-environment/61966/1 "2017-05-02T15:38:05Z")

</div>

I’m desperately trying to work out how to create a duplicate of our production system to allow testing of upgrades etc before taking it live. I’m hoping there is an easily reproducible set of steps to “export” the production system and then “import” into a new clear server.

I’ve looked at a number of different threads but nothing seem to cover this.

Is there a set of steps to duplicate a production system onto another machine with all data/attachements/etc in place ?

Regards  
Henti

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [02.Май.2017 15:42:24 UTC](https://meta.discourse.org/t/creating-a-duplicate-of-production-environment/61966/2 "2017-05-02T15:42:24Z")

</div>

> [@Henti\_Smith](#):
>
> Is there a set of steps to duplicate a production system onto another machine with all data/attachements/etc in place ?

Download a backup from production and restore on staging.

---

<div class="post-metadata">

### Author: ![JagWaugh](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jagwaugh/32/69335_2.png) [@JagWaugh](https://meta.discourse.org/u/JagWaugh)
#### Post date: [02.Май.2017 15:51:06 UTC](https://meta.discourse.org/t/creating-a-duplicate-of-production-environment/61966/3 "2017-05-02T15:51:06Z")

</div>

It’s pretty simple. Off the top of my head:

Create your sandbox, install discourse.  
Decide if you want mail (you don’t really need it if you’re just testing how to do “stuff”)  
Fudge app.yml so mail won’t go out.  
Download a backup from live, restore.  
Restart.  
Check it works.  
Clean up the .db ([https://meta.discourse.org/t/disk-space-usage-by-postgres/61137/4](https://meta.discourse.org/t/disk-space-usage-by-postgres/61137/4))  
Have at it.

EDIT: My sandbox is just for checking software and such, so I don’t have outgoing mail. In fact I deliberately mangled all the entries in app.yml so that it would never send mail (and I disabled all outgoing).

---

<div class="post-metadata">

### Author: ![cpradio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cpradio/32/4970_2.png) [@cpradio](https://meta.discourse.org/u/cpradio)
#### Post date: [02.Май.2017 15:53:15 UTC](https://meta.discourse.org/t/creating-a-duplicate-of-production-environment/61966/4 "2017-05-02T15:53:15Z")

</div>

> [@JagWaugh](#):
>
> Download a backup from live, restore.  
> Restart.  
> Check it works

I think you may want to run a [remap domain](https://meta.discourse.org/t/change-the-domain-name-or-rename-my-discourse/16098) in there too. That way all of the links do not go out to Production.

---

<div class="post-metadata">

### Author: ![Henti\_Smith](https://avatars.discourse-cdn.com/v4/letter/h/ebca7d/32.png) [@Henti\_Smith](https://meta.discourse.org/u/Henti_Smith)
#### Post date: [02.Май.2017 16:02:11 UTC](https://meta.discourse.org/t/creating-a-duplicate-of-production-environment/61966/5 "2017-05-02T16:02:11Z")

</div>

Hi Andrew,

I originally thought that was the correct way, but I could not get past step 1. My installation of discourse fails and unfortunately, nobody seems to be able to assist with that.

[https://meta.discourse.org/t/failure-when-trying-to-install-older-version-of-discourse/61722](https://meta.discourse.org/t/failure-when-trying-to-install-older-version-of-discourse/61722)

I was hoping it’s the wrong process and there is a different way to do it.

Thank you for the information.

Regards  
Henti

---

<div class="post-metadata">

### Author: ![JagWaugh](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jagwaugh/32/69335_2.png) [@JagWaugh](https://meta.discourse.org/u/JagWaugh)
#### Post date: [02.Май.2017 16:10:47 UTC](https://meta.discourse.org/t/creating-a-duplicate-of-production-environment/61966/6 "2017-05-02T16:10:47Z")

</div>

I think you could do it by changing git head, but I wasn’t smart enough for that. In my case I was close enough to the live site that the restore ran.

Have you seen this:

> [@How do you install an earlier version of Discourse?](https://meta.discourse.org/t/how-do-you-install-an-earlier-version-of-discourse/31930/2):
>
> There should be a version key in your app.yml file. #version: tests-passed Remove the # and change test-passed to the version you want to use; e.g. v1.3.4. [Tags · discourse/discourse · GitHub](https://github.com/discourse/discourse/tags) shows the available version strings.

---

<div class="post-metadata">

### Author: ![Henti\_Smith](https://avatars.discourse-cdn.com/v4/letter/h/ebca7d/32.png) [@Henti\_Smith](https://meta.discourse.org/u/Henti_Smith)
#### Post date: [03.Май.2017 07:56:48 UTC](https://meta.discourse.org/t/creating-a-duplicate-of-production-environment/61966/7 "2017-05-03T07:56:48Z")

</div>

That is the process I tried.

I’ll continue trying to get that working today. Thanks again for all the assistance.

---

<div class="post-metadata">

### Author: ![Henti\_Smith](https://avatars.discourse-cdn.com/v4/letter/h/ebca7d/32.png) [@Henti\_Smith](https://meta.discourse.org/u/Henti_Smith)
#### Post date: [03.Май.2017 10:05:10 UTC](https://meta.discourse.org/t/creating-a-duplicate-of-production-environment/61966/8 "2017-05-03T10:05:10Z")

</div>

Resolved the problem.

I had the failed data in /var/discourse that I didn’t know I needed to clean up.

---

<div class="post-metadata">

### Author: ![Henti\_Smith](https://avatars.discourse-cdn.com/v4/letter/h/ebca7d/32.png) [@Henti\_Smith](https://meta.discourse.org/u/Henti_Smith)
#### Post date: [19.Май.2017 14:34:54 UTC](https://meta.discourse.org/t/creating-a-duplicate-of-production-environment/61966/9 "2017-05-19T14:34:54Z")

</div>

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 [Manually create and restore Discourse backups](https://meta.discourse.org/t/advanced-manual-method-of-manually-creating-and-restoring-discourse-backups/18273) method for my restore, but it failed with `rake db:migrate` creating an empty db. Might work for you, I did not test further.

---

<div class="post-metadata">

### Author: ![Henti\_Smith](https://avatars.discourse-cdn.com/v4/letter/h/ebca7d/32.png) [@Henti\_Smith](https://meta.discourse.org/u/Henti_Smith)
#### Post date: [24.Май.2017 13:08:24 UTC](https://meta.discourse.org/t/creating-a-duplicate-of-production-environment/61966/10 "2017-05-24T13:08:24Z")

</div>

Slight update.

Replacing the DISCOURSE\_HOSTNAME with $(hostname) bit me in the arse .. I didn’t realise it’s used for url generation, so make sure it’s the url external users will be seeing if you use proxy/load balancers.

H

---

<div class="post-metadata">

### Author: ![keith1](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/keith1/32/178982_2.png) [@keith1](https://meta.discourse.org/u/keith1)
#### Post date: [07.Январь.2019 02:22:40 UTC](https://meta.discourse.org/t/creating-a-duplicate-of-production-environment/61966/11 "2019-01-07T02:22:40Z")

</div>

I went about this in a different, although slightly uglier way - I cloned my entire droplet on DigitalOcean, then logged into the droplet and disabled all of the ssl/https settings in the app.yml. This at least gave me a clone of my community content to screw with settings on.

I have no elegant way to migrate changes from my test server to the live server except by manually repeating, so this is still total amateur hour, but it at least let’s me explore without breaking the live server.

---

<div class="post-metadata">

### Author: ![kimardenmiller](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kimardenmiller/32/119631_2.png) [@kimardenmiller](https://meta.discourse.org/u/kimardenmiller)
#### Post date: [26.Январь.2019 22:16:15 UTC](https://meta.discourse.org/t/creating-a-duplicate-of-production-environment/61966/12 "2019-01-26T22:16:15Z")

</div>

> [@Falco](#):
>
> Download a backup from production and restore on staging.

Took your approach. Thanks. A quick question: I’ve backed up a production instance and restored it to a local Mac instance for dev, but resolving to localhost:3000 is incomplete. e.g. My logo sits at `http://localhost:3000/uploads` but Discourse is looking in `http://localhost/uploads`. I see talk of editing my app.yml, but don’t see one inside my discourse directory. Is there something I’m missing here?

---

<div class="post-metadata">

### Author: ![sau226](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sau226/32/302324_2.png) [@sau226](https://meta.discourse.org/u/sau226)
#### Post date: [27.Январь.2019 08:27:10 UTC](https://meta.discourse.org/t/creating-a-duplicate-of-production-environment/61966/13 "2019-01-27T08:27:10Z")

</div>

Try running the below in a rails console (probably `RAILS_ENV=development bundle exec rails c` or `bundle exec rails c`)

`SiteSetting.port = "3000"`

It’s a hidden site setting if I remember correctly which is why it doesn’t show up in the settings panel.

---

<div class="post-metadata">

### Author: ![kimardenmiller](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kimardenmiller/32/119631_2.png) [@kimardenmiller](https://meta.discourse.org/u/kimardenmiller)
#### Post date: [27.Январь.2019 18:32:10 UTC](https://meta.discourse.org/t/creating-a-duplicate-of-production-environment/61966/14 "2019-01-27T18:32:10Z")

</div>

That worked. Thanks.

I’ve set everything up with a local Rails install vs a local Docker container. Looking at so many examples of local Docker containers I’m wondering, did I make the wrong choice? Does it matter at this point, or will I eventually wish I’m in a Docker container to better mirror my DigitalOcean install?

---

<div class="post-metadata">

### Author: ![sau226](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sau226/32/302324_2.png) [@sau226](https://meta.discourse.org/u/sau226)
#### Post date: [23.Февраль.2019 15:14:12 UTC](https://meta.discourse.org/t/creating-a-duplicate-of-production-environment/61966/15 "2019-02-23T15:14:12Z")

</div>

Personally I’d go for the development environment but create a VM with a production style install (if you have the resources to do so).

That way you can test out your changes and work in a development environment. You can then use the production style container to test out your changes in a prod like environment (sometimes the local Rails install suppresses some errors or causes strange behaviour) and get the best of both worlds.

---

<div class="post-metadata">

### Author: ![kimardenmiller](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kimardenmiller/32/119631_2.png) [@kimardenmiller](https://meta.discourse.org/u/kimardenmiller)
#### Post date: [23.Февраль.2019 19:25:08 UTC](https://meta.discourse.org/t/creating-a-duplicate-of-production-environment/61966/16 "2019-02-23T19:25:08Z")

</div>

Thanks for that feedback. Makes sense.

Are all options for hosting a Docker container paid options, regardless of traffic? I’m used to using Heroku to stage Rails sites at no cost, but the Docker containers are new to me.

Looks as if Heroku supports Docker, but seems the Community recommends Digital Ocean, which I assume does not have a free tier.

---

<div class="post-metadata">

### Author: ![sau226](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sau226/32/302324_2.png) [@sau226](https://meta.discourse.org/u/sau226)
#### Post date: [24.Февраль.2019 06:21:34 UTC](https://meta.discourse.org/t/creating-a-duplicate-of-production-environment/61966/17 "2019-02-24T06:21:34Z")

</div>

Theoretically if you don’t mind having a private dev instance (i.e. it doesn’t allow access from the internet but can be accessed from the network your PC lives at) just run a VM using virtualbox or somthing similar with a bridged IP. Install ubuntu, set up remote root login and you should be OK to follow the production install guide.

The only thing you’d need to pay for is the internet connection that you probably already have and the power for the computer used. There are no server costs related to running your own Ubuntu Server in a VM that you control on your PC.

---

<div class="post-metadata">

### Author: ![kimardenmiller](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kimardenmiller/32/119631_2.png) [@kimardenmiller](https://meta.discourse.org/u/kimardenmiller)
#### Post date: [24.Февраль.2019 18:55:28 UTC](https://meta.discourse.org/t/creating-a-duplicate-of-production-environment/61966/18 "2019-02-24T18:55:28Z")

</div>

Now I’m wondering if we should just add a Droplet to our DigitalOcean account for a _staging_ instance at $5 / month. Is the cleanest, simplest approach just a matter of spinning up another Droplet inside the same DigitalOcean account which can be accessed at _[staging.ourdomain.org](http://staging.ourdomain.org)_? I see posts about running two instances inside a single Droplet. Is there any reason to do that other than cost?

---

<div class="post-metadata">

### Author: ![mreach](https://avatars.discourse-cdn.com/v4/letter/m/9d8465/32.png) [@mreach](https://meta.discourse.org/u/mreach)
#### Post date: [02.Ноябрь.2019 22:28:30 UTC](https://meta.discourse.org/t/creating-a-duplicate-of-production-environment/61966/19 "2019-11-02T22:28:30Z")

</div>

Это довольно важный пост, но не могли бы вы также предоставить рекомендации и инструкции по процессам, в которых не используется система резервного копирования? Я обнаружил, что встроенная система резервного копирования, похоже, не может работать при использовании внешнего сервера базы данных. В моём конкретном случае я хочу взять рабочую установку Discourse с отдельным сервером базы данных и развернуть её на тестовом сервере, где база данных интегрирована в Docker-окружение.

Как только я добьюсь успеха, я опубликую свои выводы и шаги, которые предпринял, но считаю, что этот вопрос крайне важен для данной темы.

---

<div class="post-metadata">

### Author: ![Remah](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/remah/32/70590_2.png) [@Remah](https://meta.discourse.org/u/Remah)
#### Post date: [02.Ноябрь.2019 23:22:21 UTC](https://meta.discourse.org/t/creating-a-duplicate-of-production-environment/61966/20 "2019-11-02T23:22:21Z")

</div>

Я не думаю, что ваш вопрос относится к этому разделу, особенно учитывая, что это маловероятный сценарий для подавляющего большинства разработчиков. То есть, большинству разработчиков не потребуется дублировать производственную среду за пределами официально поддерживаемой установки, которая является золотым стандартом для воспроизведения ошибок.Кроме того, вы фактически засоряете этот форум своим вопросом, поскольку будете дублировать решение вашей проблемы по адресу [Pg\_dump backup failure for remote pgsql - port & version differentials; what options exist?](https://meta.discourse.org/t/pg-dump-backup-failure-for-remote-pgsql-port-version-differentials-what-options-exist/132453?u=remah)

[Следующая страница](https://meta.discourse.org/t/creating-a-duplicate-of-production-environment/61966.md?page=2)
