Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 42 lines (34 sloc) 1.54 KB
# Copyright 2017 Martin Scharm
# This file is part of Docker MySQL-Backup.
# <>
# <>
# Docker MySQL-Backup is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option) any
# later version.
# Docker MySQL-Backup is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
# You should have received a copy of the GNU General Public License along with
# Docker MySQL-Backup. If not, see <>.
NOW=$(date +"%Y-%m-%d_%H-%M")
[ -e "/etc/default/docker-mysql-backup" ] && source "/etc/default/docker-mysql-backup"
for container in $(docker ps --format '{{.Names}}\t{{.Image}}' | /bin/grep '\smysql' | awk '{print $1}')
mkdir -p "${BACKUP_DIR}"
docker exec "$container" sh -c 'exec mysqldump --all-databases -uroot -p"$MYSQL_ROOT_PASSWORD"' | ${GZIP} -9 > "${BACKUP_DIR}/${NOW}_complete.sql.gz"
# delete all that are older than 30 days and the date does not end with a 2 -> keep ~3 per month
for file in $(find $BACKUP_DIR -mtime +30 | grep -v '20..-..-.2_')
rm $file