docker-compose exec mariadb sh -c \
'exec mysqldump --all-databases -uroot -p"$MYSQL_ROOT_PASSWORD"' \
____encoding____
| xz --stdout --verbose > [filename].sql.xz
| gzip -c > [filename].sql.gz
| bzip2 -c > [filename].sql.bz2
Scenario: You got a database dump and should restore it. You are making use of the official MariaDB Docker image and docker-compose.
docker-compose up -d mariadb && \
sleep 20 && \
____decoding____ \
docker exec -i "$(docker-compose ps -q mariadb)" \
sh -c 'mysql -uroot -p"$MYSQL_ROOT_PASSWORD" $MYSQL_DATABASE'
docker-compose up -d mariadb
: Create and start a service named mariadb. The service name may vary, dependend how you call it in your docker-compose.yamlsleep 20
: Give the DBMS time to start. You may, instead create a bash script polling for the server to have startet and being ready for connections.____decoding____
: See below.docker exec -i
: There is/was an issue with piping into docker-compose directly. May be solved now."$(docker-compose ps -q mariadb)"
: Find the full identifier for the docker-compose mariadb service.sh -c 'mysql -uroot -p"$MYSQL_ROOT_PASSWORD" $MYSQL_DATABASE'
: Inside the container, execute MySQL and take the connection details from the environment.Dumps may be double-encoded (you can tell your DBA that's unnecessary):
tgz
= tar.gz
tbz2
= tar.bz2
tar.xz
First, decompress, then untar, for instance:
docker-compose up -d mariadb && sleep 20 && gzip -cd [filename] | tar -Ox | docker exec -i "$(docker-compose ps -q mariadb)" sh -c 'mysql -uroot -p"$MYSQL_ROOT_PASSWORD" $MYSQL_DATABASE'
xz --stdout --force --keep --verbose --decompress [filename] |
gzip -cd [filename] |
pv [filename] | gzip -cd |
bzip2 -cd [filename] |
pv [filename] | bzip2 -cd |
tar -Ox |