之前一直很纳闷,最后才了解到原来是MYSQLDUMP搞的鬼。
如果单纯用MYSQLDUMP进行全库备份会造成以下三个方面的影响。
1、服务器CPU严重阻塞。
2、磁盘I/O直线增加。
3、所有的查询都成了慢查询。
表结构是MYISAM,INNODB,MEMORY三者混合。
所以单纯用HOTCOPY工具恐怕有点困难。所以我今天简单变了一下我上次写的关于用OUTFILE来备份MYSQL的脚本。
可以解决上面说的三个缺点。
#!/bin/sh
BACKUPDIR=/home/david_yeung/backup_new
USERNAME=backup_user
PASSWD=123456
TARNAME=”$BACKUPDIR”/backup”$1″`date ‘+%Y%m%d’`
# Add your own database name here.
case “$1″ in
my_site);;
*) exit;;
esac
# Get all the tables’ name.
NUM=`/usr/local/mysql/bin/mysql -u$USERNAME -p$PASSWD -s -vv -e “show tables” -D $DBNAME|wc -l`
HEADNUM=`expr ${NUM} – 3`
TAILNUM=`expr ${NUM} – 7`
ARR1=`/usr/local/mysql/bin/mysql -u$USERNAME -p$PASSWD -s -vv -e “show tables” -D $DBNAME| head -n”$HEADNUM” | tail -n “$TAILNUM”`
ARR2=($ARR1)
while [ "$i" -lt "${#ARR2[@]}” ]
do
tmpFileName=${ARR2[$i]}
# The real dump process.
/usr/local/mysql/bin/mysqldump -u$USERNAME -p”$PASSWD” “$DBNAME” “$tmpFileName” >> “$TARNAME”
let “i++”
done
[david_yeung@localhost ~]$ cat fast_sp
#!/bin/sh
# Created by david yeung 20080122.
#
# Backup site’s routine.
TARNAME=/home/david_yeung/backup_new/spBackup”$1″`date ‘+%Y%m%d’`
/usr/local/mysql/bin/mysqldump -ubackup_user -p123456 -n -t -d -R my_site > “$TARNAME”
0 01 * * * /home/david_yeung/fast_backup my_site
0 0 * * 5 /home/david_yeung/fast_sp
#!/bin/sh
#
# Created by david yeung.
#
# 20080707.
#
# Backup mysql’s full data.
#
DBNAME=$1
USERNAME=backup_user
PASSWD=123456
PREFIX=/home/david_yeung/backup_new/
DIRNAME=$PREFIX`date ‘+%Y%m%d’`
echo $TARNAME
# Add your own database name here.
case “$1″ in
t_girl);;
*) exit;;
esac
if [ ! -d "$DIRNAME" ]
then
mkdir “$DIRNAME”
fi
# Get all the tables’ name.
NUM=`/usr/local/mysql/bin/mysql -u$USERNAME -p$PASSWD -S/tmp/mysql50.sock -s -vv -e “show tables” -D $DBNAME|wc -l`
HEADNUM=`expr ${NUM} – 3`
TAILNUM=`expr ${NUM} – 7`
ARR1=`/usr/local/mysql/bin/mysql -u$USERNAME -p$PASSWD -S/tmp/mysql50.sock -s -vv -e “show tables” -D $DBNAME| head -n”$HEADNUM” | tail -n “$TAILNUM”`
ARR2=($ARR1)
i=0
while [ "$i" -lt "${#ARR2[@]}” ]
do
tmpFileName=${ARR2[$i]}
# The real dump process.
/usr/local/mysql/bin/mysqldump -u$USERNAME -p”$PASSWD” -S/tmp/mysql50.sock “$DBNAME” “$tmpFileName” > “$DIRNAME”/”$tmpFileName”
let “i++”
done
做Mysql数据库备份还有一个选择:
XtraBackup: Open Source Alternative for Innodb Hot Backup call for ideas
http://www.searchfull.net/1927730.html
Pingback: zabbix性能优化-灰太狼的博客