Database Maintenance - Seneca-CDOT/telescope GitHub Wiki
Database Maintenance
Backup (Manual)
- Go to Portainer (staging or production) and locate the
pg-backup-cron-jobcontainer - Click the Console button and select
bin/shin order to get a shell in the container - Run a backup:
$ /etc/periodic/daily/create-backup
This will create a new dump file in /var/opt/pg_dumps with the current date and time.
Restore a Backup
- Go to Portainer (staging or production) and locate the
pg-backup-cron-jobcontainer - Click the Console button and select
bin/shin order to get a shell in the container - Run a restore:
ls /var/opt/pg_dumps
# Locate your desired dump file <absolute-path-to-dump-file>
$ ./restore-backup <absolute-path-to-dump-file>
This will attempt to restore the database to the state in the dump file. NOTE: some operations will fail if tables exist or if the schema in the dump file does not match with the schema in the database, or if Postgres can't make it work for some reason.
Migrations
- Go to Portainer (staging or production)
- Click on the
primaryenvironment, which has all of our containers. - Click Containers
- Get the current postgres password going to the
supabase-dbcontainer, and inspecting thePOSTGRES_PASSWORDenvironment variable. Copy this (you will need it below). - Go back to Containers and click Add Container to add a new container
- Enter a Name:
db-migrations - Select the
docker.cdot.systemsRegistry. NOTE: if you don't see it, add it via the Registries navigation menu on the left. - Enter Image Name:
db-migrations:staging - Under Advanced Container Settings, click the Network tab, and change the Network from
bridgeto use current default network (e.g.,blue_defaultorgreen_default). - Under Advanced Container Settings, click the Env tab, and add an environment variable,
DATABASE_URLwith a value ofpostgres://postgres:<$POSTGRES_PASSWORD>@db:5432/postgres, where<$POSTGRES_PASSWORD>is the current postgres password for thedbcontainer. - Click the Deploy the container button
- Look at the Logs for the
db-migrationscontainer that you just created, and make sure it ran correctly. - Go to the Supabase Console (staging or production)
- Once you are happy with what it has done, you can Remove the
db-migrationscontainer.