Created
September 6, 2017 06:23
-
-
Save esolitos/c08169297eba3a8f43b9e88f6dec0b3b to your computer and use it in GitHub Desktop.
backup 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="" | |
OUTDIR="`basename $1`" | |
if [ -z "$OUTDIR" ]; then | |
echo "Specify an output directory" | |
exit 1; | |
fi | |
read -s -p "Password: " PASSWORD | |
echo "Ok" | |
if [ -z "$PASSWORD" ]; then | |
echo "Specify a pasword." | |
exit 2; | |
fi | |
databases=`mysql -u $USER -p$PASSWORD -s --skip-column-names -e "SHOW DATABASES;" | grep -Ev '(mysql|information_schema)'` | |
for db in $databases; do | |
filename="$db--`date +%Y%m%d`" | |
echo "Dumping database: $filename" | |
mysqldump -u $USER -p$PASSWORD --databases $db | gzip > "${OUTDIR}/${filename}.sql.gz" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment