We recently posted a guide to get up and running with the great backup tool Kopia and received a question asking if it was possible to use the Kopia installation on the host to back up container databases as well.
Absolutely! Just use
docker exec and
mysqldump to export the database to the host filesystem as a sql file.
The example below is similar to a command that we run as a cron job each night. The name of the container is
$MYSQL_ROOT_PASSWORD is an environment variable that exists within the container. The exact command may not work right off the bat on your system, but it should get you most of the way there.
docker exec mariadb sh -c 'mysqldump --all-databases -uroot -p"$MYSQL_ROOT_PASSWORD"' > /root/db/mariadb.sql