Created
April 8, 2015 18:54
-
-
Save indrisepos/1d3b5bf34bee6c988cc8 to your computer and use it in GitHub Desktop.
mysqldump all databases into separate files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /bin/bash | |
| #origin: http://dev.mensfeld.pl/2013/04/backup-mysql-dump-all-your-mysql-databases-in-separate-files/ | |
| TIMESTAMP=$(date +"%F") | |
| BACKUP_DIR="/mnt/backup/mysql/$TIMESTAMP" | |
| MYSQL_USER="backup" | |
| MYSQL=/usr/bin/mysql | |
| MYSQL_PASSWORD="password" | |
| MYSQLDUMP=/usr/bin/mysqldump | |
| mkdir -p "$BACKUP_DIR" | |
| databases=`$MYSQL --user=$MYSQL_USER -p$MYSQL_PASSWORD -e "SHOW DATABASES;" | grep -Ev "(Database|information_schema|performance_schema)"` | |
| for db in $databases; do | |
| $MYSQLDUMP --force --opt --events --user=$MYSQL_USER -p$MYSQL_PASSWORD --databases $db | gzip > "$BACKUP_DIR/mysql/$db.gz" | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment