首先系统的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来生成校验码,作用是一旦需要进行远程备份传递,可以进行校验
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。