---
title: "Deploy Postgres S3 backup"
description: "Deploy and Host Postgres S3 backup with Railway"
category: "Other"
url: https://railway.com/deploy/postgres-s3-backup-2
---

# Deploy Postgres S3 backup

Deploy and Host Postgres S3 backup with Railway

**[Deploy Postgres S3 backup on Railway](https://railway.com/template/postgres-s3-backup-2)**

- **Creator:** Suhel 's Projects
- **Category:** Other

## Template content

### pg-backup-cron

- **Source:** moonLight-7k/pg-backup-cron

## Buckets

- **pg_backup_bucket**

## Documentation

# 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:

| 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:

```dotenv
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.


## Similar templates

- [Rocky Linux](https://railway.com/deploy/rocky-linux) — [Jul'26] Hosted Rocky Linux 9 workspace with SSH and persistent storage. 🚀
- [Foundry Virtual Tabletop](https://railway.com/deploy/X5tR6G) — A Self-Hosted & Modern Roleplaying Platform
- [Letta Code Remote](https://railway.com/deploy/letta-code-remote) — Run a Letta Code agent 24/7. No inbound ports, just deploy.

Open this page in a browser: https://railway.com/deploy/postgres-s3-backup-2
