# Set up a staging server

**URL:** https://meta.discourse.org/t/set-up-a-staging-server/225951
**Category:** Sysadmins
**Tags:** how-to
**Created:** [May 3, 2022, 5:24am UTC](https://meta.discourse.org/t/set-up-a-staging-server/225951 "2022-05-03T05:24:53Z")
**Posts on this page:** 13
**Page:** 2

<div class="post-metadata">

### Author: ![nathank](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nathank/32/290039_2.png) [@nathank](https://meta.discourse.org/u/nathank)
#### Post date: [September 9, 2023, 8:54am UTC](https://meta.discourse.org/t/set-up-a-staging-server/225951/23 "2023-09-09T08:54:53Z")

</div>

That is kind of the point of the setup above; it is super useful to have the staging server pointing at the same bucket as this makes it much easier to keep them in sync.

However, you don’t want it contributing any backups automatically (or deleting any) - hence these is turned off by these settings:

> [@nathank](#):
>
> ```plaintext
> DISCOURSE_AUTOMATIC_BACKUPS_ENABLED: false
> DISCOURSE_S3_DISABLE_CLEANUP: true
> 
> ```

Agree that the CDN needs to be turned off for your staging site. I haven’t messed with that myself, but once you work how to do that please do update / add to [the wiki in the OP](https://meta.discourse.org/t/set-up-a-staging-server/225951/1).

---

<div class="post-metadata">

### Author: ![Octoberon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/octoberon/32/288382_2.png) [@Octoberon](https://meta.discourse.org/u/Octoberon)
#### Post date: [September 9, 2023, 9:09am UTC](https://meta.discourse.org/t/set-up-a-staging-server/225951/24 "2023-09-09T09:09:50Z")

</div>

Thanks, Nathan. I saw mention of S3 backups making things easier but a backup is different to the site assets so I wasn’t sure.

I’ve already turned off backups and emails so all good there. I’ll get on with pointing the staging server to the existing bucket and make sure it isn’t using the CDN.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [September 9, 2023, 2:17pm UTC](https://meta.discourse.org/t/set-up-a-staging-server/225951/25 "2023-09-09T14:17:34Z")

</div>

Sharing backups is really nice because it makes it easy to copy your production database to staging.

---

<div class="post-metadata">

### Author: ![Richie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/richie/32/115110_2.png) [@Richie](https://meta.discourse.org/u/Richie)
#### Post date: [February 21, 2024, 1:20pm UTC](https://meta.discourse.org/t/set-up-a-staging-server/225951/26 "2024-02-21T13:20:27Z")

</div>

I plan to create a mirror of my production Discourse by using [the rsync method](https://meta.discourse.org/t/move-a-discourse-site-to-another-vps-with-rsync/43812).

I have a couple of other web sites which integrate with Discourse, so having the dev/test versions of those sites being able to hit and interact with a dev/test/staging version of Discourse would be _ideal_.

Therefore I would only power it on when needed, and I would restore a database backup of my PROD on to my STAGING periodically - not daily and maybe as little as once per month.

If I do this, how do I stop it changing some settings back when I do the database restore? 🤔

These for example, would be invaluable:

> [@nathank](#):
>
> However, you don’t want it contributing any backups automatically (or deleting any) - hence these is turned off by these settings:
> 
> > [@nathank](#):
> >
> > ```plaintext
> > DISCOURSE_AUTOMATIC_BACKUPS_ENABLED: false
> > DISCOURSE_S3_DISABLE_CLEANUP: true
> > 
> > ```

Is there a way I could restore a database backup and then maybe manually apply some settings before starting Discourse? Any other ideas, suggestions, gotchas? 🤔

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [February 21, 2024, 2:01pm UTC](https://meta.discourse.org/t/set-up-a-staging-server/225951/27 "2024-02-21T14:01:32Z")

</div>

If you keep backups on S3 and configure that via ENV variables, then you can pretty easily spin up a new site that can restore that backup. Just spin up a new VM, clone discourse, copy the yml, rebuild and restore. You can override settings in the database with ENV variables as in the quote in your post.

---

<div class="post-metadata">

### Author: ![Richie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/richie/32/115110_2.png) [@Richie](https://meta.discourse.org/u/Richie)
#### Post date: [February 21, 2024, 4:15pm UTC](https://meta.discourse.org/t/set-up-a-staging-server/225951/28 "2024-02-21T16:15:06Z")

</div>

> [@pfaffman](#):
>
> You can override settings in the database with ENV variables

Perfect, it sounds almost too easy 😃

---

<div class="post-metadata">

### Author: ![denvergeeks](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/denvergeeks/32/327671_2.png) [@denvergeeks](https://meta.discourse.org/u/denvergeeks)
#### Post date: [March 5, 2024, 8:46pm UTC](https://meta.discourse.org/t/set-up-a-staging-server/225951/29 "2024-03-05T20:46:17Z")

</div>

Am I missing a step? I’m pretty sure this worked a year ago or so. But now, while it does populate, it doesn’t add any Topics or posts beyond the **About** the Category… has something changed?

> [@nathank](#):
>
> If what you want is a test server to see what Discourse is like, though, you might want to check things out with some fake data, and if you do, you can do this:
> 
> ```plaintext
> ./launcher enter app
> ALLOW_DEV_POPULATE=1 bundle install
> ALLOW_DEV_POPULATE=1 rake dev:populate
> 
> ```
> 
> This will seed your forum with some fake data so that you can see what things look like with whatever themes and plugins you want. If you haven’t started your forum yet, this will give you some idea what things are likely to look like.

 ![Screenshot 2024-03-05 134114](https://global.discourse-cdn.com/meta/original/4X/2/2/7/227e5414cb59eab50875b3c54f0a7fb67891637f.png)

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [March 6, 2024, 4:21pm UTC](https://meta.discourse.org/t/set-up-a-staging-server/225951/30 "2024-03-06T16:21:46Z")

</div>

> [@denvergeeks](#):
>
> But now, while it does populate, it doesn’t add any Topics or posts beyond the **About** the Category… has something changed?

When I tried it just now, it created group and user records, but when creating categories failed with

```plaintext
ActiveRecord::RecordInvalid: Validation failed: Category Name has already been taken (ActiveRecord::RecordInvalid)

```

It seems like it should be smart enough not to try to create a category with an existing name.

Mine was not an empty site, however. There is also a `dev:repopulate` task, which first wipes the database.

---

<div class="post-metadata">

### Author: ![denvergeeks](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/denvergeeks/32/327671_2.png) [@denvergeeks](https://meta.discourse.org/u/denvergeeks)
#### Post date: [March 6, 2024, 5:47pm UTC](https://meta.discourse.org/t/set-up-a-staging-server/225951/31 "2024-03-06T17:47:07Z")

</div>

Thank you Jay! Here’s a screen showing what I tried… It looks like I need to be in “development environment”. How do I enter that?

 ![Screenshot 2024-03-06 104401](https://global.discourse-cdn.com/meta/original/4X/0/2/9/02932214955134b6c7aa5f626c9600459964db6a.png)

---

<div class="post-metadata">

### Author: ![denvergeeks](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/denvergeeks/32/327671_2.png) [@denvergeeks](https://meta.discourse.org/u/denvergeeks)
#### Post date: [March 7, 2024, 4:59am UTC](https://meta.discourse.org/t/set-up-a-staging-server/225951/32 "2024-03-07T04:59:09Z")

</div>

I ended up restoring an old backup from one of my discourse instances where I had previously used this method to populate. I had to do [this](https://meta.discourse.org/t/after-the-update-the-site-did-not-open-and-the-backup-database-was-not-loaded/295786/5), but it worked.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [March 7, 2024, 1:41pm UTC](https://meta.discourse.org/t/set-up-a-staging-server/225951/33 "2024-03-07T13:41:59Z")

</div>

There’s a thing you have to do to be able to drop the database. If you do the db:drop rake task it’ll tell you what it is. So I guess you’d need to `sv stop unicorn` and then drop, create, and migrate the database before running the task. Or that’s the next thing I would try, but you’ve got another solution…

---

<div class="post-metadata">

### Author: ![HAWK](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hawk/32/86627_2.png) [@HAWK](https://meta.discourse.org/u/HAWK)
#### Post date: [July 15, 2024, 11:37pm UTC](https://meta.discourse.org/t/set-up-a-staging-server/225951/34 "2024-07-15T23:37:39Z")

</div>

14 posts were split to a new topic: [Change server to a 2-container setup](https://meta.discourse.org/t/change-server-to-a-2-container-setup/316424)

---

<div class="post-metadata">

### Author: ![manuel](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/manuel/32/468169_2.png) [@manuel](https://meta.discourse.org/u/manuel)
#### Post date: [November 30, 2024, 11:12am UTC](https://meta.discourse.org/t/set-up-a-staging-server/225951/35 "2024-11-30T11:12:02Z")

</div>

I’m trying to seed test data on my staging server, but I get an error:

```plaintext
rake aborted!
Database commands are only supported in development environment

```

This is on a multisite setup, so the commands I’m running are:

```plaintext
./launcher enter web_only
ALLOW_DEV_POPULATE=1 bundle install
RAILS_DB=instance-x ALLOW_DEV_POPULATE=1 rake dev:populate

```

Which I’ve been using without issues so far, but now I get this error. Can I set an environment variable to allow database commands in production?

[Previous page](https://meta.discourse.org/t/set-up-a-staging-server/225951.md?page=1)
