Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2503713
  • 博文数量: 540
  • 博客积分: 11289
  • 博客等级: 上将
  • 技术积分: 6160
  • 用 户 组: 普通用户
  • 注册时间: 2008-02-11 20:27
个人简介

潜龙勿用,见龙在田

文章分类

全部博文(540)

文章存档

2018年(2)

2013年(5)

2012年(24)

2011年(104)

2010年(60)

2009年(217)

2008年(128)

分类:

2008-08-15 16:00:16

以下为mysql备份脚本,因使用的mysqlhotcopy命令,所以只适用于MYISAM引擎数据库,并且建议在100G容量以内的数据库使用。本脚本做的是每天完全备份。
[root@mysql mysql_backup]# cat mysqlbackup.sh
#!/bin/bash
#Shell Name: mysqlbackup.sh.
#MySQL Daily Backup by mysqlhotcopy tools.
#Last Modify: 2008-7-30 Writen by Navy Dai.
#crontab -e
#0 4 * * * /databak/mysql_backup/mysqlbackup.sh
#Shell will run at 4:00 everyday.
MYSQLBACKUPDIR=/databak/mysql_backup
SHELLDIR=$MYSQLBACKUPDIR/mysqlbackup.sh
MYSQLDATADIR=/var/lib/mysql
MYSQLBACKUPLOG=$MYSQLBACKUPDIR/MySQLBackup.log
DATE=`date -I`
mkdir -p $MYSQLBACKUPDIR/MySQL-$DATE
if [ -e "$MYSQLBACKUPLOG" ];then
  continue
else
touch $MYSQLBACKUPLOG
fi
echo "------------Backup start at `date +%Y-%m-%d_%H:%M:%S`-----\
---------" >>$MYSQLBACKUPLOG
for DB in `find $MYSQLDATADIR -type d | \
grep -v '^/var/lib/mysql$'| \
sed  "s/\/var\/lib\/mysql\///" | \
sed "s/test//"`;do
if [ "x$DB" == "x" ];then
   continue
else
   /usr/bin/mysqlhotcopy -q $DB $MYSQLBACKUPDIR/MySQL-$DATE
   echo "`date +%Y-%m-%d_%H:%M:%S` Database:$DB mysqlhotcopy backup success!" >>$MYSQLBACKUPLOG
fi;
done
#tar
for BAKDB in `find $MYSQLBACKUPDIR/MySQL-$DATE/ -type d | \
   grep -v '^/databak/mysql_backup/MySQL-'$DATE'$'| \
   sed "s/\/databak\/mysql_backup\/MySQL-$DATE\///"`;
do
   cd $MYSQLBACKUPDIR/MySQL-$DATE
   tar -zcf $BAKDB-$DATE.tar.gz $BAKDB
   echo "`date +%Y-%m-%d_%H:%M:%S` Database:$BAKDB tar success!" >>$MYSQLBACKUPLOG
   rm -fr $MYSQLBACKUPDIR/MySQL-$DATE/$BAKDB
   echo "`date +%Y-%m-%d_%H:%M:%S` Database:$BAKDB Remove success!" >>$MYSQLBACKUPLOG;
done
echo "------------Backup end at `date +%Y-%m-%d_%H:%M:%S`-----\
---------" >>$MYSQLBACKUPLOG
exit 0
阅读(1038) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~