DEV Community

Michiel Sikkes for Firmhouse

Posted on • Originally published at michielsikkes.com on

Upgrading an existing Intercity installation to the new installer

Two days ago, I posted about the updated and simpler installation method I shipped into Intercity's master branch: Updated installing Intercity to a single command. The new command works great on a fresh new Ubuntu LTS. 🕺💃

However, if you've previously installed Intercity via the intercity-server command as described in the previous docs/installation.md, you'll have to perform some additional steps as the database setup is different. You'll have to migrate your current database into the database of the new installation. You definitely don't want to loose al your precious app configuration settings and secrets!

What you'll have to do is the following. I'll explain each step in details below.

  1. Export the current Intercity database via pg_dump.
  2. Stop your current Intercity installation.
  3. Install the new Intercity via the new installation procedure.
  4. Import the database from your previous installation into the new one.

Before you perform the above steps: make sure you have a backup of your server. For example by using the backups/snapshots feature of your VPS provider or Cloud.

You can also copy the directory /var/intercity/shared/postgres_data to /var/intercity/shared/postgres_data_backup for example:

$ sudo cp -r /var/intercity/shared/postgres_data /var/intercity/shared/postgres_data_backup

Ok, so here we go:

Export the current database

Look up the Docker container ID of your current Intercity installation:

$ sudo docker ps

You should see something like this:

db76d2869d40    local_intercity/app "/sbin/boot"

"db76d2869d40" is the container ID of your current Intercity installation. Use it in the next few commands to access a shell in that running container, export the database, and bring it back to your host system:

$ sudo docker exec -it db76d2869d40 bash
(container) # su intercity
(container) $ cd /home/intercity
(container) $ pg_dump -U intercity -d intercity -f intercity.sql
(container) $ exit
(container) # cp /home/intercity/intercity.sql /shared
(container) # exit

You have now succesfully exported the database from your current Intercity environment into a file intercity.sql in /var/intercity/shared on your host system. We'll use this file in one of the next steps to import into your new Intercity installation.

Stop your current installation

You can safely stop your current Intercity with the following command, using the container ID you fetched in the previous steps:

$ sudo docker stop db76d2869d40

Install Intercity via the new installation procedure

$ mkdir intercity
$ wget https://raw.githubusercontent.com/intercity/intercity-next/master/scripts/bootstrap.sh
$ sudo bash bootstrap.sh

After a few minutes your installation is running and the "Create your first user" screen should be visible on the domain name you've configured. Please verify that you see the "Create your first user" screen to ensure your new installation is fully booted up!

Import your Intercity database

Now we're going to import the intercity.sql database into the new Intercity installation.

Run the following commands to do so:

$ sudo -s
# cat /var/intercity/shared/intercity.sql | docker-compose exec db psql -U postgres -d intercity

You should see a lot of output in your terminal. This indicates that the database is being imported. You probably see a lot of errors in this output, telling you relations or indexes already exist. This is fine, as the clean bootstrapped database from the new Intercity install already created those. This command is now only importing the data.

To check if the import was succesful: head over to the URL that your Intercity installation is hosted on. Instead of the "Create your first user" screen, you should now see the regular login screen again. If you see the login screen: import succesful!


Awesome! I hoped this procedure worked for you. If not, or if you're getting errors: let me know!

Top comments (0)