---
title: "Automated PostgreSQL Backups"
description: "A deployable Node.js template automates PostgreSQL backups on Railway by running a cron job that uploads compressed dumps to an S3 bucket."
url: "https://swe.quest/articles/automated-postgresql-backups-be869b2aa09ef3bf"
canonical: "https://blog.railway.com/p/automated-postgresql-backups"
source: "Railway"
published: "2022-09-02"
difficulty: "medium"
kind: "How-to"
reading_minutes: 4
tags: ["postgres","cloud","storage-systems"]
---

# Automated PostgreSQL Backups

A post on [Railway](https://swe.quest/sources/railway.md), published 2022-09-02, 4 min read, How-to. Original: [https://blog.railway.com/p/automated-postgresql-backups](https://blog.railway.com/p/automated-postgresql-backups)

## Summary

A deployable Node.js template automates PostgreSQL backups on Railway by running a cron job that uploads compressed dumps to an S3 bucket. Setup involves creating an S3 bucket and an IAM user with programmatic access, ideally restricted to s3:PutObject on that bucket rather than AmazonS3FullAccess. The service is then configured through environment variables for AWS credentials, bucket, region, the BACKUP\_DATABASE\_URL and an optional cron schedule that defaults to daily at 5 AM UTC. Restoring means extracting the tar.gz and running pg\_restore against the target database URL.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [PostgreSQL](https://swe.quest/tags/postgres.md) (Data & databases)
- [Cloud platforms](https://swe.quest/tags/cloud.md) (Infrastructure)
- [Storage systems](https://swe.quest/tags/storage-systems.md) (Infrastructure)

## Prerequisites

- PostgreSQL basics ([easy posts on PostgreSQL](https://swe.quest/tags/postgres.md?difficulty=easy))
- AWS S3 and IAM ([easy posts on Cloud platforms](https://swe.quest/tags/cloud.md?difficulty=easy))
- cron syntax

## Keywords

PostgreSQL, Railway, Amazon S3, AWS IAM, pg\_restore, Node.js

## Related posts

- [How to Set Up Nightly Backups to AWS S3 for Multiple Neon Projects](https://swe.quest/articles/how-to-set-up-nightly-backups-to-aws-s3-for-multiple-neon-projects-8546de66a0aa7f01.md): Neon · 2024-10-29 · Medium · 7 min read · PostgreSQL, CI/CD, Cloud platforms, Databases
  Nightly backups of multiple Neon Postgres databases can be automated with one GitHub Actions workflow per database.
- [How to create an AWS S3 bucket for Postgres backups](https://swe.quest/articles/how-to-create-an-aws-s3-bucket-for-postgres-backups-1b827136764e94f1.md): Neon · 2024-10-28 · Medium · 4 min read · Cloud platforms, Identity & auth, PostgreSQL, CI/CD, Multi-tenancy
  Part 1 of a series on automating nightly Postgres backups from many Neon projects to S3 via scheduled GitHub Actions covers the AWS setup.
- [How to Backup and Restore Your Postgres Database](https://swe.quest/articles/how-to-backup-and-restore-your-postgres-database-d30608dda77d6504.md): Railway · 2021-08-31 · Medium · 3 min read · PostgreSQL, Databases
  Postgres databases on Railway can be backed up with pg\_dump using tar format (-F t) and the PGUSER, PGHOST, PGPORT, PGDATABASE and PGPASSWORD values from the project's variables, then restored into another Railway Postgres instance with pg\_restore.
- [Managed Postgres on Railway](https://swe.quest/articles/managed-postgres-on-railway-38376e6923686bbc.md): Railway · 2026-11-05 · Medium · 9 min read · PostgreSQL, Replication, Cloud platforms, AI agents
  Railway's managed Postgres now covers the full database lifecycle: private-by-default services with reference-variable credentials, usage-billed vertical scaling, live volume resizing, and one-click PgBouncer pooling with a separate unpooled URL for migrations.
- [Neon Twin: Move Dev/Test/Staging to Neon, Keep Production on RDS](https://swe.quest/articles/neon-twin-move-dev-test-staging-to-neon-keep-production-on-rds-a26cd19df36ac332.md): Neon · 2024-07-24 · Medium · 7 min read · PostgreSQL, CI/CD, Databases
  A Neon Twin is a nightly-synced copy of an RDS Postgres production database kept in Neon for dev, test and staging, so teams get instant provisioning, branching and scale-to-zero without migrating production.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
