#!/bin/bash if [[ -z $2 ]]; then cat <<- EOT Usage: $0 [dst_dir] dst_dir - destination dir, where to save backups container_name - name of the mysql docker container EOT fi BASEDIR=$(dirname $0) DEST_DIR=${1:-${BASEDIR}} CONTAINER_NAME=$2 TIMESTAMP=$(date "+%s") DB_NAME=$(docker exec ${CONTAINER_NAME} env | grep MYSQL_DATABASE | cut -d '=' -f 2) # dump command chain docker exec ${CONTAINER_NAME} \ bash -c "mysqldump -u root --password=\${MYSQL_ROOT_PASSWORD} \${MYSQL_DATABASE}" 2> /dev/null | \ bzip2 -c -9 > ${DEST_DIR}/${CONTAINER_NAME%%_*}_${DB_NAME}_${TIMESTAMP}.sql.bz2