Created
April 30, 2016 22:19
-
-
Save bosko/0f1c74b71163ef87e2e60d70b3713e4d to your computer and use it in GitHub Desktop.
Back up all MySQL databases - one file per database
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/sh | |
Host=localhost | |
BDir=~/backup/mysql | |
read -p "User: " user | |
read -s -p "Pass: " pass | |
Dump="/usr/local/bin/mysqldump --skip-extended-insert --force" | |
MySQL=/usr/local/bin/mysql | |
Today=$(date "+%a") | |
# Get a list of all databases | |
Databases=$(echo "SHOW DATABASES" | $MySQL -h $Host -u $user -p$pass) | |
for db in $Databases; do | |
date=`date` | |
file="$BDir/$Host-$db-$Today.sql.gz" | |
echo "Backing up '$db' from '$Host' on '$date' to: " | |
echo " $file" | |
$Dump -u $user -p$pass -h $Host $db | gzip > $file | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment