---
title: "Deploy postgres-s3-backup"
description: "Automated PostgreSQL backups to S3 with restore verification"
category: "Automation"
url: https://railway.com/deploy/sparkling-creation
---

# Deploy postgres-s3-backup

Automated PostgreSQL backups to S3 with restore verification

**[Deploy postgres-s3-backup on Railway](https://railway.com/template/sparkling-creation)**

- **Creator:** kjudeh's Projects
- **Category:** Automation
- **Total deploys:** 2

## Template content

### postgres-s3-backup

- **Source:** Kjudeh/railway-postgres-backups

## Documentation

# PostgreSQL Backup & Restore Verification

Automated PostgreSQL backup system that dumps your database on a configurable schedule, compresses and optionally encrypts it with AES-256, then uploads to any S3-compatible storage provider. Includes a dedicated restore verification service that periodically downloads backups and restores them to a separate database to prove they actually work — because a backup you've never tested is a backup you can't trust.

## About Hosting on Railway

This template deploys two services on Railway:

**Backup Service** — Runs `pg_dump` on a configurable interval (default: every hour), compresses the output with gzip, and uploads to your S3 bucket. Supports automatic retention management that cleans up backups older than your configured threshold (default: 7 days). Failed uploads are retried with exponential backoff. Optional AES-256-CBC encryption protects sensitive data at rest.

**Verify Service** — Performs automated restore drills on a separate schedule (default: every 24 hours). Downloads the latest backup from S3, restores it to an isolated verification database, runs integrity checks (table counts, row validation, custom SQL queries), then cleans up. Built-in safety checks prevent accidental restores to your production database.

Both services are lightweight containers built on `postgres:16-alpine` with minimal dependencies. You provide your own S3-compatible storage — AWS S3, Backblaze B2, Cloudflare R2, DigitalOcean Spaces, Wasabi, or MinIO all work out of the box. Configure your database connection and S3 credentials as environment variables and the services start working immediately.

## Common Use Cases

- **Scheduled production backups** — Automatically back up your Railway PostgreSQL database to S3 on a configurable interval (hourly, daily, or custom)
- **Restore verification drills** — Prove your backups are valid and recoverable with automated daily restore tests against an isolated database
- **Backup retention management** — Automatically clean up old backups based on configurable retention policies to control storage costs
- **Encrypted backups** — Protect sensitive production data with AES-256-CBC encryption before uploading to S3
- **Failure alerting** — Get Slack, Discord, or webhook notifications when backups fail or restore verification detects issues
- **Compliance requirements** — Meet data protection and disaster recovery requirements with documented, verified backup procedures

## Configuration

### Required Variables

| Variable | Description |
|----------|-------------|
| `DATABASE_URL` | Your PostgreSQL connection string |
| `S3_ENDPOINT` | S3-compatible endpoint URL |
| `S3_BUCKET` | Bucket name for storing backups |
| `S3_ACCESS_KEY_ID` | S3 access key |
| `S3_SECRET_ACCESS_KEY` | S3 secret key |
| `VERIFY_DATABASE_URL` | Separate database for restore testing |

### Optional Variables

| Variable | Default | Description |
|----------|---------|-------------|
| `BACKUP_INTERVAL` | `3600` | Backup frequency in seconds |
| `BACKUP_RETENTION_DAYS` | `7` | Days to retain backups |
| `BACKUP_ENCRYPTION` | `false` | Enable AES-256 encryption |
| `WEBHOOK_URL` | — | Slack/Discord webhook for notifications |
| `VERIFY_INTERVAL` | `86400` | Restore verification frequency in seconds |
| `MIN_TABLE_COUNT` | `0` | Minimum expected tables after restore |

## Features

- **Any S3 provider** — AWS S3, Backblaze B2, Cloudflare R2, DigitalOcean Spaces, Wasabi, MinIO
- **Configurable compression** — Gzip levels 1-9 to balance speed vs size
- **Exponential backoff retries** — Failed S3 uploads retry automatically
- **Structured logging** — Clean, parseable log output with automatic secret scrubbing
- **Health checks** — Built-in database and S3 connectivity monitoring
- **Graceful shutdown** — Proper SIGTERM/SIGINT signal handling
- **Safety guards** — Verify service validates it never targets your production database
# Deploy and Host PostgreSQL Backup & Restore Verification on Railway

PostgreSQL Backup & Restore Verification is an automated backup system that dumps your database on a configurable schedule, compresses and optionally encrypts it with AES-256, then uploads to any S3-compatible storage. It includes a dedicated restore verification service that periodically restores backups to a separate database to prove they actually work — because a backup you've never tested is a backup you can't trust.

## Why Deploy PostgreSQL Backup & Restore Verification on Railway

- **Zero-maintenance backups** — Deploy once and your PostgreSQL database is automatically backed up on a schedule with configurable retention. No cron jobs to manage, no servers to maintain.
- **Proven recoverability** — The built-in verify service performs automated restore drills daily, so you know your backups work before you need them in an emergency.
- **Flexible storage** — Works with any S3-compatible provider (AWS S3, Backblaze B2, Cloudflare R2, DigitalOcean Spaces, Wasabi, MinIO), so you control where your data lives and what you pay.
- **Production-ready out of the box** — Includes AES-256 encryption, exponential backoff retries, structured logging with secret scrubbing, health checks, graceful shutdown, and webhook notifications to Slack or Discord.

## About Hosting on Railway

This template deploys two services on Railway:

**Backup Service** — Runs `pg_dump` on a configurable interval (default: every hour), compresses the output with gzip, and uploads to your S3 bucket. Supports automatic retention management that cleans up backups older than your configured threshold (default: 7 days). Failed uploads are retried with exponential backoff. Optional AES-256-CBC encryption protects sensitive data at rest.

**Verify Service** — Performs automated restore drills on a separate schedule (default: every 24 hours). Downloads the latest backup from S3, restores it to an isolated verification database, runs integrity checks (table counts, row validation, custom SQL queries), then cleans up. Built-in safety checks prevent accidental restores to your production database.

Both services are lightweight containers built on `postgres:16-alpine`. Configure your database connection and S3 credentials as environment variables and the services start working immediately with sensible defaults.

## Dependencies for PostgreSQL Backup & Restore Verification

### Deployment Dependencies

- **PostgreSQL database** — A running PostgreSQL instance to back up (Railway-managed or external)
- **S3-compatible storage** — A bucket on any S3-compatible provider (AWS S3, Backblaze B2, Cloudflare R2, DigitalOcean Spaces, Wasabi, or MinIO) with access credentials
- **Verification database** — A separate PostgreSQL instance for restore testing (must be different from production to prevent accidental overwrites)

## Common Use Cases

- **Scheduled production backups** — Automatically back up your Railway PostgreSQL database to S3 on a configurable interval (hourly, daily, or custom)
- **Restore verification drills** — Prove your backups are valid and recoverable with automated daily restore tests against an isolated database
- **Backup retention management** — Automatically clean up old backups based on configurable retention policies to control storage costs
- **Encrypted backups** — Protect sensitive production data with AES-256-CBC encryption before uploading to S3
- **Failure alerting** — Get Slack, Discord, or webhook notifications when backups fail or restore verification detects issues
- **Compliance requirements** — Meet data protection and disaster recovery requirements with documented, verified backup procedures

## Configuration

### Required Variables

| Variable | Description |
|----------|-------------|
| `DATABASE_URL` | Your PostgreSQL connection string |
| `S3_ENDPOINT` | S3-compatible endpoint URL |
| `S3_BUCKET` | Bucket name for storing backups |
| `S3_ACCESS_KEY_ID` | S3 access key |
| `S3_SECRET_ACCESS_KEY` | S3 secret key |
| `VERIFY_DATABASE_URL` | Separate database for restore testing |

### Optional Variables

| Variable | Default | Description |
|----------|---------|-------------|
| `BACKUP_INTERVAL` | `3600` | Backup frequency in seconds |
| `BACKUP_RETENTION_DAYS` | `7` | Days to retain backups |
| `BACKUP_ENCRYPTION` | `false` | Enable AES-256 encryption |
| `WEBHOOK_URL` | — | Slack/Discord webhook for notifications |
| `VERIFY_INTERVAL` | `86400` | Restore verification frequency in seconds |
| `MIN_TABLE_COUNT` | `0` | Minimum expected tables after restore |

## Features

- **Any S3 provider** — AWS S3, Backblaze B2, Cloudflare R2, DigitalOcean Spaces, Wasabi, MinIO
- **Configurable compression** — Gzip levels 1-9 to balance speed vs size
- **Exponential backoff retries** — Failed S3 uploads retry automatically
- **Structured logging** — Clean, parseable log output with automatic secret scrubbing
- **Health checks** — Built-in database and S3 connectivity monitoring
- **Graceful shutdown** — Proper SIGTERM/SIGINT signal handling
- **Safety guards** — Verify service validates it never targets your production database


## Similar templates

- [N8N Main + Worker](https://railway.com/deploy/n8n-main-worker) — Deploy and Host N8N with Inactive worker.
- [Evolution API with n8n](https://railway.com/deploy/evolution-api-with-n8n) — [Jul'26] WhatsApp automation platform using Evolution API, n8n & PostgreSQL
- [Postgres Backup](https://railway.com/deploy/postgres-s3-backups) — Cron-based PostgreSQL backup to bucket storage

Open this page in a browser: https://railway.com/deploy/sparkling-creation
