Railway

Deploy Postgres S3 backup

Deploy and Host Postgres S3 backup with Railway

Deploy Postgres S3 backup

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_ID and AWS_SECRET_ACCESS_KEY)
  • Destination bucket name
  • (Optional) Custom S3 endpoint for non-AWS providers

Implementation Details

Required environment variables:

VariableDescription
DATABASE_URLSComma-separated PostgreSQL connection URLs
AWS_S3_BUCKET_NAMEDestination bucket
AWS_ACCESS_KEY_IDS3 access key
AWS_SECRET_ACCESS_KEYS3 secret key

Optional environment variables:

VariableDefaultDescription
AWS_ENDPOINT_URLAWS S3Custom S3-compatible endpoint
AWS_DEFAULT_REGIONus-east-1Bucket region
BACKUP_RETENTION_DAYS30Number of days to retain backups (0 disables pruning)
PG_DUMP_TIMEOUT_SECONDS3600Maximum 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:

  1. Connects to every database listed in DATABASE_URLS.
  2. Creates a compressed SQL dump using pg_dump.
  3. Uploads the backup to backups// in the configured bucket.
  4. 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_bucket

Bucket

More templates in this category

View Template
Rocky Linux
[Jul'26] Hosted Rocky Linux 9 workspace with SSH and persistent storage. 🚀

codestorm
37
View Template
Foundry Virtual Tabletop
A Self-Hosted & Modern Roleplaying Platform

Lucas
71
View Template
Letta Code Remote
Run a Letta Code agent 24/7. No inbound ports, just deploy.

Letta
51