Deploy Postgres S3 backup
Deploy and Host Postgres S3 backup with Railway
pg-backup-cron
Just deployed
pg_backup_bucket
Bucket
Just deployed
Deploy and Host Postgres S3 Backup on Railway
Postgres S3 Backup is a lightweight backup utility that creates compressed SQL dumps of one or more PostgreSQL databases and uploads them to an S3-compatible object storage bucket. It also supports automatic retention policies, allowing old backups to be removed after a configurable number of days.
About Hosting Postgres S3 Backup
Hosting Postgres S3 Backup on Railway allows you to automate PostgreSQL backups without managing your own infrastructure. The service connects to one or more PostgreSQL databases using connection URLs, runs pg_dump to generate compressed SQL backups, and uploads them to any S3-compatible object storage provider, including AWS S3, Cloudflare R2, MinIO, Backblaze B2, and others. Retention policies can automatically remove expired backups, reducing storage usage. The container can be scheduled using Railway's Cron feature to perform backups at regular intervals, providing a simple and reliable disaster recovery solution.
Common Use Cases
- Automatically back up production PostgreSQL databases to S3-compatible storage.
- Maintain scheduled off-site backups for disaster recovery and compliance.
- Back up multiple PostgreSQL databases using a single deployment.
Dependencies for Postgres S3 Backup Hosting
- PostgreSQL database(s) accessible via connection URLs.
- An S3-compatible object storage bucket with API credentials.
Deployment Dependencies
- PostgreSQL connection URL(s)
- S3-compatible object storage (AWS S3, Cloudflare R2, MinIO, etc.)
- AWS-compatible credentials (
AWS_ACCESS_KEY_IDandAWS_SECRET_ACCESS_KEY) - Destination bucket name
- (Optional) Custom S3 endpoint for non-AWS providers
Implementation Details
Required environment variables:
| Variable | Description |
|---|---|
DATABASE_URLS | Comma-separated PostgreSQL connection URLs |
AWS_S3_BUCKET_NAME | Destination bucket |
AWS_ACCESS_KEY_ID | S3 access key |
AWS_SECRET_ACCESS_KEY | S3 secret key |
Optional environment variables:
| Variable | Default | Description |
|---|---|---|
AWS_ENDPOINT_URL | AWS S3 | Custom S3-compatible endpoint |
AWS_DEFAULT_REGION | us-east-1 | Bucket region |
BACKUP_RETENTION_DAYS | 30 | Number of days to retain backups (0 disables pruning) |
PG_DUMP_TIMEOUT_SECONDS | 3600 | Maximum time allowed for each database dump |
Example configuration:
DATABASE_URLS=postgresql://user:password@host:5432/database
AWS_S3_BUCKET_NAME=backups
AWS_ACCESS_KEY_ID=access-key
AWS_SECRET_ACCESS_KEY=secret-key
AWS_DEFAULT_REGION=us-east-1
Each scheduled run:
- Connects to every database listed in
DATABASE_URLS. - Creates a compressed SQL dump using
pg_dump. - Uploads the backup to
backups//in the configured bucket. - Removes backups older than
BACKUP_RETENTION_DAYS(if enabled).
Why Deploy Postgres S3 Backup on Railway?
Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.
By deploying Postgres S3 Backup on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.
Template Content
pg-backup-cron
moonLight-7k/pg-backup-cronpg_backup_bucket
Bucket
