Lv.的博客

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

posted @ 2014-07-03 15:11  Avatarx  阅读(408)  评论(0编辑  收藏  举报