db-dump.sh is a simple Bash script for creating PostgreSQL database dumps. It automatically reads connection details from your .env file — no manual input required.
- Auto Configuration: Reads
DB_HOST,DB_USER,DB_PASSWORD,DB_NAMEandDB_PORTfrom.env. - Flexible ENV Path: Accepts a custom path to
.envfile as an argument. - Timestamped Output: Each dump file is named with the current date and time to avoid overwrites.
- Organized Storage: Saves all dumps to
dumps/db/directory.
Ensure the script is executable:
chmod +x scripts/db-dump.shbash scripts/db-dump.shbash scripts/db-dump.sh apps/api/.envOutput: dumps/db/backup-2026-04-09_14-30-00.sql
The following variables must be present in your .env file:
DB_HOST=localhost
DB_PORT=5432
DB_USER=postgres
DB_PASSWORD=your_password
DB_NAME=your_database
bashpg_dump(comes with PostgreSQL)
Add the following to your .gitignore to avoid committing dump files:
# Dumps (e.g. database dumps, codebase dumps, etc.)
dumps/