Mysql数据库导出压缩并保存到指定位置备份脚本
#!/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