首先代表所有使用者,感谢PERCONA的无私贡献,今天简单介绍一下 MySQL 免费热备工具 XtraBackup , 特别是几个使用时值得注意的地方。
1. 下载XtraBackup并安装 当前最新的版本是1.6 ,从这里可以选择不同OS的相应版本: http://www.percona.com/downloads/XtraBackup/XtraBackup-1.6/ 在LINUX下你可以直接运行: wget http://www.percona.com/redir/downloads/XtraBackup/XtraBackup-1.6/RPM/rhel5/x86_64/xtrabackup-1.6-245.rhel5.x86_64.rpm rpm -ivh xtrabackup-1.6-245.rhel5.x86_64.rpm 2. 数据库中建立备份账号 GRANT SELECT, RELOAD, LOCK TABLES, REPLICATION CLIENT ON *.* TO ‘username'@'localhost' IDENTIFIED BY ‘password'; |
#!/bin/bash #this script used backup mysql data.edit by colderboy.user=root host=localhost passwd=123456 backlog=/data/log/`date '+%Y%m'` backup_path=/backup mycnf=/etc/my.cnf echo "#################################start backup `date '+%Y-%m-%d %T'`" >> $backlog innobackupex-1.5.1 --user=$user --password=$passwd --host=$host --port=3306 --tmpdir=/tmp --defaults-file=$mycnf $backup_path 2>$bac klog cd $backup_path backname=`ls` tar -zcvf ${backname}.tar.gz $backname 2>>$backlog if [ $? -eq 0 ] then if [ -f ${backname}.tar.gz ] then /www/scripts/ftp_upload.sh ${backname}.tar.gz && rm -rf ${backname}.tar.gz else echo "$backname file not exist `date '+%Y-%m-%d %T'`" >> $backlog fi echo "delete backup file $backname" >>$backlog rm -rf $backname else echo "backup failed `date '+%Y-%m-%d %T'`" >> $backlog fi echo "###########################################################################" >>$backlog |
[root@log scripts]# more ftp_upload.sh #/bin/bash #This script is used to upload a backup file. #badboy 2011-05-25 if [ $# -ne 1 ] then echo " Usage `basename $0` upload filename upload backup dir " exit 1 fi host=192.168.0.11 user=test passwd=test f_name=$1 s_dir=/www/backup t_dir=test ftp -n<<! open $host user $user $passwd binary cd $t_dir lcd $s_dir prompt put $f_name close bye ! |
xtrabackup --defaults-file=/etc/my.cnf --prepare --target-dir=/backup/2011-08-04_21-56-08 xtrabackup --target-dir/backup/2011-08-04_21-56-08 --prepare --incremental-dir=/backup/daiy ## 应用日志 xtrabackup --defaults-file=/etc/my.cnf --prepare --target-dir=/backup/2011-08-04_21-56-08
|
本文出自 “badboy” 博客,请务必保留此出处http://colderboy.blog.51cto.com/485582/631347