rewrites the whole thing

This commit is contained in:
Jean-Christophe Vanhalle
2023-08-14 14:48:47 +02:00
parent 222d86a909
commit b47876ad62
19 changed files with 407 additions and 139 deletions

40
replace-db.sh Executable file
View File

@@ -0,0 +1,40 @@
#! /bin/sh
#
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <sql dump file>" >&2
exit 1
fi
if ! [ -e "${1}" ]; then
echo "$1 not found" >&2
exit 1
fi
set -a
. "${PWD}/.env"
set +a
mkdir --parents "${PWD}/tmp"
dump_filename_path="${1}"
docker compose up db -d
while ! docker ps -q -f name="${PREFIX}-db"; do
echo "Waiting for the db container to be up and running..."
sleep 1
done
while ! docker exec "${PREFIX}-db" /bin/sh -c "mysqladmin ping -h 127.0.0.1 -P 3306 --protocol=tcp -u root -p${DB_ROOT_PASSWORD} --silent"; do
echo "Waiting for the mysql server in ${PREFIX}-db to be up and running..."
sleep 1
done
echo "copying mysql dump to db container"
docker cp "${dump_filename_path}" "${PREFIX}"-db:/tmp/dump.sql
echo "dropping ${DB_NAME}"
docker exec "${PREFIX}-db" /bin/sh -c "mysqladmin --force -uroot -p${DB_ROOT_PASSWORD} drop ${DB_NAME}"
echo "creating ${DB_NAME}"
docker exec "${PREFIX}-db" /bin/sh -c "mysqladmin -uroot -p${DB_ROOT_PASSWORD} create ${DB_NAME}"
echo "importing ${dump_filename_path} ({PREFIX}-db/tmp/dump.sql) into ${DB_NAME}"
docker exec "${PREFIX}-db" /bin/sh -c "mysql -uroot -p${DB_ROOT_PASSWORD} ${DB_NAME} < /tmp/dump.sql"