forked from openedx-unsupported/devstack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-dbs-init-sql-scripts.sh
executable file
·37 lines (30 loc) · 1.42 KB
/
update-dbs-init-sql-scripts.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
#!/usr/bin/env bash
# Updates MySQL databases dumps with MySQL Docker container schema/data
# Make sure you have added your user to the docker group before running this script
# or use sudo to run it
set -x # echo on
set -e # exit when any command fails
set -u # exit when undefined variables are found
set -o pipefail # prevents errors in a pipeline from being masked
# constants
readonly EDXAPP_MYSQL_DB_USER="edxapp001"
readonly ECOMMERCE_MYSQL_DB_USER="ecomm001"
readonly MYSQL_DB_PASSWORD="password"
readonly EDXAPP_DBS=("edxapp" "edxapp_csmh")
DBS=("ecommerce" "${EDXAPP_DBS[@]}")
# create a docker devstack with LMS and ecommerce
make destroy
make dev.clone.ssh
make dev.provision.services.lms+ecommerce
# dump schema and data from mysql databases in the mysql docker container and copy them to current directory in docker host
MYSQL_DOCKER_CONTAINER="$(make --silent dev.print-container.mysql57)"
for DB_NAME in "${DBS[@]}"; do
DB_CREATION_SQL_SCRIPT="${DB_NAME}.sql"
if [[ " ${EDXAPP_DBS[@]} " =~ " ${DB_NAME} " ]]; then
MYSQL_DB_USER=${EDXAPP_MYSQL_DB_USER}
else
MYSQL_DB_USER=${ECOMMERCE_MYSQL_DB_USER}
fi
docker exec ${MYSQL_DOCKER_CONTAINER} /bin/bash -c "mysqldump -u ${MYSQL_DB_USER} -p${MYSQL_DB_PASSWORD} --no-tablespaces --add-drop-database --skip-add-drop-table --databases ${DB_NAME} > ${DB_CREATION_SQL_SCRIPT}"
docker cp ${MYSQL_DOCKER_CONTAINER}:/${DB_CREATION_SQL_SCRIPT} .
done