Last active
February 21, 2021 19:26
-
-
Save khasky/28cbc8b1a00ed98b84348d6e5c37b078 to your computer and use it in GitHub Desktop.
Bash MySQL backup for all databases
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 | |
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