网站建设资讯

NEWS

网站建设资讯

使用mysqlhotcopy

首先系统的perl包和DBD/DBI一定要全,并且版本要对应好,不然调用MySQLhotcopy很容易出错。特别有名的错误就是:

创新互联是一家专注于成都网站制作、成都网站设计、外贸营销网站建设与策划设计,禹城网站建设哪家好?创新互联做网站,专注于网站建设10年,网设计领域的专业建站公司;建站业务涵盖:禹城等地区。禹城做网站价格咨询:13518219792

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来生成校验码,作用是一旦需要进行远程备份传递,可以进行校验


网站标题:使用mysqlhotcopy
标题网址:http://njwzjz.com/article/jpjpgo.html