-
Notifications
You must be signed in to change notification settings - Fork 0
/
backup.sh
executable file
·45 lines (33 loc) · 1.05 KB
/
backup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/sh
if [[ -z "${IDENTIFIER}" ]]; then
echo "Missing environment variable IDENTIFIER"
exit 1
fi
echo identifier: ${IDENTIFIER}
if [[ -z "${DATABASE_HOST}" ]]; then
echo "Missing environment variable DATABASE_HOST"
exit 1
fi
echo database-host:${DATABASE_HOST}
if [[ -z "${DATABASE_NAME}" ]]; then
echo "Missing environment variable DATABASE_NAME"
exit 1
fi
echo database-NAME:${DATABASE_NAME}
if [[ -z "${DATABASE_USER}" ]]; then
echo "Missing environment variable DATABASE_USER"
exit 1
fi
echo database-user:${DATABASE_USER}
if [[ -z "${S3_BUCKET}" ]]; then
echo "Missing environment variable S3_BUCKET"
exit 1
fi
echo s3-bucket:${S3_BUCKET}
# DATE=$(date "+%Y-%m-%d") we should only use this function once we decided to version / timestamp our update
TARGET=s3://${S3_BUCKET}/${IDENTIFIER}/${DATABASE_NAME}.sql
echo Backing up ${DATABASE_HOST}/${DATABASE_NAME} to ${TARGET}
pg_dump -v -a -h ${DATABASE_HOST} -U ${DATABASE_USER} -d ${DATABASE_NAME} | aws s3 cp --sse aws:kms - ${TARGET}
rc=$?
if [[ $rc != 0 ]]; then exit $rc; fi
echo Done