Database and Backups

Our databases uses Patroni Postgres on Openshift.

Database backups are handled with the BCGov Backup Container [Repo](https://github.com/BCDevOps/backup-container). We create a build in our `tools` environment and a deployment in our respective environments. This deployment creates a pod that includes a job that runs backups daily, weekly, and monthly.

The backup pod gives a range of options for manual backups, all surrounded in the script `backup.sh`. `./backup.sh -1`, for example, runs a manual backup just once. You can use `backup.sh -h` to see what commands are available. Backups are stored in the `backups` folder.

As noted in the above repo, backups are on a schedule while restoration must be done manually. The steps to restore are:

  • Scale down all resources that connect to the database - at this point, it is just the hcap-server DC pods

  • Ensure that no cron jobs will not run while performing the restoration

  • Scale down patroni to a single node, ensuring that it is the leader

  • To see which members are the leaders vs the replicas, while RSH-ing into the Patroni node, use `patronictl -c patroni.yml list`

  • You can switch nodes using the config map `hcap-patroni-leader`

  • RSH into the backup node. You'll find the backup script `backup.sh` there

  • You can use `./backup.sh -h` for help commands

  • Make a manual backup of current time

  • Restore with a specific file within the `backups` directory using the `backup.sh -r` script

  • Use the superuser password found in secrets

This should now restore your database to your desired point in time.