Introduction
Terraform Enterprise v202103-1 introduced logic to upgrade the internally-managed PostgreSQL data from PostgreSQL 9.5 to PostgreSQL 12. This change only affects Proof of Concept and Mounted Disk installations.
Use Case
Before Terraform Enterprise upgrades the PostgreSQL data from version 9.5 to 12, it creates a backup to ensure data integrity. Depending on the data size, this backup can take a long time and may time out. If you have a large amount of PostgreSQL data, you can back it up manually before upgrading to Terraform Enterprise v202103-1. When the upgrade process detects a manual backup, it skips its own backup step.
This procedure is meant to supplement, not replace, any existing backup procedures you may have. You should perform your existing backup procedures in addition to the steps detailed here.
Note: If the file
${backup_path}/.pg_backup_donealready exists, do not perform these steps. This indicates the backup step of the upgrade process has already completed. If the upgrade failed at a later stage, investigate other potential causes.
Procedure
The procedure involves determining the correct paths for your installation type and then running the backup commands.
Step 1: Determine PostgreSQL Paths
Choose the set of commands that matches your Terraform Enterprise installation type.
For Proof of Concept Installations
-
Define the PostgreSQL data and backup paths.
## The PostgreSQL data path. docker_vol_pgdata="$(docker volume inspect --format='{{.Mountpoint}}' postgres)" pgdata_path="${docker_vol_pgdata}/pgdata" ## The PostgreSQL backup path. docker_vol_backup="$(docker volume inspect --format='{{.Mountpoint}}' postgres_backup)" backup_path="${docker_vol_backup}/9.5"
For Mounted Disk Installations
-
Define the PostgreSQL data and backup paths. The
tr -d '\r'command removes any carriage return characters from the output.## The mounted disk path. mounted_disk_path="$(replicatedctl app-config export --template '{{.disk_path.Value}}' | tr -d '\r')" ## The PostgreSQL data path. pgdata_path="${mounted_disk_path}/postgres/pgdata" ## The PostgreSQL backup path. backup_path="${mounted_disk_path}/postgres-backup/9.5"
Step 2: Perform the Manual Backup
After defining the pgdata_path and backup_path variables in the previous step, follow these steps to complete the backup.
-
Ensure the backup path directory exists.
# mkdir -p "${backup_path}" -
Confirm that the variables contain the correct paths.
# echo "${pgdata_path}" # echo "${backup_path}" -
Shut down the Terraform Enterprise application to stop writes to the database.
# replicatedctl app stop
-
Back up the PostgreSQL 9.5 data.
# cp -r "${pgdata_path}" "${backup_path}" -
Create a file to signal to Terraform Enterprise that the backup is complete. This causes the upgrade process to skip its own backup step.
# touch "${backup_path}/.pg_backup_done"
Outcome
You now have a manual backup of the PostgreSQL 9.5 data located at the path defined in your ${backup_path} variable. You can now proceed to start or upgrade to Terraform Enterprise v202103-1 or a newer version.