-
Notifications
You must be signed in to change notification settings - Fork 7
/
run.sh
48 lines (35 loc) · 1.29 KB
/
run.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
45
46
47
48
#!/bin/bash
set -e
set -o pipefail
if [ "${AWS_BUCKET}" = "**None**" ]; then
echo "You need to set the AWS_BUCKET environment variable."
exit 1
fi
if [ "${PREFIX}" = "**None**" ]; then
echo "You need to set the PREFIX environment variable."
exit 1
fi
if [ -z "${MYSQL_ENV_MYSQL_USER}" ]; then
echo "You need to set the MYSQL_ENV_MYSQL_USER environment variable."
exit 1
fi
if [ -z "${MYSQL_ENV_MYSQL_PASSWORD}" ]; then
echo "You need to set the MYSQL_ENV_MYSQL_PASSWORD environment variable."
exit 1
fi
if [ -z "${MYSQL_PORT_3306_TCP_ADDR}" ]; then
echo "You need to set the MYSQL_PORT_3306_TCP_ADDR environment variable or link to a container named MYSQL."
exit 1
fi
if [ -z "${MYSQL_PORT_3306_TCP_PORT}" ]; then
echo "You need to set the MYSQL_PORT_3306_TCP_PORT environment variable or link to a container named MYSQL."
exit 1
fi
if [ -z "${DATE_FORMAT}" ]; then
DATE_FORMAT="%Y/%m/%d"
fi
MYSQL_HOST_OPTS="-h $MYSQL_PORT_3306_TCP_ADDR --port $MYSQL_PORT_3306_TCP_PORT -u $MYSQL_ENV_MYSQL_USER -p$MYSQL_ENV_MYSQL_PASSWORD"
echo "Starting dump of ${MYSQLDUMP_DATABASE} database(s) from ${MYSQL_PORT_3306_TCP_ADDR}..."
mysqldump $MYSQL_HOST_OPTS $MYSQLDUMP_OPTIONS $MYSQLDUMP_DATABASE | gzip | aws s3 cp - s3://$AWS_BUCKET/$PREFIX/$(date +"$DATE_FORMAT").sql.gz
echo "Done!"
exit 0