The Postgres Backup API is a lightweight Node.js service that allows you to securely download highly-compressed PostgreSQL database backups via a single HTTP endpoint. It streams the native pg_dump output directly to your browser or terminal without consuming any local disk space, ensuring fast, out-of-memory-safe database exports.
- Zero Disk Usage: Streams the backup directly to the client via HTTP.
- Highly Compressed: Uses Postgres's custom format (
-Fc) for minimal bandwidth. - Token Security: Enforces optional API key authentication to keep your data safe.
- Dynamic Postgres Versions: Set the exact
PG_VERSIONto match your database.
Hosting this backup service involves deploying a lightweight container capable of running both Node.js and the native PostgreSQL client tools.
When deployed, the Express server listens for HTTP GET requests on the / route. Instead of saving large backup files to ephemeral storage, it directly pipes the data stream to the client. To ensure safety in a public cloud environment, the deployment relies on environment variables to establish the database connection and enforce token-based authentication for all backup requests.
- Automated off-site backups triggered by scheduled cron jobs (e.g., using
curlorwget). - Secure, one-click manual database snapshots for your team without distributing raw database credentials.
- Quickly pulling copies of production data down to your local machine for staging and development.
To deploy this service successfully, you must configure the following environment variables:
| Variable | Description | Required | Default |
|---|---|---|---|
DATABASE_URL |
The full connection string of the PostgreSQL database you want to back up. | Yes | - |
SECRET_TOKEN |
A secure passphrase used to authenticate requests. If set, backups can only be downloaded by appending ?token=YOUR_TOKEN to the URL. |
No | - |
PG_VERSION |
Adjust this if you need a specific major version of the Postgres client tools to match your database. | No | 18 |
Once deployed, you can trigger a backup from your browser or terminal by sending a GET request to the / endpoint: