skillbox/docs/import-prod-data-heroku.md

1.8 KiB
Raw Permalink Blame History

Update prepreprod Database Contents

This document describes the process to import the database from one heroku environment to another (e.g. production to pre-prod). The goal is then to remove all users, with the exception of superusers and some whitelisted ones, and also their custom content.

heroku pg:backups:restore my-dhf-prod::b313 --app my-dhf-preprod

Check latest backup on the source (where the data comes from) environment, note the backup id

heroku pg:backups --app <source-app>

# example
# 21:56:52 $ heroku pg:backups --app my-dhf-prod
 #    Warning: heroku update available from 7.60.1 to 8.1.9.
# === Backups
# ID    Created at                 Status                               Size    Database
# ────  ─────────────────────────  ───────────────────────────────────  ──────  ────────
# a314  2023-08-31 01:02:23 +0000  Completed 2023-08-31 01:03:52 +0000  7.52MB  DATABASE

If desired, capture a new backup

heroku pg:backups:capture --app <source-app>

For redundancy's sake, create backup on target app

heroku pg:backups:capture --app <target-app>

Restore the backup from the source to the target (where the data goes, and all the old data is lost) app, using the backup id noted before

heroku pg:backups:restore <source-app>::<backup-id> --app <target-app>

# example
#
# heroku pg:backups:restore my-dhf-prod::b313 --app my-dhf-preprod

Connect to target app and run a bash prompt

heroku run --app <target-app> /bin/bash

Go to server folder, run the python shell

cd server
python manage.py shell

Import the nuke_user script, run it

from nuke_users import nuke_users
nuke_users()