#!/bin/bash
backdir=/home/shaowei/dbbak
dbuser=‘dbusername‘
dbpass=‘dbpasswd‘
dblist=$(ls -p /var/lib/mysql | grep / | tr -d /)
today=$(date +%Y%m%d)
mkdir $backdir
mkdir $backdir/$today
for dbname in $dblist
do mysqldump -u$dbuser -p$dbpass $dbname | gzip -v > $backdir/$today/$dbname-$today.sql.gz
echo $dbname ‘OK‘
done