Importing database backup with progress bar to running docker container.
Use a MySQL image with pv installed.
FROM mysql:8.0
RUN apt-get update
RUN apt-get install -y pv
COPY my.cnf /etc/mysql/conf.d/my.cnfI share a backup volume(/app/backup/) with a database container. then I have a sh script that looks like this:
# load .env
export $(cat .env | sed 's/#.*//g' | xargs)
restore_database() {
container_id=$(docker ps -f name=$MYSQL_HOST -q | tail -n1)
docker exec -it $container_id sh -c 'pv /app/backup/backup.sql | /usr/bin/mysql -u $MYSQL_ROOT_USER --password=$MYSQL_ROOT_PASSWORD $MYSQL_DATABASE'
}
# anable running different fuctions from console
$@backup.sql I swapped for the backup I want to restore.
The result*:
* I use makefile as a wrapper and sh scripts as my fuctions