[root@db7 ~]# mysqlhotcopy --allowold --flushlog --host=localhost --user=root --password=123456 mysql /tmp
DBD::mysql::db do failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'all TABLES' at line 1 at /mysql/bin/mysqlhotcopy line 452.
查看mysqlhotcopy脚本 第452行如下
450 else {
451 my $start = time;
452 $dbh->do("LOCK all TABLES ");
453 printf "Locked $num_tables tables in %d seconds.\n", time-$start unless $opt{quiet};
454 $hc_started = time; # count from time lock is granted
455
456 # flush tables to make on-disk copy up to date
google baidu 都没有找到,既然mysqlhotcopy是先锁表,然后调用linux 上的cp scp命令直接拷贝数据文件.然后就自己写了一个.测试之后挺好用.现在贴出脚本.有什么好的方法希望指出.
tables=($(${MYSQL} -A -Bse "show tables"))
tab_num=`echo ${#tables[@]}`
for arg in ${tables[@]}
do
if [ $i -eq $tab_num ]
then
echo $arg|awk '{print $1,"read"}' >>/tmp/tables
else
echo $arg|awk '{print $1,"read,"}' >>/tmp/tables
fi
i=$(($i+1))
done
lock_tables=`cat /tmp/tables|awk '{printf("%s",$0)}'`
echo "`date '+%Y-%m-%d %H:%M:%S'` start backup database $database" >> $logfile
$MYSQL -A -Bse "lock table $lock_tables ;system cp -r "'/data/mysql'" "'/backup/'";" >>$logfile 2>&1
#echo $?
if [ $? -eq 0 ]
then
echo "`date '+%Y-%m-%d %H:%M:%S'`Backup $database successed" >> $logfile
cd /backup
if [ -d ${database}${DATE} ]
then
echo "`date '+%Y-%m-%d %H:%M:%S'` ${database}${DATE} is exist" >> $logfile
else
mv $database ${database}${DATE}
echo "`date '+%Y-%m-%d %H:%M:%S'` del useless file" >> $logfile
rm -rf /tmp/tables
cd /backup/${database}${DATE}
rm -rf im* cdr* oplog*
fi
else
echo "`date '+%Y-%m-%d %H:%M:%S'` Backup $database Failed" >> $logfile
fi
cd /backup
if [ -d $database${C_DATE} ]
then
echo "`date '+%Y-%m-%d %H:%M:%S'` $database database exist" >> $logfile
tar -zcvf $database${C_DATE}.tar $database >> $logfile 2>&1
echo "`date '+%Y-%m-%d %H:%I:%S'` Delete 7 days before the data $database " >> $logfile
rm -rf $database
else
echo "`date '+%Y-%m-%d %H:%I:%S'` $database${C_DATE} not exist" >> $logfile
fi