使用mysqlhotcopy

wenaini發表於2009-02-05

首先系統的perl包和DBD/DBI一定要全,並且版本要對應好,不然呼叫mysqlhotcopy很容易出錯。特別有名的錯誤就是:

Can't locate DBI.pm in @INC

另外要注意,OS和Mysql的位數要一致,否則Mysqlhotcopy呼叫perl時會發生錯誤。

[@more@]

以mysql 4.0.27為例,DBI我們選用DBI-1.53,DBD則為DBD-mysql-3.0008

將2個包上傳到伺服器,用yum直接安裝也可以,但是有的情況下版本對應會出現錯誤導致hotcopy不可用。

tar zxvf DBI.tar.gz
cd DBI-1.53
perl Makefile.PL
make
make test
make install
tar zxvf DBD-mysql-3.0008.tar.gz
cd DBD-mysql-3.0008
perl Makefile.PL --mysql_config=/usr/local/mysql/bin/mysql_config
make
make test
make install

結束了安裝就可以測試拉

下面是備份指令碼:

#!/bin/bash
#
# Use mysqlhotcopy backup mysql database
#
cmd='/usr/local/mysql/bin/mysqlhotcopy -q'
BackupPatch='/usr/backup/data'
logfile='/usr/backup/data/backup.log'
DBNAME=`ls -l /usr/local/mysql/data/ | grep '^d' | awk '{print $9}'`

error (){
case "${1}" in
1)
echo "mysqlhotcoyp error"
exit 1
;;
2)
exit 2
;;
*)
useage
;;
esac
}

do_check(){
for loop in $DBNAME
do
[ -d $loop ]&& rm -rf $BackupPatch/$loop
done
}

do_backup (){
$cmd $DBNAME $BackupPatch 2>>$logfile||{ date >>$logfile;error 1; }
}

do_compress (){
cd $BackupPatch
ts=`date +%Y%m%d`
fname=db.$ts.tgz
[ -f $fname ]&& rm $BackupPatch/$fname
tar czvf $fname $DBNAME
}
check_3 (){
num=`ls *.tgz|wc -l`
if [ $num -gt 3 ];then
do_delold
check_3
fi
}

do_delold () {
old=`ls *.tgz|sort|head -n 1`
rm -f $BackupPatch/$old
}

### Main###

cd $BackupPatch
echo "--------backup start at $(date +"%y-%m-%d %H:%M:%S")----------" >> $logfile
do_check
do_backup
do_compress
check_3
do_check
chown -R backup.backup $BackupPatch/
echo "--------backup finish at $(date +"%y-%m-%d %H:%M:%S")--------" >> $logfile
exit 0

備份完可以使用md5sum來生成校驗碼,作用是一旦需要進行遠端備份傳遞,可以進行校驗

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/79686/viewspace-1016772/,如需轉載,請註明出處,否則將追究法律責任。

相關文章