Commit 8b76c40b authored by Benjamin's avatar Benjamin

Restore : db restore with docker-compose facilities

parent 0d540b31
......@@ -65,7 +65,9 @@ function db_informations ()
#- Fill the following variables: MYSQL_ROOT_PASSWORD, MYSQL_DATABASE, MYSQL_USER, MYSQL_PASSWORD, PUID, PGID, TZ.
DB_NAME="$MYSQL_DATABASE"
DB_USER="$MYSQL_USER"
DB_PWD="$MYSQL_ROOT_PASSWORD"
DB_PWD="$MYSQL_PASSWORD"
DB_ROOT_USER="root"
DB_ROOT_PWD="$MYSQL_ROOT_PASSWORD"
;;
"pgsql")
#- // TO TEST //#
......@@ -83,14 +85,17 @@ function restore_db ()
echo "*** Database restore from sql dump ***"
#-- Restore database from sql archive:
#- Database container name is 'db' and it's assumed that it is define like that in app's docker-compose.yml file.
case $DB_ENGINE in
"mysql" | "mariadb")
docker exec -i $CONT_DB_ID bash -c "mysql -u '"$DB_USER"' -p${DB_PWD} '"$DB_NAME"'" < ${DB_NAME}.sql
#cat ${DB_NAME}.sql | docker exec -i $CONT_DB_ID /usr/bin/mysql '"$DB_NAME"' -u '"$DB_USER"' --password='"$DB_PWD"'
docker-compose exec -T db bash -c "mysql -u '"$DB_ROOT_USER"' --password='"${DB_ROOT_PWD}"' '"$DB_NAME"'" < ${DB_NAME}.sql
#docker exec -i $CONT_DB_ID bash -c "mysql -u '"$DB_ROOT_USER"' -p${DB_ROOT_PWD} '"$DB_NAME"'" < ${DB_NAME}.sql
#cat ${DB_NAME}.sql | docker exec -i $CONT_DB_ID /usr/bin/mysql '"$DB_NAME"' -u '"$DB_ROOT_USER"' --password='"$DB_ROOT_PWD"'
;;
"pgsql")
#- // TO TEST //#
docker exec -i $CONT_DB_ID bash -c "PGPASSWORD='"$DB_PWD"' psql -U '"$DB_USER"' '"$DB_NAME"'" < ${DB_NAME}.sql
docker-compose exec -T db bash -c "PGPASSWORD='"$DB_PWD"' psql -U '"$DB_USER"' '"$DB_NAME"'" < ${DB_NAME}.sql
#docker exec -i $CONT_DB_ID bash -c "PGPASSWORD='"$DB_PWD"' psql -U '"$DB_USER"' '"$DB_NAME"'" < ${DB_NAME}.sql
#cat ${DB_NAME}.sql | docker exec -i $CONT_DB_ID PGPASSWORD='"$DB_PWD"' /usr/bin/psql -U '"$DB_USER"' '"$DB_NAME"'
;;
esac
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment