+add mariadb dump file path to metactl.env +add connection check after mariadb container is lauched (#3)
This commit is contained in:
parent
99dce29cfc
commit
575cf402f8
|
@ -10,4 +10,5 @@ NGINX_SERVICE="nginx";
|
||||||
|
|
||||||
# 3. Mariadb credentials
|
# 3. Mariadb credentials
|
||||||
MARIADB_ROOT_PASSWORD="root";
|
MARIADB_ROOT_PASSWORD="root";
|
||||||
MARIADB_DATABASE_NAME="vhost";
|
MARIADB_DATABASE_NAME="vhost";
|
||||||
|
MARIADB_DUMP="$ROOT/persistent/mariadb.sql";
|
|
@ -10,11 +10,31 @@ source $(dirname `realpath $0`)/environment.sh;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## [1] Wait for database to be READY
|
||||||
|
|
||||||
|
# Restore mariadb database
|
||||||
|
echo -ne " * mariadb socket..";
|
||||||
|
docker exec $MARIADB_SERVICE mysql -uroot -p$MARIADB_ROOT_PASSWORD 2>/dev/null;
|
||||||
|
DB_RESTORED="$?";
|
||||||
|
|
||||||
|
# Try until connection OK
|
||||||
|
while [ "$DB_RESTORED" != "0" ]; do
|
||||||
|
sleep .5;
|
||||||
|
echo -ne ".";
|
||||||
|
docker exec $MARIADB_SERVICE mysql -uroot -p$MARIADB_ROOT_PASSWORD 2>/dev/null;
|
||||||
|
DB_RESTORED="$?";
|
||||||
|
done;
|
||||||
|
|
||||||
|
echo "ready";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## [1] Restore database
|
## [1] Restore database
|
||||||
|
|
||||||
# 1. Check if dump file exists
|
# 1. Check if dump file exists
|
||||||
echo -ne " * Check dump file...........";
|
echo -ne " * Check dump file...........";
|
||||||
test -f $ROOT/persistent/mariadb.sql;
|
test -f $MARIADB_DUMP;
|
||||||
DUMP_FILE_EXISTS="$?";
|
DUMP_FILE_EXISTS="$?";
|
||||||
|
|
||||||
# 2. Restore database
|
# 2. Restore database
|
||||||
|
@ -23,19 +43,8 @@ if [ "$DUMP_FILE_EXISTS" = "0" ]; then
|
||||||
echo "found";
|
echo "found";
|
||||||
|
|
||||||
# Restore mariadb database
|
# Restore mariadb database
|
||||||
echo -ne " * Restore database";
|
echo -ne " * Restore database..........";
|
||||||
cat $ROOT/persistent/mariadb.sql | docker exec -i $MARIADB_SERVICE mysql -uroot -p$MARIADB_ROOT_PASSWORD $MARIADB_DATABASE_NAME 2>/dev/null;
|
cat $MARIADB_DUMP | docker exec -i $MARIADB_SERVICE mysql -uroot -p$MARIADB_ROOT_PASSWORD $MARIADB_DATABASE_NAME 2>/dev/null && echo "restored" || echo "failed";
|
||||||
DB_RESTORED="$?";
|
|
||||||
|
|
||||||
# Try until connection OK
|
|
||||||
while [ "$DB_RESTORED" != "0" ]; do
|
|
||||||
sleep .5;
|
|
||||||
echo -ne ".";
|
|
||||||
cat $ROOT/persistent/mariadb.sql | docker exec -i $MARIADB_SERVICE mysql -uroot -p$MARIADB_ROOT_PASSWORD $MARIADB_DATABASE_NAME 2>/dev/null;
|
|
||||||
DB_RESTORED="$?";
|
|
||||||
done;
|
|
||||||
|
|
||||||
echo "restored";
|
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|
||||||
|
@ -45,7 +54,7 @@ else
|
||||||
test ! -d $ROOT/persistent && mkdir -p $ROOT/persistent;
|
test ! -d $ROOT/persistent && mkdir -p $ROOT/persistent;
|
||||||
|
|
||||||
echo " * Create dump file..........created";
|
echo " * Create dump file..........created";
|
||||||
touch $ROOT/persistent/mariadb.sql;
|
touch $MARIADB_DUMP;
|
||||||
|
|
||||||
|
|
||||||
fi;
|
fi;
|
|
@ -15,5 +15,5 @@ test ! -d $ROOT/persistent && mkdir -p $ROOT/persistent;
|
||||||
|
|
||||||
# 2. Backup database
|
# 2. Backup database
|
||||||
echo -ne " * Backup database...........";
|
echo -ne " * Backup database...........";
|
||||||
docker exec $MARIADB_SERVICE mysqldump -uroot -p$MARIADB_ROOT_PASSWORD $MARIADB_DATABASE_NAME > $ROOT/persistent/mariadb.sql;
|
docker exec $MARIADB_SERVICE mysqldump -uroot -p$MARIADB_ROOT_PASSWORD $MARIADB_DATABASE_NAME > $MARIADB_DUMP;
|
||||||
test "$?" = "0" && echo "done" || (echo "failed"; exit 1);
|
test "$?" = "0" && echo "done" || (echo "failed"; exit 1);
|
Loading…
Reference in New Issue