首页    新闻    下载    文档    论坛     最新漏洞    黑客教程    数据库    搜索    小榕软件实验室怀旧版    星际争霸WEB版    最新IP准确查询   
名称: 密码:      忘记密码  马上注册

正在浏览:   1 名游客





嵌入式下MySQL增量备份解决方案
网站管理员
注册日期:
1970/1/1 8:00
所属群组:
网站管理员
帖子: 7077
等级: 58; EXP: 5
HP : 0 / 1426
MP : 2359 / 209489
离线
嵌入式下MySQL增量备份解决方案
由于以前的环境是在嵌入式系统下,对flash的读写有一定限制,所以对mysql的记录必须使用tmpfs。   由于以前的环境是在嵌入式系统下,对flash的读写有一定限制,所以对mysql的记录必须使用tmpfs。

  这是工作中拼凑出来的一个脚本,记录了辛酸的学习之路,记录一下

QUOTE:
#mount.sh

#!/bin/bash

set -e
dataDir=/opt/lampp/var/mysql
backupDir=/opt/lampp/var/mysqldata
plusDir=/opt/lampp/backup/mysql/daily
SqlUser=root
SqlPass=kai089hong

if [ ! -e $plusDir ]
then
mkdir -p $plusDir
fi

test -f /etc/init.d/nasa_switch || exit 0
case "$1" in

start)

echo -n "Starting NASA Server ......"
if [ -d $dataDir ]
then
mount -t tmpfs -o size=32m tmpfs $dataDir
else
mkdir -p $dataDir
mount -t tmpfs -o size=32m tmpfs $dataDir
fi
echo -e "\nMount tmpfs successfully!\n"
cp -R $backupDir/mysql $dataDir/
chmod -R 777 $dataDir
chown -R nobody $dataDir
sleep 4
/opt/lampp/lampp start >/dev/null 2>&1 && echo -e "\nStarted XAMPP successfully!\n"
sleep 4
/opt/lampp/bin/mysqladmin -u$SqlUser -p$SqlPass CREATE nasa > /dev/null
SqlFile=/opt/lampp/backup/mysql
SqlName=`cat $SqlFile/lastone`
/opt/lampp/bin/mysql -u$SqlUser -p$SqlPass nasa < $SqlFile/$SqlName
/opt/lampp/bin/mysqlbinlog $plusDir/mysql-bin.*|mysql -uroot -pkai089hong nasa > /dev/null 2>&1
sleep 3
/opt/lampp/bin/backup.sh
echo -e "\nRecover data successfully!\n"
sleep 10
;;

stop)

echo -e "Stopping NASA Server .......\n"
/opt/lampp/bin/add.sh
sleep 5
/opt/lampp/lampp stop >/dev/null 2>&1
umount $dataDir >/dev/null 2>&1
#mv $backupDir $dataDir
#/opt/lampp/lampp restart >/dev/null 2>&1
#/opt/lampp/bin/mysqlbinlog $plusDir/mysql-bin.*|mysql -uroot -pkai089hong nasa
#mv $dataDir $backupDir
sleep 10
echo -e "OK\n"

;;

*)

echo "Usage: /etc/init.d/nasa_switch {start|stop}"

exit 1

esac

exit 0

bakup.sh
#!/bin/bash

BakDir=/opt/lampp/backup/mysql
LogFile=/opt/lampp/backup/mysql/mysqlbak.log
CatFile=/opt/lampp/backup/mysql/lastone
DailyBakDir=$BakDir/daily
DATE=`date +%y%m%d%H%M%S`
SqlUser=root
SqlPass=kai089hong


if [ ! -e $DailyBakDir ]
then
mkdir -p $DailyBakDir
fi

echo " " >> $LogFile
echo " " >> $LogFile
echo "-------------------------------------------" >> $LogFile
echo $(date +"%y-%m-%d %H:%M:%S") >> $LogFile
echo "--------------------------" >> $LogFile


cd $BakDir
DumpFile=$DATE
echo $DumpFile>$CatFile
/opt/lampp/bin/mysqldump --flush-logs --delete-master-logs --lock-all-tables nasa -u$SqlUser -p$SqlPass>$DumpFile
echo "Dump Done" >> $LogFile

echo "[$DumpFile]Backup Success!" >> $LogFile

cd $DailyBakDir
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

#add.sh

#!/bin/bash
#
# mysql binlog backup script
#


DATADIR=/opt/lampp/var/mysql
BAKDIR=/opt/lampp/backup/mysql/daily
SqlUser=root
SqlPass=kai089hong
/opt/lampp/bin/mysqladmin flush-logs -u$SqlUser -p$SqlPass

if [ ! -e "$BAKDIR" ]
then
mkdir $BAKDIR
fi

cd $DATADIR

FILELIST=`cat mysql-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 [ -e $dest ]
then
echo "skip exist $base"
else
echo "copying $base"
cp $base $BAKDIR
fi
fi
done
#cp $DATADIR/mysql-bin.index $BAKDIR
echo "backup mysql binlog ok"

2008/12/24 2:54
应用扩展 工具箱






可以查看帖子.
不可发帖.
不可回复.
不可编辑自己的帖子.
不可删除自己的帖子.
不可发起投票调查.
不可在投票调查中投票.
不可上传附件.
不可不经审核直接发帖.

[高级搜索]



系统导航

 

Copyright © 2001-2010 安信网络. All Rights Reserved
京ICP备05056747号