Last active
May 28, 2016 13:00
-
-
Save turkeryildirim/baa2a18e68b530a8f2360e2ddc726f60 to your computer and use it in GitHub Desktop.
MySQL - Backup each database into a different file
This file contains 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 | |
USER="myuser" | |
PASSWORD="mypassword" | |
OUTPUT="/etc/mysql/backup" | |
ExcludeDatabases="information_schema|performance_schema|mysql" | |
if [ ! -d $OUTPUT ]; then | |
mkdir -p $OUTPUT | |
fi | |
chmod 0700 $OUTPUT | |
rm "$OUTPUT/*" > /dev/null 2>&1 | |
databases=`mysql --user=$USER --password=$PASSWORD -e "SHOW DATABASES;" | tr -d "|" | grep -v $ExcludeDatabases` | |
for db in $databases; do | |
echo "Dumping database: $db" | |
mysqldump --add-drop-database --opt --lock-all-tables -u $USER -p$PASSWORD $db | gzip -9 > "$OUTPUT/$db.sql.gz" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment