On paper, moving a Supabase project between Supabase Cloud and a self-hosted VPS sounds like a one-liner:

pg_dump "$SOURCE_DB" | psql "$TARGET_DB" 

In practice, a raw pg_dump fails almost immediately—and the parts that do succeed silently drop half of what makes a Supabase project work.

Platform roles (anon, service_role, supabase_*) collide with the destination instance. Internal schemas (_analytics, _realtime, _supavisor, auth, storage) clash with the target's own migrations. pg_cron jobs disappear completely. S3 uploads overwrite storage.objects owner columns. And if the target Postgres major version is older than the source, you only find out halfway through a multi-gigabyte restore.

This is the engineering behind bidirectional Supabase Cloud Sync (import and export) in Nitrobase.

Nitrobase has only recently launched and is still in Beta. Cloud Sync is not a zero-downtime logical replication cluster; it is a structured migration pipeline built to move a real Supabase project between Cloud and self-hosted without silent data loss or corrupted platform state.

1. Roles, schema, and data cannot share one exclusion list

A Supabase database mixes your application tables with platform-managed schemas owned by GoTrue (auth), Storage (storage), Realtime (_realtime), Supavisor (_supavisor), Vault (vault), and extensions.

Nitrobase separates the database copy into distinct stages (roles, schema, data, plus vault and pg_cron), using two different schema filters (supabase-dump.ts):

Dump stage What is excluded Why
Roles (pg_dumpall) Reserved platform roles (anon, authenticated, authenticator, service_role, supabase_*, pgsodium_*, pgtle_admin), plus superuser-only attributes (NOSUPERUSER, NOREPLICATION) The target Supabase instance already owns those roles; Nitrobase keeps only non-superuser-safe ALTER ROLE ... SET configs (pgaudit.*, pgrst.*, session_replication_role, statement_timeout, track_io_timing)
Schema (pg_dump --schema-only) Platform and extension schemas (auth, storage, supabase_functions, supabase_migrations, cron, vault, pgsodium, _realtime, _analytics, _supavisor, etc.) The destination instance already runs its own platform DDL and migrations; user DDL is rewritten to be idempotent (IF NOT EXISTS, CREATE OR REPLACE)
Data (pg_dump --data-only) Narrower exclusion list—keeps auth, storage, and queue data, while skipping auth.schema_migrations, storage.migrations, supabase_functions.migrations, storage.buckets_vectors, storage.vector_indexes (and on export, storage.s3_multipart_uploads*) Users, sessions, refresh tokens, buckets, and object rows move across without clobbering the destination's migration ledger or orphaned multipart uploads

Two smaller parser details also avoid surprise restore failures:

  • Postgres ≥ 17.6 \restrict lines: Newer pg_dump emits \restrict / \unrestrict psql meta-commands; Nitrobase comments them out during role and schema transforms and checks data dumps before loading.
  • Superuser-only statements: Event triggers, supabase_realtime publications, ALTER DEFAULT PRIVILEGES FOR ROLE "supabase_admin", and SET transaction_timeout = 0; are stripped from the schema dump so a non-superuser Cloud pooler role (postgres.<ref>) can load cleanly during export.

2. Why pg_cron jobs vanish—and cannot be COPY'd

If you rely on pg_cron to trigger Edge Functions or cleanup queries, pg_dump --schema '*' leaves cron.job behind because it is an extension configuration table.

Even if you dump cron.job explicitly, a raw COPY into the destination fails due to row-level security keyed by username, owner permissions, and colliding jobid sequences.

Instead, Nitrobase migrates pg_cron in a dedicated step (supabase-cron.ts) through pg_cron's own SQL API:

select cron.alter_job( job_id := cron.schedule_in_database( 'nightly-cleanup', '0 3 * * *', 'select public.cleanup_expired();', 'postgres', null, -- non-superuser target: pg_cron rejects ANY explicit username, even its own! false -- paused mode: do not fire jobs until cutover ), active := false ); 

