-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint
executable file
·83 lines (61 loc) · 1.37 KB
/
entrypoint
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/bash
. functions.sh
if [[ -n "$DB_DUMP_DEBUG" ]]; then
set -x
fi
# get all variables from environment variables or files (e.g. VARIABLE_NAME_FILE)
# (setting defaults happens here, too)
file_env "DB_SERVER"
file_env "DB_PORT"
file_env "DB_USER"
file_env "DB_PASS"
file_env "DB_NAMES"
file_env "DB_DUMP_DEBUG"
file_env "DB_DUMP_TARGET" "/backup"
file_env "DB_DUMP_KEEP_PERMISSIONS" "true"
file_env "AWS_ENDPOINT_URL"
file_env "AWS_ENDPOINT_OPT"
file_env "AWS_ACCESS_KEY_ID"
file_env "AWS_SECRET_ACCESS_KEY"
file_env "AWS_DEFAULT_REGION"
if [[ -n "$DB_DUMP_DEBUG" ]]; then
set -x
fi
# ensure it is defined
MYSQLDUMP_OPTS=${MYSQLDUMP_OPTS:-}
# login credentials
if [ -n "${DB_USER}" ]; then
DBUSER="-u${DB_USER}"
else
DBUSER=
fi
if [ -n "${DB_PASS}" ]; then
DBPASS="-p${DB_PASS}"
else
DBPASS=
fi
# database server
if [ -z "${DB_SERVER}" ]; then
echo "DB_SERVER variable is required. Exiting."
exit 1
fi
# database port
if [ -z "${DB_PORT}" ]; then
echo "DB_PORT not provided, defaulting to 3306"
DB_PORT=3306
fi
# temporary dump dir
TMPDIR=/tmp/backups
# this is global, so has to be set outside
declare -A uri
# wait for the next time to start a backup
# for debugging
echo Starting at $(date)
exit_code=0
# make sure the directory exists
mkdir -p $TMPDIR
do_dump
[ $? -ne 0 ] && exit_code=1
# remove lingering file
/bin/rm ${TMPDIR}/${SOURCE}
exit $exit_code