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
|
|
|
|
|
|
|
## [1] Restore database
|
|
|
|
|
|
|
|
# 1. Check if dump file exists
|
|
|
|
echo -ne " * Check dump file...........";
|
|
|
|
test -f $ROOT/persistent/mariadb.sql;
|
|
|
|
DUMP_FILE_EXISTS="$?";
|
|
|
|
|
|
|
|
# 2. Restore database
|
|
|
|
if [ "$DUMP_FILE_EXISTS" = "0" ]; then
|
|
|
|
|
|
|
|
echo "found";
|
|
|
|
|
|
|
|
# Restore mariadb database
|
|
|
|
echo -ne " * Restore database";
|
2018-02-18 14:28:52 +00:00
|
|
|
cat $ROOT/persistent/mariadb.sql | docker exec -i $MARIADB_SERVICE mysql -uroot -p$MARIADB_ROOT_PASSWORD $MARIADB_DATABASE_NAME 2>/dev/null;
|
|
|
|
DB_RESTORED="$?";
|
2018-02-18 18:07:44 +00:00
|
|
|
|
|
|
|
# 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
|
|
|
|
|
|
|
|
echo "missing";
|
|
|
|
|
|
|
|
# Create 'persistent' directory if missing
|
|
|
|
test ! -d $ROOT/persistent && mkdir -p $ROOT/persistent;
|
|
|
|
|
|
|
|
echo " * Create dump file..........created";
|
|
|
|
touch $ROOT/persistent/mariadb.sql;
|
|
|
|
|
|
|
|
|
|
|
|
fi;
|