+upd metactl.post-start and metactl.pre-stop scripts (verbosity) for
database backup/restore #3
This commit is contained in:
parent
2456c6c1ea
commit
99dce29cfc
|
@ -8,13 +8,44 @@ source $(dirname `realpath $0`)/environment.sh;
|
||||||
## ##
|
## ##
|
||||||
#############################################
|
#############################################
|
||||||
|
|
||||||
# 1.1. Restore mariadb database
|
|
||||||
cat $ROOT/persistent/mariadb.sql | docker exec -i $MARIADB_SERVICE mysql -uroot -p$MARIADB_ROOT_PASSWORD $MARIADB_DATABASE_NAME 2>/dev/null;
|
|
||||||
DB_RESTORED="$?";
|
|
||||||
|
|
||||||
# 1.2. Try until connection OK
|
|
||||||
while [ "$DB_RESTORED" != "0" ]; do
|
## [1] Restore database
|
||||||
sleep 1;
|
|
||||||
|
# 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";
|
||||||
cat $ROOT/persistent/mariadb.sql | docker exec -i $MARIADB_SERVICE mysql -uroot -p$MARIADB_ROOT_PASSWORD $MARIADB_DATABASE_NAME 2>/dev/null;
|
cat $ROOT/persistent/mariadb.sql | docker exec -i $MARIADB_SERVICE mysql -uroot -p$MARIADB_ROOT_PASSWORD $MARIADB_DATABASE_NAME 2>/dev/null;
|
||||||
DB_RESTORED="$?";
|
DB_RESTORED="$?";
|
||||||
done;
|
|
||||||
|
# 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;
|
|
@ -8,5 +8,12 @@ source $(dirname `realpath $0`)/environment.sh;
|
||||||
## ##
|
## ##
|
||||||
#############################################
|
#############################################
|
||||||
|
|
||||||
# 1. Backup mariadb database
|
## [1] Backup mariadb database
|
||||||
docker exec $MARIADB_SERVICE mysqldump -uroot -p$MARIADB_ROOT_PASSWORD $MARIADB_DATABASE_NAME > $ROOT/persistent/mariadb.sql;
|
|
||||||
|
# 1. Create parent dir (if does not exists)
|
||||||
|
test ! -d $ROOT/persistent && mkdir -p $ROOT/persistent;
|
||||||
|
|
||||||
|
# 2. Backup database
|
||||||
|
echo -ne " * Backup database...........";
|
||||||
|
docker exec $MARIADB_SERVICE mysqldump -uroot -p$MARIADB_ROOT_PASSWORD $MARIADB_DATABASE_NAME > $ROOT/persistent/mariadb.sql;
|
||||||
|
test "$?" = "0" && echo "done" || (echo "failed"; exit 1);
|
Loading…
Reference in New Issue