Skip to content

Prod → Dev Sync

Refreshes the shared dev environment from an anonymized production snapshot, preserving Aerscape dev logins.

  • Script: aws_control/prod-to-dev-sync/prod-to-dev-sync.sh
  • Target: app-cluster-dev in us-east-1
  • Trigger: GitHub Actions → Prod-to-Dev-SyncRun workflow (manual)

See Environment Syncs for the shared pipeline; this page covers what is specific to dev.


What it does

A single linear bash script that runs the shared pipeline: backup → download prod snapshot → restore to staging → anonymize → stop services → extract dev users → replace dev DB → re-insert dev users → migrate → start services → sync S3.

The staging database is prod_staging_anonymized (configurable via STAGING_DB); the target dev database defaults to postgres (DEV_DB).

Dev user preservation

Dev users are identified by email:

sql
email LIKE '%@aerscape.com' AND email NOT LIKE '%+%@aerscape.com'

i.e. real @aerscape.com logins, excluding +-tagged test addresses (those come back anonymized from prod instead). prepare_dev_seed.sql extracts these users — plus their companies, SSO configs, and memberships — into /tmp/dev_seed.sql before the swap, then the script replays it afterward. All IDs are regenerated by sequences to avoid collisions with prod IDs in the restored data.

S3 media sync

sh
aws s3 sync --delete \
  s3://aerscape-prod-backup-ohio s3://"$AWS_STORAGE_BUCKET_NAME" \
  --source-region us-east-2 --region us-east-1 \
  --exclude 'data_import/*'

Runs twice in the script's logic: once inside the COPY_ONLY fast-path, once as the final step of a full sync. See the planned exclusions change.

Environment variables

Dev (target) side

VariableNotes
DB_URLHostname of the dev PostgreSQL server
PGPASSWORDDev DB password
RESTIC_PASSWORDPassword for the dev restic repo (backup step)
AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEYDev AWS creds (ECS, S3)
AWS_STORAGE_BUCKET_NAMEDev media bucket

Prod (source) side

VariableNotes
PROD_RESTIC_PASSWORDProd restic repo password
PROD_AWS_ACCESS_KEY_ID / PROD_AWS_SECRET_ACCESS_KEYRead prod backup repo
SOURCE_RESTIC_REPOSITORYDefaults to s3:https://s3.us-west-1.amazonaws.com/aerscape-db-backups

Common / optional

VariableDefaultNotes
STAGING_DBprod_staging_anonymizedStaging DB name
DEV_DBpostgresTarget DB name
PGUSER / PGPORTpostgres / 5432
SKIP_SLACKfalseSuppress Slack notifications
COPY_ONLYfalseRun only the S3 media sync
PROD_DUMP_FILEprod_postgres.gzExpected dump filename in the snapshot

The prod-to-dev README.md in aws_control has drifted from the script (it references DEV_DB_URL, aerscape_anon_staging, etc.). The table above reflects the actual variables the current script reads.

Known issues

  • Sensor API keysanonymize_db.sql writes plaintext into Fernet-encrypted columns, so Django raises a cryptography error when reading those sensor rows. Known limitation.
  • Staging DB is not dropped — the cleanup step (drop prod_staging_anonymized) is commented out, so the anonymized staging DB persists on the dev server between runs.