backup dockerise mysql database from host volume I use a VPS (my host) where a LAMP server was installed.
I already have a database associated to host mariaDB server Ver 15.1 Distrib 10.1.47 and automysqlbackup backups it. This part works well.
For a &quot;new project&quot;, we use now docker servers and one with a mysql 5.7 and a volume to save this new project database in a host folder, for exemple: /path/on/host/dockerise/db/
I want to backup too this new database.
What is the right way?

Is there a way with automysqlbackup? I think no because it uses host mariaDb server and mysqldump, and you shouldn't have two servers working on the same database (https://dev.mysql.com/doc/refman/5.7/en/multiple-data-directories.html)
Directly with mysqldump ?
Or just create a bash script and CRON it?
I have a little script for my MariaDb database inside a docker container.
The setup is comparable. I have a database container with a mounted volume. Furthermore I have a second volume for backups mounted under /backup.
The script is run on the host via cron and uses the database instance inside the container, so only one database accesses the data. That is the docker exec part.
I'm sure, you can adopt it to mysql. You only have to configure the CONTAINER_NAME and change the command inside the container.
#!/bin/bash
DATE_TIME=`date +&quot;%Y_%m_%d_%H_%M&quot;`
CONTAINER_NAME=&quot;mariadb&quot;
CONTAINER=`docker ps -q -f name=${CONTAINER_NAME}`
PASSWORD=`docker exec ${CONTAINER} sh -c 'echo $MYSQL_ROOT_PASSWORD'`
BACKUPFILE=${DATE_TIME}_${CONTAINER_NAME}.backup.gz

echo &quot;Backup of MariaDb&quot;
echo &quot;&quot;
echo &quot;Old backps will be deleted.&quot;
echo &quot;Datenbank Container Name: $CONTAINER_NAME&quot;
echo &quot;Datenbank Container:  $CONTAINER&quot;

echo &quot;Writing backup to ${BACKUPFILE}&quot;
echo &quot;&quot;
docker exec ${CONTAINER} sh -c &quot;find /backup/ -mindepth 1 -mtime +8 -delete; /usr/bin/mariabackup --backup --user root --password=${PASSWORD} --stream=xbstream | gzip &gt; /backup/${BACKUPFILE}&quot;
echo &quot;&quot;
echo &quot;Backup finished&quot;