Deploy PostgreSQL Backups to GCS
Scheduled PostgreSQL backups to Google Cloud Storage.
railway-gcp-postgres-backup
Just deployed
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 namedPostgres, 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
- Create a Google Cloud Storage bucket
- Create a Google Cloud service account
- Create and manage a service-account JSON key
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.
Template Content
railway-gcp-postgres-backup
Ayko-Technologies/railway-gcp-postgres-backup