---
title: "Deploy PostgreSQL Backups to GCS"
description: "Scheduled PostgreSQL backups to Google Cloud Storage."
category: "Storage"
url: https://railway.com/deploy/postgresql-backups-to-gcs
---

# Deploy PostgreSQL Backups to GCS

Scheduled PostgreSQL backups to Google Cloud Storage.

**[Deploy PostgreSQL Backups to GCS on Railway](https://railway.com/template/postgresql-backups-to-gcs)**

- **Creator:** carrickkv2's Projects
- **Category:** Storage

## Template content

### railway-gcp-postgres-backup https://devicons.railway.com/i/googlecloud.svg

- **Source:** Ayko-Technologies/railway-gcp-postgres-backup

## Documentation

# Deploy and Host PostgreSQL Backups to GCS on Railway

PostgreSQL Backups to GCS is a Railway Cron Job that creates compressed PostgreSQL archives and stores them in Google Cloud Storage. Connect it to a Railway Postgres service with a reference variable, provide a bucket and service-account credentials, and schedule automated backups. This Railway template intentionally supports GCS only.

## About Hosting PostgreSQL Backups to GCS

This template deploys a short-lived Node.js backup service as a Railway Cron Job. On each scheduled run, it connects to the database defined by `BACKUP_DATABASE_URL`, detects the server’s PostgreSQL major version, selects a compatible `pg_dump` client, and creates a compressed `.tar.gz` archive. The archive is uploaded to your Google Cloud Storage bucket under an environment and date-based folder, then removed from temporary local storage. Configure the schedule in Railway’s Cron Schedule setting; the service runs once and exits after each backup. No public domain, health check, or persistent Railway volume is required.

## Common Use Cases

- Create daily or weekly recovery backups of a Railway PostgreSQL database.
- Store database archives in a GCS bucket owned by your organisation.
- Keep a dated off-platform copy before releases, migrations, or maintenance work.

## Dependencies for PostgreSQL Backups to GCS Hosting

- A PostgreSQL database accessible through `BACKUP_DATABASE_URL`. When the template includes a Railway Postgres service named `Postgres`, use `${{Postgres.DATABASE_URL}}`.
- A Google Cloud Storage bucket for backup archives.
- A Google Cloud service account with permission to create objects in that bucket, supplied as a Base64-encoded JSON key in `GCP_SERVICE_ACCOUNT_KEY`.

### Deployment Dependencies

- [Configure Railway Cron Jobs](https://docs.railway.com/cron-jobs)
- [Create a Google Cloud Storage bucket](https://docs.cloud.google.com/storage/docs/creating-buckets)
- [Create a Google Cloud service account](https://docs.cloud.google.com/iam/docs/service-accounts-create)
- [Create and manage a service-account JSON key](https://docs.cloud.google.com/iam/docs/keys-create-delete)

### Implementation Details

The Docker image includes PostgreSQL client versions 16, 17, and 18. The backup process automatically uses a compatible `pg_dump` client, writes a compressed tar archive, uploads it to GCS, and deletes the temporary file after a successful upload.

Treat `GCP_SERVICE_ACCOUNT_KEY` as a secret and seal it in Railway after setting it. GCS bucket lifecycle rules are recommended for retention and automatic expiry of older backups.

## Why Deploy PostgreSQL Backups to GCS 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 PostgreSQL Backups to GCS 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

- [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/postgresql-backups-to-gcs
