Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1473024
  • 博文数量: 463
  • 博客积分: 10540
  • 博客等级: 上将
  • 技术积分: 5450
  • 用 户 组: 普通用户
  • 注册时间: 2006-11-12 08:30
文章分类

全部博文(463)

文章存档

2014年(2)

2012年(14)

2011年(42)

2010年(18)

2009年(78)

2008年(35)

2007年(182)

2006年(92)

我的朋友

分类: Mysql/postgreSQL

2008-06-10 09:37:47

mysql备份脚本
#!/bin/sh
# data backup by Jason
# by scud
# 2008-01-23
#
# use mysqldump
#
BakDir=/backup/mysql
LogFile=/backup/mysql/mysqlbak.log
DATE=`date +%Y%m%d`
echo " " >> $LogFile
echo " " >> $LogFile
echo "-------------------------------------------" >> $LogFile
echo $(date +"%y-%m-%d %H:%M:%S") >> $LogFile
echo "--------------------------" >> $LogFile
cd $BakDir
DumpFile=$DATE.sql
GZDumpFile=$DATE.sql.tgz
mysqldump --quick --all-databases --flush-logs
--delete-master-logs --lock-all-tables -Q -e -f > $DumpFile
echo "Dump Done" >> $LogFile
tar czvf $GZDumpFile $DumpFile >> $LogFile 2>&1
echo "[$GZDumpFile]Backup Success!" >> $LogFile
rm -f $DumpFile
cd $BakDir/daily
rm -f *
cd $BakDir
echo "Backup Done!"
echo "please Check $BakDir Directory!"
echo "copy it to your local disk or ftp to somewhere !!!"
ls -al $BakDir >> $LogFile
echo "-----------------close----------" >> $LogFile
echo $(date +"%y-%m-%d %H:%M:%S") >> $LogFile
echo "----------------------close----" >> $LogFile
#增量使用以下脚本
#!/bin/sh
#
# mysql binlog backup by Jason
#
/usr/local/mysql/bin/mysqladmin flush-logs
DATADIR=/usr/local/mysql/data
BAKDIR=/backup/mysql/daily
HOSTNAME=`uname -n`
cd $DATADIR
FILELIST=`cat $HOSTNAME-bin.index`
COUNTER=0
for file in $FILELIST
do
COUNTER=`expr $COUNTER + 1 `
done
NextNum=0
for file in $FILELIST
do
base=`basename $file`
NextNum=`expr $NextNum + 1`
if [ $NextNum -eq $COUNTER ]
then
echo "skip lastest"
else
dest=$BAKDIR/$base
if(test -e $dest)
then
echo "skip exist $base"
else
echo "copying $base"
cp $base $BAKDIR
fi
fi
done
echo "backup mysql binlog ok"
阅读(1019) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~