Skip to content

Commit c8c0ccd

Browse files
committed
fix: update prod db dump script via EC2 ssh
1 parent 28d3053 commit c8c0ccd

File tree

3 files changed

+41
-6
lines changed

3 files changed

+41
-6
lines changed

.env.example

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,24 @@ REVIEW_DRIVE_ID=?
1010
REVIEW_DRIVE_EMAIL=?
1111
REVIEW_DRIVE_PASSWORD=?
1212

13-
# database
14-
DB_USER=?
13+
# local database
1514
DB_NAME=?
15+
DB_USER=?
1616
DB_PASSWORD=?
1717
DB_HOST=?
1818
DB_PORT=?
19-
sslmode=?
2019

21-
# email
20+
# prod database
21+
PROD_DB_NAME=?
22+
PROD_DB_USER=?
23+
PROD_DB_PASSWORD=?
24+
PROD_DB_HOST=?
25+
PROD_DB_PORT=?
26+
27+
# feedback
2228
EMAIL_HOST_USER=?
2329
EMAIL_HOST_PASSWORD=?
2430

25-
2631
# aws
2732
AWS_ACCESS_KEY_ID=?
2833
AWS_SECRET_ACCESS_KEY=?
@@ -31,9 +36,14 @@ AWS_SECRET_ACCESS_KEY=?
3136
AWS_STORAGE_BUCKET_NAME=?
3237
AWS_S3_REGION_NAME=?
3338

34-
# AWS Cognito
39+
# cognito
3540
COGNITO_USER_POOL_ID=?
3641
COGNITO_APP_CLIENT_ID=?
3742
COGNITO_APP_CLIENT_SECRET=?
3843
COGNITO_DOMAIN=?
3944
COGNITO_REGION_NAME=?
45+
46+
# ec2
47+
EC2_USER=?
48+
EC2_HOST=?
49+
PEM_KEY=?

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,5 @@ db/*.dump
3434
# Virtual Environments
3535
venv
3636
.venv
37+
# AWS key.pem
38+
key/

scripts/prod_dump.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
# This script dumps a remote database by connecting through an EC2 instance.
3+
4+
filename="$1"
5+
filename="${filename:-prod.dump}"
6+
7+
if [ ! -d "$(dirname "db/$filename")" ]; then
8+
echo "Database destination 'db/$filename' invalid."
9+
echo "Ensure the directory db exists, and provide just the filename."
10+
exit 1
11+
fi
12+
13+
# Ensure EC2 instance is active!
14+
15+
set -e
16+
17+
echo "--- Connecting to EC2 instance '$EC2_HOST' to dump database from '$PROD_DB_HOST' with key at '$PEM_KEY'..."
18+
19+
chmod 400 $PEM_KEY
20+
21+
ssh -i "$PEM_KEY" "$EC2_USER@$EC2_HOST" "PGPASSWORD='$PROD_DB_PASSWORD' pg_dump --host='$PROD_DB_HOST' --username=$PROD_DB_USER --format=custom --clean $PROD_DB_USER" > "db/$filename"
22+
23+
echo "--- ✅ Successfully created remote database dump at: db/$filename"

0 commit comments

Comments
 (0)