-
Run the Cloud SQL Auth Proxy script:
./proxy.sh $ENVIRONMENT
-
Obtain the database password for the environment:
gcloud secrets versions access latest --project dft-schemes-$ENVIRONMENT --secret database-password
-
Connect using PSQL and enter the password when prompted:
psql -h localhost -U schemes schemes
To download the latest database backup for storing offline:
-
Download the backup (you will be prompted to input your BitWarden master password):
./cold-backup.sh $ENVIRONMENT
This will create an encrypted compressed PostgreSQL custom-format archive schemes-$ENVIRONMENT-$BACKUP_TIMESTAMP.dump.gz.gpg
.
To restore a backup to a local or proxied database:
-
Decrypt the archive (you will be prompted to input your BitWarden master password):
bw get password "UYCS Database Backup Passphrase" \ | ( gpg --batch --decrypt --passphrase-fd 0 --output $ARCHIVE.gz $ARCHIVE.gz.gpg && rm $ARCHIVE.gz.gpg )
-
Uncompress the archive:
gunzip $ARCHIVE.gz
-
Restore the backup:
docker run --rm -i \ --network=host \ -e PGUSER=schemes \ -e PGPASSWORD=$PGPASSWORD \ postgres:16 \ pg_restore -h localhost -d schemes --no-owner < $ARCHIVE