Quick and dirty: Backup MySQL from Docker Container to local filesystem
I have a little shell script to backup some of my MySQL Databases running in a docker container.
It first finds the ID for the container and then exec the mysqldump
command inside the container and save it outside:
#!/bin/bash
# config section
SERVICE_NAME="service"
DB_NAME="db"
DB_USER="user"
DB_PASSWORD="**top-secret**"
BACKUP_FILE=$SERVICE_NAME-$(date -I).sql
# find container
CONTAINER=$(docker ps|grep $SERVICE_NAME|awk '{print $1}')
# run backup
doc
Please be aware to have adequate permissions for this file because it contains the password in plain text (that’s the „dirty“ part here).