Three subtle details make that step reliable in production:

  • alter_job wraps schedule_in_database: cron.schedule_in_database (pg_cron ≥ 1.4) upserts by (name, owner), but leaves an existing job's active flag untouched—so Nitrobase explicitly sets active via cron.alter_job.
  • Non-superuser username quirk: On managed Postgres, pg_cron refuses any non-null username argument from a non-superuser—even if you pass its own username. Nitrobase checks rolsuper first, passes null when targeting a non-superuser, deduplicates colliding names across merged owners (${name}-${job.jobid}), and lets you import jobs paused (active := false) so migrated schedules do not fire prematurely against live endpoints.
  • Redacting secrets from cron commands and errors: Supabase pg_cron jobs frequently embed Authorization: Bearer <jwt> or sb_secret_... keys for pg_net calls. Nitrobase scans job commands (cronCommandSecrets) to register those tokens with the run redactor and strips quoted SQL literals and bearer tokens from any cronErrorDetail log line.

3. The Storage S3 PutObject owner-reset trap

Supabase Storage stores file binaries in S3 (or local S3-compatible storage) and file metadata (id, owner, user_metadata, bucket_id) in storage.objects.

When exporting a self-hosted app back to Supabase Cloud (supabase-export.ts), Nitrobase loads storage.objects with the data dump first and then copies bucket files via rclone through Supabase's S3 protocol.

The catch: every S3 PutObject against Supabase Storage upserts the matching storage.objects row—and resets its owner and user metadata. If you stop after rclone, every file exists on disk, but RLS policies checking owner = auth.uid() silently break!

Nitrobase snapshots owner and user metadata before the S3 copy and restores them afterward—leaving every storage.objects row matched to its uploaded binary with its original ownership intact.

4. Preflight blockers before moving a single byte

Failed migrations usually waste the most time when they fail 40 minutes in. Before a sync job starts, Nitrobase runs pure preflight checks (supabase-preflight.ts) separated into hard blockers (refuse to start) and explicit warnings (shown before confirmation):

Preflight facts (source + target) │ ├── Hard Blockers (refuse to start) │ ├── Postgres major downgrade (sourceMajor > targetMajor) │ ├── Target free disk < (dbBytes + storageBytes) * diskFactor │ ├── Export target not empty (user tables/functions, auth.users, │ │ storage.buckets/objects, vault.secrets, or Edge Functions exist) │ └── Export DB user lacks CREATE / rolcreaterole, or staging schema prefix taken │ └── Explicit Warnings (surface before confirm) ├── Vault secrets: import copies pgsodium root key if available; │ export NEVER overwrites Cloud's pgsodium root key ├── Hardcoded *.supabase.co references in cron jobs, triggers, or functions ├── Non-base Postgres extensions & custom role passwords └── Edge Functions deployed without JWT verification (verify_jwt: false) 

Notice the honest asymmetry on Vault (pgsodium): when importing from Cloud into a fresh self-hosted instance, Nitrobase warns whether the project's encryption root key can be copied so Vault secrets remain readable. When exporting to Supabase Cloud, Nitrobase intentionally never copies Vault secrets—overwriting a hosted project's pgsodium root key (PUT /pgsodium) is experimental and can render data encrypted under the old key unreadable.

What this migration pipeline still cannot automate

Because API keys (anon, service_role) and auth JWT secrets differ between projects, active user sessions do not survive a cutover untouched (CLOUD_WARN_SESSIONS), and any hardcoded *.supabase.co URLs inside triggers, webhooks, or frontend clients still require updating after the move.

My checklist before migrating a Supabase project

  • [ ] Verify target Postgres major version is >= source major version and target disk has headroom (diskFactor buffer for dumps + storage)
  • [ ] Split roles, schema, and data dumps with different schema exclusion lists—keeping auth and storage data while excluding *.schema_migrations / storage.migrations
  • [ ] Migrate pg_cron jobs via cron.schedule_in_database + cron.alter_job (in paused mode first) and scrub bearer tokens from migration logs
  • [ ] Snapshot and restore storage.objects owner/user metadata if uploading files through Supabase Storage's S3 API
  • [ ] Audit vault.secrets, custom roles, non-base extensions, Edge Function secrets (verify_jwt), and hardcoded *.supabase.co URLs before cutover

Moving Postgres data is the easy part. Preserving roles, cron schedules, storage ownership, and encryption boundaries is what keeps the app working after DNS flips.

Nitrobase source code: https://github.com/AydenGroup/nitrobase