-
Notifications
You must be signed in to change notification settings - Fork 0
/
restore.sh
executable file
·50 lines (41 loc) · 1.01 KB
/
restore.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
49
50
#!/bin/bash
STAGE=demo
show_help() {
cat << EOF
Usage: ${0##*/} [-p]
By default, deploy to dev environment on AWS account 812644853088
-p PRODUCTION 192458993663
-d DEMO 915001051872
-l localhost
EOF
}
while getopts "pdl" opt
do
case $opt in
d)
echo "DEMO" >&2
STAGE=demo
;;
l)
echo "localhost" >&2
STAGE=localhost
;;
*)
show_help >&2
exit 1
;;
esac
done
AWS_PROFILE=uneet-$STAGE
shift "$((OPTIND-1))" # Discard the options and sentinel --
test -f "$1" || exit
if test $STAGE == "localhost"
then
export PASSWORD=funfunfun
export MYSQL_HOST=db
else
export PASSWORD=$(aws --profile $AWS_PROFILE ssm get-parameters --names MYSQL_ROOT_PASSWORD --with-decryption --query Parameters[0].Value --output text)
export MYSQL_HOST=$(aws --profile $AWS_PROFILE ssm get-parameters --names MYSQL_HOST --with-decryption --query Parameters[0].Value --output text)
fi
echo Restoring $1 to $STAGE $MYSQL_HOST
mysql -h $MYSQL_HOST -P 3306 -u root --password=$PASSWORD < $1