Deploy PostgreSQL S3 backups

A simple utility to backup Postgres databases to S3 using Bun.

Deploy PostgreSQL S3 backups

PostgreSQL S3 Backups

ncontiero/postgres-s3-backups

Just deployed

Deploy and Host Postgres S3 backups on Railway

PostgreSQL S3 Backups is an automated backup service that uses node-cron or Railway cron to dump PostgreSQL data and upload it to S3-compatible storage. The service is written in TypeScript and provides configurable scheduling and storage options.

About Hosting PostgreSQL S3 Backups

PostgreSQL S3 Backups runs as a Bun application that executes pg_dump operations on a schedule and uploads compressed database dumps to S3 storage. You'll need to manage cron job reliability, monitor backup success/failure rates, and handle S3 storage costs as backup data accumulates. The service requires database connection management, S3 authentication, and error handling for network failures during uploads. Storage lifecycle policies become important for managing backup retention and costs over time.

Features

  • Automated Backups: Schedule backups using cron expressions.
  • S3-Compatible: Works with AWS S3, Cloudflare R2, MinIO and other S3-compatible services.
  • Compression: Compresses backups using Gzip for efficient storage.
  • Flexible: Supports custom pg_dump options.
  • Run on Startup: Option to run a backup immediately on startup.
  • Single Shot Mode: Run once and exit, ideal for CI/CD pipelines.

Common Use Cases

  • Database Administrators: Automate regular PostgreSQL backups to cloud storage with configurable retention policies
  • DevOps Engineers: Implement disaster recovery procedures and maintain backup compliance for production databases

Dependencies for Postgres S3 backups Hosting

  • Bun: TypeScript execution environment for cron scheduling and backup operations.
  • PostgreSQL Access: Database connection credentials and pg_dump utility availability.
  • S3 Storage: AWS S3 or compatible storage service with appropriate access permissions.

Deployment Dependencies

Implementation Details

Overview

The template uses node-cron or Railway cron, written in TypeScript to dump your PostgreSQL data to a file and then upload the file to S3.

Required Configuration

# AWS/S3 Configuration
AWS_ACCESS_KEY_ID=your-access-key-id
AWS_SECRET_ACCESS_KEY=your-secret-access-key
S3_BUCKET=your-bucket-name
S3_REGION=us-east-1

# Database Configuration
DATABASE_URL=postgresql://user:password@host:port/database

Environment Variables

To configure the backup utility, you need to set the following environment variables:

VariableDescriptionDefault
AWS_ACCESS_KEY_IDYour S3 access key ID.
AWS_SECRET_ACCESS_KEYYour S3 secret access key.
S3_BUCKETThe name of your S3 bucket.
S3_REGIONThe region of your S3 bucket.
S3_ENDPOINTThe endpoint for your S3-compatible service (optional).
DATABASE_URLThe connection URL for your PostgreSQL database.
BACKUP_CRON_SCHEDULEThe cron schedule for backups. See crontab.guru for help.0 0 * * *
BACKUP_FILE_PREFIXThe prefix for the backup file name.backup
BUCKET_SUBFOLDERA subfolder within the bucket to store backups (optional).
BACKUP_OPTIONSExtra options to pass to the pg_dump command (optional).
RUN_ON_STARTUPWhether to run a backup on startup.false
SINGLE_SHOT_MODEWhether to run a single backup and then exit.false
PG_VERSIONThe version of PostgreSQL to use for pg_dump on Docker.18

Why Deploy Postgres S3 backups 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 backups 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

PostgreSQL S3 Backups

ncontiero/postgres-s3-backups

More templates in this category

View Template
N8N Main + Worker
Deploy and Host N8N with Inactive worker.

View Template
Postgres S3 backups
A simple NodeJS app to back up your PostgreSQL database to S3 via a cron

View Template
Prefect (Open-Source Workflow Orchestration Platform)
Prefect (ETL & Automation alternative to Airflow) Self Host [Oct ’25]