Skip to main content

Database backups

Refrence: https://supabase.com/blog/continuous-postgresql-backup-walg

1. Clone the the repo into your project.

clone the scripts, docker file, and other stuff in the repo to your project directory. repo link

2. Fil in the env variables in the .env file

3. Build the postgres database docker file with all the packages that comes with it in the Dockerfile.

4. Configure WAL-G environment variables

execute the shell of the database container with the command below:

docker exec -it <container_id> /bin/bash

after you logged in to the shell of the container, run the config.sh file with the command below:

/root/config.sh

5. Change postgresql.conf file to Enable WAL archiving

run the backup_config.sh file:

/root/backup_config.sh

6. Restart the database

The database is restarted to let the changes in the configuration to take effect.

docker restart <container_id>

7. Create your first physical backup

run the base_backup.sh file:

/root/base_backup.sh

At this point, if you were to check the S3 path that you provided, the following two newly created and populated directories would be observed:

backups/
├── basebackups_005/
└── wal_005/

From then on, subsequent physical backups would be found in the directory basebackups_005 and any WAL archives would be sent to the directory wal_005.