标签:msyql
#!/bin/bash
USER=root
PASSWD=123456
SOCK=/data/3306/mysql.sock
LOGIN="mysql -u$USER -p$PASSWD -S $SOCK"
DATABASE=`$LOGIN -e "show databases;" | sed ‘1d‘|egrep -v ".*schema|mysql"`
DUMP="mysqldump -u$USER -p$PASSWD -S $SOCK"
#cd /backup/mysql/
for database in $DATABASE;do
[ ! -d $database ] && mkdir -p /backup/mysql/$database
$DUMP -B $database | gzip > /backup/mysql/$database/${database}_$(date +%F).sql.gz
TABLE=`$LOGIN -e "show tables from $database;"|sed ‘1d‘`
for table in $TABLE;do
$DUMP $database $table | gzip > /backup/mysql/$database/${database}_${table}_$(date +%F).sql.gz
done
done
再结合定时任务,即可实现全自动化备份
本文出自 “激情燃烧的岁月” 博客,请务必保留此出处http://liuzhengwei521.blog.51cto.com/4855442/1763254
标签:msyql
原文地址:http://liuzhengwei521.blog.51cto.com/4855442/1763254