---
title: "Deploy Postgres Backup to Cloudflare R2 (S3-Compatible)"
description: "Automated PostgreSQL backups to S3-compatible storage with encryption"
category: "Storage"
url: https://railway.com/deploy/postgres-to-r2-backup
---

# Deploy Postgres Backup to Cloudflare R2 (S3-Compatible)

Automated PostgreSQL backups to S3-compatible storage with encryption

**[Deploy Postgres Backup to Cloudflare R2 (S3-Compatible) on Railway](https://railway.com/template/postgres-to-r2-backup)**

- **Creator:** Artour
- **Category:** Storage
- **Total deploys:** 7

## Template content

### pg-r2-backup https://devicons.railway.app/postg

- **Source:** https://github.com/BigDaddyAman/pg-r2-backup

## Documentation

# Deploy and Host Postgres-to-R2 Backup on Railway

## What is Postgres-to-R2 Backup?
Postgres-to-R2 Backup is an automated service that creates scheduled PostgreSQL backups and uploads them to **S3-compatible object storage** such as Cloudflare R2, AWS S3, Wasabi, Backblaze B2, or MinIO.

It supports optional gzip compression or 7z encryption, configurable backup retention, and both private and public database URLs, making PostgreSQL backups reliable, secure, and fully automated.

---

## Hosting Postgres-to-R2 Backup on Railway
Deploying Postgres-to-R2 Backup on Railway involves creating a project, configuring environment variables, and deploying the service. Once running, the service:

- Creates PostgreSQL backups using `pg_dump`
- Compresses or encrypts backups
- Uploads them to S3-compatible storage
- Automatically deletes old backups based on retention settings

Railway handles container hosting, restarts, and logs, allowing you to automate backups without maintaining servers.

---

## Common Use Cases
- Automated daily or hourly PostgreSQL backups
- Secure off-site storage of database snapshots
- Automatic backup retention management

---

## Dependencies
- PostgreSQL database (cloud or self-hosted)
- S3-compatible object storage credentials
- Python 3.9+ (Docker uses Python 3.12)

---

## Scheduling Backups on Railway
Postgres-to-R2 Backup schedules backups internally using the `BACKUP_TIME` environment variable (UTC).

You can:
- Let the service run continuously (recommended)
- Or use Railway Cron to trigger restarts if preferred

All scheduling defaults to **UTC** for consistent behavior across platforms.

---

## Why Deploy Postgres-to-R2 Backup on Railway?
Railway provides a unified platform to deploy and manage your infrastructure. 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-to-R2 Backup on Railway, you can automate secure PostgreSQL backups with minimal maintenance, freeing up time to focus on your application while ensuring reliable off-site backup storage.


## Similar templates

- [Garage S3 Storage](https://railway.com/deploy/garage-s3-storage) — Ultra-light S3 server: fast, open-source, plug-and-play.
- [Redis](https://railway.com/deploy/redis-1) — Self Host Latest Redis with Railway
- [EasyImg](https://railway.com/deploy/easyimg) — Simple self-hostable Nuxt.js personal image hosting system.

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