星空网 > 软件开发 > 数据库

innobackupex使用实践

先介绍一下环境:

 MySQL:5.6.19安装路径:/u01/mysql数据文件:/u01/mysql/data 备份源:/u02/backup

 我是异机恢复,和本机操作一样。

一、 全量备份

步骤:

./innobackupex --user=root --password=root --host=172.17.210.112 --parallel=4 --throttle=400 --stream=tar /mysqlbak/innobackupex 2>/mysqlbak/innobackupex/bak.log 1>/mysqlbak/innobackupex/fullbak.tar

注释一下,常用的参数。

--user=root                备份操作用户名,一般都是root用户--password=root123            密码--host=172.17.210.112           主机ip,本地可以不加--parallel=4 --throttle=400        并行个数,根据主机配置选择合适的,                     默认是1个,多个可以加快备份速度。--stream=tar               压缩类型,这里选择tar格式,可以加,可不加。                     加上文件就小一点,在备份的时候就已经打包好了。/mysqlbak/innobackupex          备份存放的目录2>/mysqlbak/innobackupex/bak.log     备份日志,将备份过程中的输出信息重定向到bak.log1>/mysqlbak/innobackupex/fullbak.tar   备份文件压缩后的名字   

 给出不压缩的全备:

./innobackupex --user=root --password=root --host=172.17.210.112 --parallel=4 --throttle=400 /mysqlbak/innobackupex 2>/mysqlbak/innobackupex/bak.log 1>/mysqlbak/innobackupex/

 查看日志信息,会出现

141011 09:44:02 innobackupex: Executing FLUSH ENGINE LOGS...141011 09:44:02 innobackupex: Waiting for log copying to finishxtrabackup: The latest check point (for incremental): '14275993522'xtrabackup: Stopping log copying thread..>> log scanned up to (14275993522)xtrabackup: Creating suspend file '/tmp/xtrabackup_log_copied' with pid '19659'141011 09:44:03 innobackupex: All tables unlocked141011 09:44:03 innobackupex: Waiting for ibbackup (pid=19659) to finishxtrabackup: Transaction log of lsn (14275990028) to (14275993522) was copied.innobackupex: Backup created in directory '/mysqlbak/innobackupex'141011 09:44:04 innobackupex: Connection to database server closedinnobackupex: You must use -i (--ignore-zeros) option for extraction of the tar stream.141011 09:44:04 innobackupex: completed OK!

表示备份成功。

 

二、全量恢复

恢复备份文件要保证datadir文件为空,否则会报如下的错误

[root@newbidb data]# innobackupex --user=root  /data/backup/IMPORTANT: Please check that the copy-back run completes successfully.      At the end of a successful copy-back run innobackupex      prints "completed OK!".Original data directory is not empty! at /usr/bin/innobackupex line 568. 

恢复第一步:应用日志。

[root@newbidb bin]# ./innobackupex --user=root --password=root1 --defaults-file=/etc/my.cnf --apply-log /u02/backup/

 

恢复第二步:拷贝文件。

[root@newbidb bin]# ./innobackupex --user=root --password=root1 --defaults-file=/etc/my.cnf --copy-back /u02/backup/

 

注释一下,常用的参数。

--defaults-file=/etc/my.cnf     恢复会使用my.cnf文件把需要恢复的文件,恢复到my.cnf指定的位置。

--apply-log                           这是备份时产生的日志,

--copy-back                         这是备份源,解压后的备份文件。

 

恢复需要一点点的时间,出现下面信息表示恢复成功。

innobackupex: Starting to copy InnoDB system tablespaceinnobackupex: in '/u02/backup'innobackupex: back to original InnoDB data directory '/u01/mysql/data'innobackupex: Copying '/u02/backup/ibdata1' to '/u01/mysql/data/ibdata1'innobackupex: Starting to copy InnoDB undo tablespacesinnobackupex: in '/u02/backup'innobackupex: back to '/u01/mysql/data'innobackupex: Starting to copy InnoDB log filesinnobackupex: in '/u02/backup'innobackupex: back to original InnoDB log directory '/u01/mysql/data'innobackupex: Copying '/u02/backup/ib_logfile1' to '/u01/mysql/data/ib_logfile1'innobackupex: Copying '/u02/backup/ib_logfile0' to '/u01/mysql/data/ib_logfile0'innobackupex: Finished copying back files. 

 

恢复第三步:修改文件权限。

cd 到data目录

chown -R mysql.mysql data/

 

可能出现的报错:

    1、出现下面错误,先初始化一下mysql

[root@newbidb support-files]# ./mysql.server start

Starting MySQL...The server quit without updating PID file (/u01/mysql/data/newbidb.pid).[FAILED]

[root@newbidb script]# ./mysql_install_db --basedir=/u01/mysql --no-defaults --skip-name-resolve --user=mysql --datadir=/u01/mysql/data

 

    2、权限:应该恢复使用的是root用户,但是MySQL需要MySQL用户去访问。

[root@newbidb support-files]# ./mysql.server restart

MySQL server PID file could not be found![FAILED]

Starting MySQL.The server quit without updating PID file (/u01/mysql/data/newbidb.pid).[FAILED]

 

    3、连接MySQL的时候

[root@newbidb bin]# ./mysql -uroot -p

Enter password:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

没有这个文件,touch  mysql.sock 并修改文件权限。

 




原标题:innobackupex使用实践

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流