Bash MySQL backup for all databases
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=root | |
PASSWORD=root | |
DATE_NOW="`date '+%Y-%m-%d_%H-%M-%S'`" | |
DIR=/var/local/backup | |
DATABASES=`mysql -u$USER -p$PASSWORD -e "SHOW DATABASES;" | tr -d "| " | grep -v Database` | |
echo "Databases found: $DATABASES" | |
for db in $DATABASES; do | |
if [[ "$db" != "information_schema" ]] && [[ "$db" != "performance_schema" ]] && [[ "$db" != "mysql" ]] && [[ "$db" != _* ]] ; then | |
echo "Exporting $db" | |
path=$DIR/"$db"_"$DATE_NOW".sql | |
mysqldump -u $USER -p$PASSWORD $db > $path --skip-opt --extended-insert --quick --compact --compress | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment