This project provides a set of tools for managing PostgreSQL database backups and restores across different environments (Development, QA, and Production).
- Docker and Docker Compose
- SSH access (for production database backups)
- PostgreSQL client tools (installed in the Docker container)
- Clone this repository:
git clone <repository-url> cd <repository-name>- Create an environment file:
cp .env.example .env- Edit the
.envfile with your database credentials:
- Set the remote database credentials (
REMOTE_DB_*) - Set the local database credentials (
LOCAL_DB_*) - Set the QA database credentials (
QA_DB_*)
- For production backups, create a
remote_config.shfile with the following variables:
PROD_DB_HOST="your-prod-db-host"
PROD_DB_PORT="5432"
PROD_DB_USER="your-prod-db-user"
PROD_DB_PASSWORD="your-prod-db-password"
PROD_DB_NAME="your-prod-db-name"
SSH_KEY_PATH="/path/to/your/ssh/key"
SSH_PORT="22"
SSH_USER="your-ssh-user"
SSH_HOST="your-ssh-host"- Start the Docker container:
make upmake up- Start the Docker containersmake down- Stop and remove the Docker containers
make backup- Create a backup of the development databasemake restore- Restore the development database backup to localmake refresh- Run backup and restore in sequence
make qa_backup- Create a backup of the QA databasemake qa_restore- Restore the QA database backup to localmake qa_refresh- Run QA backup and restore in sequence
make prod_backup- Create a backup of the production databasemake prod_restore- Restore the production backup to localmake prod_refresh- Run production backup and restore in sequence
make local_backup- Create a backup of the local databasemake local_restore- Restore from a local database backupmake local_drop- Drop the local databasemake local_create- Create a new local databasemake local_recreate- Drop and recreate the local database
All backup and restore operations include timing information, showing:
- Real elapsed time
- CPU time in user mode
- CPU time in kernel mode
- Database backups are stored in
/tmp/within the Docker container:- Development:
/tmp/db_backup.gz - QA:
/tmp/qa_db_backup.gz - Production:
/tmp/prod_backup.dump - Local:
/tmp/local_db_backup.gz
- Development:
- Never commit the
.envfile orremote_config.shto version control - Keep SSH keys and database credentials secure
- Ensure proper access controls are in place for production database access
-
If the SSH tunnel fails during production backup:
- Check SSH key permissions
- Verify SSH connection details
- Ensure no existing tunnel is running on port 5433
-
If database operations fail:
- Verify database credentials in
.env - Check database host accessibility
- Ensure Docker containers are running (
docker compose ps)
- Verify database credentials in
- Create a feature branch
- Make your changes
- Submit a pull request
This project is licensed under the GNU General Public License v3.0.
The GPL-3.0 license ensures that:
- The software is free to use, modify, and distribute
- Any modifications or derived works must also be open source
- The source code must be made available
- Changes made to the code must be documented