This script is used to make the staging database tables a clone of the production database tables. A few modifications are made to the dumps before loading so that the staging database works (e.g. users are renamed, ownership changed).
The script roughly follows these steps:
- Dump the production database tables.
- Modify the dump to rename users and change ownership.
- Load the modified dump into the staging database tables.
The script needs to be run on a server with access to the database (e.g. a bastion host on AWS).
The database host is not stored in the repo. Before running the scripts you
must provide PGHOST on the bastion/server, in one of two ways:
-
Create
scripts/db-clone/env.shby copying the template and filling in the real host. This file is gitignored and stays on the server only:cp env.sh.example env.sh # then edit env.sh and set PGHOST to the RDS cluster endpoint
Passwords for the following users need to be set in the environment variables:
prod_loculus_userstaging_loculus_userprod_keycloak_userstaging_keycloak_userpostgres
You will need to configure the db-clone AWS IAM user profile on the bastion, this can be done with:
aws configure --profile db-clone
The user profile needs write access to the staging s3 bucket and ONLY read access to the production s3 bucket (for security ensure the user does not have write access to the production s3 bucket).
Run the script as follows:
./clone-prod-to-staging.shIt can happen that part of the clone fails. You can check the logs if things don't work as expected.