Select Page
#!/bin/sh
NOW=$(date +"%d-%m-%Y")
# set MySQL login info
MUSER="USERNAME"
MPASS="PASSWORD"
MHOST="localhost"
# guess binary names 
MYSQL="$(which mysql)"
MYSQLDUMP="$(which mysqldump)"
GZIP="$(which gzip)"
 
# get all db names 
DBS="$($MYSQL -u $MUSER -h $MHOST -p$MPASS -Bse 'show databases')"
for db in $DBS
do
 FILE=mysql-$db.$NOW-$(date +"%T").gz
 $MYSQLDUMP -u $MUSER -h $MHOST -p$MPASS $db | $GZIP -9 > $FILE
done
Share This