时间:2021-07-01 10:21:17 帮助过:29人阅读
BACKPATH=/root/gool/backup
MYUSER=root
MYPASS=gool
MYCMD="mysql -u$MYUSER -p$MYPASS"
MYDUMP="mysqldump -u$MYUSER -p$MYPASS -x -B -F -R"
[ ! -d $BACKPATH ] && mkdir -p $BACKPATH
DBLIST=`$MYCMD -e "show databases;"|sed 1d|egrep -v "_schema|mysql|sys"`
for dbname in $DBLIST
do
$MYDUMP $dbname|gzip > /root/gool/backup/${dbname}_$(date +%F).sql.gz
done
分库分表备份:
#!/bin/sh
BACKPATH=/root/gool/backup
MYUSER=root
MYPASS=gool
MYCMD="mysql -u$MYUSER -p$MYPASS"
MYDUMP="mysqldump -u$MYUSER -p$MYPASS -x -F -R"
[ ! -d $BACKPATH ] && mkdir -p $BACKPATH
DBLIST=`$MYCMD -e "show databases;"|sed 1d|egrep -v "_schema|mysql|sys"`
for dbname in $DBLIST
do
TBLIST=`$MYCMD -e "show tables from $dbname;"|sed 1d`
for tablename in $TBLIST
do
mkdir -p $BACKPATH/$dbname
$MYDUMP $dbname $tablename |gzip > $BACKPATH/${dbname}/${tablename}_$(date +%F).sql.gz
done
done
mysql增量备份与恢复实战
标签:数据库备份实战