How to Set Up Nightly Backups to AWS S3 for Multiple Neon Projects
Nightly backups of multiple Neon Postgres databases can be automated with one GitHub Actions workflow per database. Each workflow runs on a cron schedule, installs a matching Postgres client version, and assumes an AWS IAM role via OIDC. It then pipes pg_dump through gzip, deletes .gz files in that database's S3 folder older than a configurable retention period, and uploads the new dump. Workflows differ only in name, connection-string secret and retention. GitHub-hosted runners time out after about 6 hours, so large databases may need self-hosted runners.
Related posts
- How to create an AWS S3 bucket for Postgres backups
Neon mediumAdept
Part 1 of a series on automating nightly Postgres backups from many Neon projects to S3 via scheduled GitHub Actions covers the AWS setup. It registers GitHub's OIDC identity provider (token.actions.githubusercontent.com, audience sts.amazonaws.com), creates a web-identity IAM role scoped to a specific repository, and creates a general-purpose S3 bucket. A bucket policy then grants that role List, Get, Put and Delete access. Bucket region matters, since distance from the databases lengthens backup jobs, and the account ID, bucket name and role name should be stored as GitHub Secrets for part 2.
- Automated PostgreSQL Backups
Railway mediumAdeptA 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.
- Neon Twin: Move Dev/Test/Staging to Neon, Keep Production on RDS
Neon mediumAdept
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. A scheduled GitHub Actions workflow installs Postgres, runs pg_dump in custom format against RDS, then pg_restore with --clean, --if-exists, --no-owner and --no-acl into a Neon main branch, with per-engineer branches created from it. Caveats include GitHub Actions' 6-hour job limit (use self-hosted runners for large databases), IP allowlisting problems with GitHub's changing runner IPs, and SSL certificate handling. Co-locating both databases in the same AWS region speeds up the job and cuts egress costs.
- Neon Twin: Automate Partial Data Dumps with Postgres and GitHub Actions
Neon mediumAdept
A scheduled GitHub Actions workflow can keep a Neon "Twin" refreshed with a partial copy of a production Postgres database. It installs a pinned Postgres version via apt, dumps the schema with pg_dump, extracts row subsets to CSV with psql \copy, then drops and recreates the target schema and restores it with pg_restore. When subsetting related tables, the selection queries must keep foreign keys intact and the restore must load parent tables first. Partial dumps can also reduce PII exposure by leaving out sensitive tables and columns.
- Neon Twin: How to deploy a change tested in Neon to prod in RDS
Neon mediumAdept
Schema changes tested on Neon database branches can be promoted to an AWS RDS production Postgres database through GitHub Actions that run when a pull request merges. Neon's schema diff shows how a dev branch differs from main. From there, migrations are applied in one of two ways: hand-written dated .sql files that a workflow detects via git diff and runs with psql, or Prisma migrations applied with `prisma migrate deploy`. A follow-up pg_dump/pg_restore job then re-syncs the Neon Twin from production.