mysqlhotcopy备份多个数据库脚本
时间:2010-04-16 来源:ubuntuer
#!/bin/bash
dateDIR=`date +"%y-%m-%d"`
mkdir -p /bak/databases/$dateDIR
user=root
password=123456
for i in `/usr/local/mysql/bin/mysql -u$user -p$password -e "show databases" | grep -v "Database"`
do
/usr/local/mysql/bin/mysqlhotcopy -u $user -p $password $i /bak/databases/$dateDIR
done
如果mysqlhotcopy运行报错,如下:
Can't locate DBI.pm in @INC (@INC contains: /usr/local/apache2/ixiubao/extman/libs /usr/local/lib/perl5/5.8.8/i686-linux /usr/local/lib/perl5/5.8.8 /usr/local/lib/perl5/site_perl/5.8.8/i686-linux /usr/local/lib/perl5/site_perl/5.8.8 /usr/local/lib/perl5/site_perl .) at /usr/local/apache2/ixiubao/extman/libs/Ext/Mgr/MySQL.pm line 13. BEGIN failed--compilation aborted at /usr/local/apache2/ixiubao/extman/libs/Ext/Mgr/MySQL.pm line 13. Compilation failed in require at /usr/local/apache2/ixiubao/extman/libs/Ext/Mgr.pm line 37.
需要安装:
perl-DBD-MySQL-3.0007-1.fc6.i386.rpm
perl-DBI-1.52-1.fc6.i386.rpm
perl-DBD-Pg-1.49-1.fc6.i386.rpm
(以上rpm包,在红帽5光盘上可以找到)
#!/bin/bash
cd /backup
dateDIR=`date +"%y-%m-%d"`
mkdir -p $dateDIR/data
\cp -r /usr/local/apache/htdocs /backup/$dateDIR/
for i in `/usr/local/mysql/bin/mysql -uroot -p123456 -e "show databases" | grep -v "Database"`
do
/usr/local/mysql/bin/mysqldump -uroot -p123456 --default-character-set=gbk --opt $i | gzip > /backup/$dateDIR/data/${i}_${dateDIR}
.sql.gz
done