Upgrade and database migration
This tutorial provides step-by-step instructions to safely upgrade Boundary to its latest version, including database backup and data migration.
When to upgrade
While new features are added to Boundary the backing database schema must be updated to support these features. Database migration is a simple process that is performed prior to upgrading Boundary on controller instances.
Even though the migrate command is resilient to errors due to utilizing PostgreSQL transactions, it is still highly recommended that you follow good database practices and backup prior to migrating because the migrate command does not allow reverting back to an older version. Versions of Boundary greater than 0.1.5 will not let you start a new controller until the database migration is complete, but will direct you to use the boundary database migrate command.
Read the release notes to learn if there are any version specific notes related to your current Boundary version or any versions between your current version and the intended upgrade version.
Boundary database migration workflow
- Backup Postgres database
- Stop all running controllers
- Perform database migration
- Restart controllers
- Upgrade Workers
Prerequisites
Docker is installed
Docker-Compose is installed
A route to download the Postgres Docker image image or a local image cached
A Boundary binary in your
PATH
Terraform 0.13.0 or later installed and in your
PATH
Deploy the demo environment
The demo environment provided for this tutorial includes a Docker-Compose cluster that deploys:
- A Boundary 0.11.2 controller server
- A Postgres database
The Terraform Boundary
Provider is
also used in this tutorial to easily provision resources using Docker, and must
be available in your PATH
when deploying the demo environment.
A worker server is not used in this example, but the process outlined in this tutorial applies to workers as well.
To learn more about the various Boundary components, refer back to the Start a Development Environment tutorial.
The lab environment can be downloaded or cloned from the following Github repository:
In your terminal, clone the repository to get the example files locally:
Move into the
learn-boundary-upgrade
folder.Ensure that you are in the correct directory by listing its contents.
The repository contains the following files:
run
: A script used to deploy and tear down the Docker-Compose configuration.compose/docker-compose.yml
: The Docker-Compose configuration file describing how to provision and network the database and the controller.compose/boundary.hcl
: The controller configuration file used when running Boundary.terraform/main.tf
: The Terraform provisioning instructions using the Boundary provider.
This tutorial makes it easy to launch the test environment with the
run
script.The generated scope ids or user details can be viewed by inspecting the
terraform/terraform.tfstate
file.You can tear down the environment at any time by executing
./run cleanup
.To verify that you deployed everything correctly, print the running docker containers and notice the ones named with the prefix "boundary".
Prepare for an upgrade
Before performing the Boundary upgrade it is recommended to backup the existing Postgres database. This is done manually using the Postgres CLI. Note that your database instance must be running Postgres 11 or greater.
Versions of Boundary greater than 0.1.5 will notify the user if a database migration needs to be performed. This occurs when the database schema is updated to reflect new and updated features. It's important to note that running an earlier version of Boundary after performing a database migration is not supported, and careful backup and verification is encouraged to prevent data loss.
Backup Postgres database
If you're interested in examining the database schema before running a backup,
you can do so by accessing the database on port 5432 with the username and
password postgres
.
To create a backup, run pg_dump
on the boundary_db_1
container as the root
user and output the database to a file like boundary_backup.sql
.
The backup file boundary_backup.sql
will be present in the current working
directory on the boundary_db_1 container. You can verify that the backup was
performed by using grep
to search for the schema names in the backup file.
Note
This tutorial does NOT use best practices for backing up a Postgres database. The method outlined here creates a logical backup of the database in a human-readable format, and does not offer point-in-time recovery (PITR). For production scenarios, use of an automated backup process to perform PITR physical backups is highly recommended. One such solution would be Backup and Recovery Manager, Barman. For more information refer to the Postgres Backup Documentation.
Upgrade the Boundary controllers
Note
Currently Boundary only supports offline database migration, so there will be necessary downtime while the migration is performed.
Stop all running controllers
Controllers need to be upgraded to the latest version of Boundary, and must be stopped while the upgrade is performed. In practice, this might look like logging in to the running controller and stopping the
boundary server
process. For this Docker example, we must kill the process by stopping the controller container and started a new one with the upgraded version of Boundary installed.Upgrade the controllers
In this tutorial the controllers are upgraded by launching an upgraded Boundary controller container. The
docker run
command below will place you in an interactive shell session where you can run the Boundary CLI directly.Note
Do not exit the interactive session until the tutorial is complete. Open a new shell session if you want to return to your local machine.
The
network
is the running Docker-Compose network the database is on:boundary_default
The
volume
is the path to the local compose/ files to be copied onto the new container:"${PWD}/compose/:/boundary/"
The
p
options are the published (forwarded) ports the controller requires:9200:9200
,9201:9201
,9202:9202
The
env
is the exported environment variable:"BOUNDARY_PG_URL=postgresql://postgres:postgres@db/boundary?sslmode=disable"
The
name
is the the name we can reference the container with:boundary_controller_upgrade
The
entrypoint
is the command we should run on the container to start a shell session:/bin/sh
hashicorp/boundary:0.12.0
is the name of the newer image containing an upgraded version of Boundary
Check the version of Boundary
Attempt to restart Boundary
Now that the new version of Boundary is available, try restarting the Boundary server.
Versions of Boundary greater than 0.1.5 will display this message when the new version requires a schema update for the database, and will prevent Boundary from starting. Be aware upgrades prior to this version will not show this message.
Note
If the
boundary/
directory or theboundary/boundary.hcl
files are missing from the container it implies that thedocker run
command was executed from the wrong directory. In this case you will need to:exit
the running container and rundocker rm -f boundary_controller_upgrade
- Navigate back to the
learn-boundary-upgrade
folder - Proceed back to the Upgrade the controllers section above and execute
docker run
again
Perform database migration
With the Postgres database successfully backed up the migration can safely be performed.
Run the migration
Restart Boundary
Boundary should now be up and running. You can open a new shell session to test as needed, or visit the Boundary Web UI in a browser tab on
http://localhost:9200
, logging into theprimary
scope asuser1
and the passwordpassword
or with any of the user info in theterraform/terraform.tfstate
file.
Upgrade the Boundary workers
This tutorial doesn't include a worker, but it is recommended that the same upgrade process is performed on any worker instances when upgrading a controller. While workers do not directly connect to database instances, upgrading workers and controllers to the same version of Boundary ensures continued protocol compatibility and communication.
To upgrade your workers:
- Stop the Boundary service on the worker instance
- Replace the Boundary binary
- Restart the Boundary service
Recommended approach for High Availability
This tutorial covers a simple example of what to expect when performing an upgrade and migration. For non-dev environments and High-Availability considerations, be sure to familiarize yourself with the HA architecture recommendations and controller configurations.
Cleanup and teardown
Stop and destroy the upgraded controller
The upgraded controller container is running independently of Docker-Compose, and must be stopped and removed directly. It is not necessary
exit
the shell session you have running in the background to destroy the container.Cleanup the database instance
The remaining database container and network resources can be cleaned up using the provided
run
script.Check your work with a quick
docker ps
and ensure there are no more containers with theboundary_
prefix leftover. If unexpected containers still exist, execute thedocker rm -f
command from above on each to remove them.