# Passer de Heroku à une installation supportée

**URL:** https://meta.discourse.org/t/migrate-from-heroku-to-a-supported-installation/32868
**Category:** Sysadmins
**Tags:** how-to
**Created:** [Septembre 3, 2015, 2:28 UTC](https://meta.discourse.org/t/migrate-from-heroku-to-a-supported-installation/32868 "2015-09-03T14:28:37Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![kimpellikaan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kimpellikaan/32/116648_2.png) [@kimpellikaan](https://meta.discourse.org/u/kimpellikaan)
#### Post date: [Septembre 3, 2015, 2:28 UTC](https://meta.discourse.org/t/migrate-from-heroku-to-a-supported-installation/32868/1 "2015-09-03T14:28:37Z")

</div>

If you ever need to migrate away from Heroku to a currently supported infrastructure by discourse it can be quite troublesome.

We did the following to be able to create a backup which could thereafter be imported by discours’s hosted solution. These steps can also be used if you just want to migrate to your own cloud hosted instance.

## Get the data out of Heroku

There are 2 parts you need to backup:

- Database
- Images

Note: **Before you continue make sure the Heroku version is updated to the last version**

### Export the DB

To export the DB from Heroku to your development system follow the instructions here:

> **[Importing and Exporting Heroku Postgres Databases | Heroku Dev Center](https://devcenter.heroku.com/articles/heroku-postgres-import-export)**
>
> Learn how to export and import PostgreSQL databases.

You can also login to the dashboard and create and download a PG dump.

### Get the images

In our case we saved the images to AWS S3. To download all the images at once we used the AWS CLI.

1. First make sure you have the AWS CLI installed.  
[Getting started with the AWS CLI - AWS Command Line Interface](http://docs.aws.amazon.com/cli/latest/userguide/installing.html)
2. Use the S3 argument to download your images.  
[s3 — AWS CLI 2.34.57 Command Reference](http://docs.aws.amazon.com/cli/latest/reference/s3/index.html)

For example:

```
aws s3 cp /tmp/foo/ s3://bucket/ --recursive

```

## Build a new discourse instance

Create a new discourse instance by following the instructions:

> <https://github.com/discourse/discourse/blob/main/docs/INSTALL-cloud.md>

## Start the restore

Assuming that you have a working discourse instance and that the versions of both Heroku and the new cloud instance are the same (discourse versions) let’s start the import.

### Get your backups from your local system in the docker container.

To get your images and db from your local to the vps I prefer scp. You can also do this with an sftp client if that is your preference.

An example of the SCP command assuming that your public key is set:

```
scp /tmp/latest.dump root@xxx.xxx.xxx.xxx:/tmp

```

### Get the backups in the container

The Container has one volume mounted; `/var/discourse/shared/standalone/`

Copy the backups to this location and you can access them when your inside your container.

### Importing your backups

Before we can start importing we need to convert the **compressed pg dump** that Heroku gave us to an sql file.

Else you get these kinds of issues:

> <https://stackoverflow.com/questions/10852631/how-to-import-a-heroku-pg-dump-into-local-machine>

#### Convert Compressed pg dump

You need to enter the Docker container inside your vps. Thereafter we can convert the dump to an sql file.

Commands:

```
cd /var/discourse
sudo ./launcher enter app
 sudo -u postgres pg_restore -O -f /tmp/latest.sql /shared/latest.dump
exit
exit

```

Now you should have a file called latest.sql in you tmp folder.

#### Do the restore

Go to the following link and follow the instructions under the **Restore** header.

> [@Manually create and restore Discourse backups](https://meta.discourse.org/t/advanced-manual-method-of-manually-creating-and-restoring-discourse-backups/18273):
>
> As discussed [below](https://meta.discourse.org/t/advanced-manual-method-of-manually-creating-and-restoring-discourse-backups/18273/7), a warning for newbies: this is an advanced method! there is an automated, web UI way to restore from backups at /admin/backups which is so much easier. with the method below, no automatic backup is kept of the /var/discourse/containers/app.yml file which contains essential SMTP credentials and SSL customizations. Keep a copy of this offsite whenever you change it. If you are using digital ocean, keep frequent snapshots of your droplets - preferably before each time you run .…

#### Rebuild container

Discourse relays heavily on caching. This means we need to rebuild the container after the DB is restored. Outside your container in the root of your vps do:

```
cd /var/discourse
sudo ./launcher rebuild app

```

## Optional: Resetting your force\_hostname value

There is a good chance that you set the force\_hostname value to make sure all links are working correct. In the new environment this is no longer needed so you need to unset the value

```
cd /var/docker
sudo ./launcher enter app
su - discourse
bundle exec rails c
SiteSetting.force_hostname = “"
exit
exit
exit

```

Now you should be good to go! Create backups to be imported later or just let it run like this.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [Septembre 3, 2015, 9:19 UTC](https://meta.discourse.org/t/migrate-from-heroku-to-a-supported-installation/32868/2 "2015-09-03T21:19:01Z")

</div>

Wow this is super detailed thank you for putting it together!

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [Septembre 4, 2015, 3:47 UTC](https://meta.discourse.org/t/migrate-from-heroku-to-a-supported-installation/32868/3 "2015-09-04T03:47:29Z")

</div>

I wonder though, could you not enable daily backups to aws and use that? Or switch to a single dyno, do a manual backup from the admin interface and then use it?

---

<div class="post-metadata">

### Author: ![kimpellikaan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kimpellikaan/32/116648_2.png) [@kimpellikaan](https://meta.discourse.org/u/kimpellikaan)
#### Post date: [Septembre 4, 2015, 12:34 UTC](https://meta.discourse.org/t/migrate-from-heroku-to-a-supported-installation/32868/4 "2015-09-04T12:34:33Z")

</div>

@sam, heroku does not have pg\_dump installed on the instance. Because of this the backups don’t work at all on heroku.
