2018-02-18 14:28:52 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
source $(dirname `realpath $0`)/environment.sh;
|
|
|
|
|
|
|
|
#############################################
|
|
|
|
## ##
|
|
|
|
## Executed after launching containers ##
|
|
|
|
## ##
|
|
|
|
#############################################
|
|
|
|
|
|
|
|
|
2018-02-18 18:07:44 +00:00
|
|
|
|
2018-02-18 18:17:18 +00:00
|
|
|
## [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";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-02-18 18:07:44 +00:00
|
|
|
## [1] Restore database
|
|
|
|
|
|
|
|
# 1. Check if dump file exists
|
|
|
|
echo -ne " * Check dump file...........";
|
2018-02-18 18:17:18 +00:00
|
|
|
test -f $MARIADB_DUMP;
|
2018-02-18 18:07:44 +00:00
|
|
|
DUMP_FILE_EXISTS="$?";
|
|
|
|
|
|
|
|
# 2. Restore database
|
|
|
|
if [ "$DUMP_FILE_EXISTS" = "0" ]; then
|
|
|
|
|
|
|
|
echo "found";
|
|
|
|
|
|
|
|
# Restore mariadb database
|
2018-02-18 18:17:18 +00:00
|
|
|
echo -ne " * Restore database..........";
|
|
|
|
cat $MARIADB_DUMP | docker exec -i $MARIADB_SERVICE mysql -uroot -p$MARIADB_ROOT_PASSWORD $MARIADB_DATABASE_NAME 2>/dev/null && echo "restored" || echo "failed";
|
2018-02-18 18:07:44 +00:00
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
echo "missing";
|
|
|
|
|
|
|
|
# Create 'persistent' directory if missing
|
|
|
|
test ! -d $ROOT/persistent && mkdir -p $ROOT/persistent;
|
|
|
|
|
|
|
|
echo " * Create dump file..........created";
|
2018-02-18 18:17:18 +00:00
|
|
|
touch $MARIADB_DUMP;
|
2018-02-18 18:07:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
fi;
|