Xtrabackup全量备份与恢复mysql数据库
一、Xtrabackup简单概述:
Percona Xtrabackup是开源免费的MySQL数据库热备份软件,它能对InnoDB和XtraDB存储引擎的数据库非阻塞地备份(对于MyISAM的备份同样需要加表锁)。XtraBackup支持所有的Percona Server、MySQL、MariaDB和Drizzle。
XtraBackup优势 :
1、无需停止数据库进行InnoDB热备
2、增量备份MySQL
3、流压缩到传输到其它服务器
4、能比较容易地创建主从同步
5、备份MySQL时不会增大服务器负载
二、Xtrabackup的安装
首先列出以下我当前的服务器环境
下载Xtrabackup
[root@localhost softs]# wget http://www.percona.com/downloads/XtraBackup/LATEST/RPM/rhel5/i386/percona-xtrabackup-2.1.6-702.rhel5.i386.rpm--2014-01-14 10:06:41-- http://www.percona.com/downloads/XtraBackup/LATEST/RPM/rhel5/i386/percona-xtrabackup-2.1.6-702.rhel5.i386.rpm
Resolving www.percona.com... 74.121.199.234
……………………此处省略部分内容输出………………
100%[==========================>] 8,662,225 360K/s in 32s
2014-01-14 10:07:43 (1448 KB/s) - `percona-xtrabackup-2.1.6-702.rhel5.i386.rpm' saved [8662225/8662225]
rpm包直接安装
[root@localhost softs]# rpm -ivh percona-xtrabackup-2.1.6-702.rhel5.i386.rpm
error: Failed dependencies:
perl(DBD::mysql) is needed by percona-xtrabackup-2.1.6-702.rhel5.i386
这里需要解决依赖包的关系,我直接使用本地yum安装
[root@localhost softs]# yum install perl-DBD-MySQL -y
[root@localhost softs]# rpm -ivh percona-xtrabackup-2.1.6-702.rhel5.i386.rpm
Preparing... ########################################### [100%]
1:percona-xtrabackup ########################################### [100%]
再次尝试安装后成功
安装XtraBackup后,其实会有几个工具:
innobackupex:
这个是其实是下面三个工具的一个perl脚本封装,可以备份MyISAM, InnoDB, XtraDB表。
xtrabackup:
一个由C编译而来的二进制文件,只能备份InnoDB和XtraDB数据。
xbcrypt:
用来加密或解密备份的数据。
xbstream:
用来解压或压缩xbstream格式的压缩文件。
建议使用perl封装的innobackupex来作数据库备份,因为比较容易使用。
三、innobackupex相关参数说明
--defaults-file:指定my.cnf参数文件的位置
[root@localhost tmp]# innobackupex --user=root --password=123456 --defaults-file=/usr/local/mysql/etc/my.cnf --port=3306 /backup
InnoDB Backup Utility v1.5.1-xtrabackup; Copyright 2003, 2009 Innobase Oy
and Percona LLC and/or its affiliates 2009-2013. All Rights Reserved.
This software is published under
the GNU GENERAL PUBLIC LICENSE Version 2, June 1991.
Get the latest version of Percona XtraBackup, documentation, and help resources:
http://www.percona.com/xb/p
140119 05:46:11 innobackupex: Connecting to MySQL server with DSN 'dbi:mysql:;mysql_read_default_file=/usr/local/mysql/etc/my.cnf;mysql_read_default_group=xtrabackup;port=3306' as 'root' (using password: YES).
140119 05:46:11 innobackupex: Connected to MySQL server
140119 05:46:12 innobackupex: Executing a version check against the server...
140119 05:46:17 innobackupex: Done.
IMPORTANT: Please check that the backup run completes successfully.
At the end of a successful backup run innobackupex
prints "completed OK!".
innobackupex: Using mysql server version 5.6.12-debug-log
innobackupex: Created backup directory /backup/2014-01-19_05-46-19
140119 05:46:19 innobackupex: Starting ibbackup with command: xtrabackup_56 --defaults-file="/usr/local/mysql/etc/my.cnf" --defaults-group="mysqld" --backup --suspend-at-end --target-dir=/backup/2014-01-19_05-46-19 --tmpdir=/tmp
innobackupex: Waiting for ibbackup (pid=2458) to suspend
innobackupex: Suspend file '/backup/2014-01-19_05-46-19/xtrabackup_suspended_2'
xtrabackup_56 version 2.1.6 for MySQL server 5.6.11 Linux (i686) (revision id: 702)
xtrabackup: uses posix_fadvise().
xtrabackup: cd to /database
xtrabackup: using the following InnoDB configuration:
xtrabackup: innodb_data_home_dir = ./
xtrabackup: innodb_data_file_path = ibdata1:10M:autoextend
xtrabackup: innodb_log_group_home_dir = ./
xtrabackup: innodb_log_files_in_group = 2
xtrabackup: innodb_log_file_size = 50331648
>> log scanned up to (2000813)
InnoDB: Allocated tablespace 2, old maximum was 0
[01] Copying ./ibdata1 to /backup/2014-01-19_05-46-19/ibdata1
>> log scanned up to (2000813)
>> log scanned up to (2000813)
>> log scanned up to (2000813)
>> log scanned up to (2000813)
>> log scanned up to (2000813)
[01] ...done
[01] Copying ./mysql/innodb_index_stats.ibd to /backup/2014-01-19_05-46-19/mysql/innodb_index_stats.ibd
[01] ...done
[01] Copying ./mysql/slave_worker_info.ibd to /backup/2014-01-19_05-46-19/mysql/slave_worker_info.ibd
[01] ...done
[01] Copying ./mysql/innodb_table_stats.ibd to /backup/2014-01-19_05-46-19/mysql/innodb_table_stats.ibd
[01] ...done
[01] Copying ./mysql/slave_relay_log_info.ibd to /backup/2014-01-19_05-46-19/mysql/slave_relay_log_info.ibd
[01] ...done
[01] Copying ./mysql/slave_master_info.ibd to /backup/2014-01-19_05-46-19/mysql/slave_master_info.ibd
…………………………此处省略大量内容输出…………………………
innobackupex: Backing up file '/database/supor/productnotes.MYI'
innobackupex: Backing up file '/database/supor/productnotes.frm'
innobackupex: Backing up file '/database/supor/orders.frm'
innobackupex: Backing up file '/database/supor/customers.frm'
innobackupex: Backing up file '/database/supor/orderitems.frm'
innobackupex: Backing up file '/database/supor/productnotes.MYD'
140119 05:46:26 innobackupex: Finished backing up non-InnoDB tables and files
140119 05:46:26 innobackupex: Waiting for log copying to finish
xtrabackup: The latest check point (for incremental): '2000813'
xtrabackup: Stopping log copying thread.
.>> log scanned up to (2000813)
xtrabackup: Creating suspend file '/backup/2014-01-19_05-46-19/xtrabackup_log_copied' with pid '2458'
xtrabackup: Transaction log of lsn (2000813) to (2000813) was copied.
140119 05:46:27 innobackupex: All tables unlocked
innobackupex: Backup created in directory '/backup/2014-01-19_05-46-19'
140119 05:46:27 innobackupex: Connection to database server closed
140119 05:46:28 innobackupex: completed OK!
InnoDB Backup Utility v1.5.1-xtrabackup; Copyright 2003, 2009 Innobase Oy
and Percona LLC and/or its affiliates 2009-2013. All Rights Reserved.
IMPORTANT: Please check that the apply-log run completes successfully.
At the end of a successful apply-log run innobackupex
prints "completed OK!".
140119 06:00:47 innobackupex: Starting ibbackup with command: xtrabackup_56 --defaults-file="/usr/local/mysql/etc/my.cnf" --defaults-group="mysqld" --prepare --target-dir=/backup/2014-01-19_05-57-08 --tmpdir=/tmp
xtrabackup_56 version 2.1.6 for MySQL server 5.6.11 Linux (i686) (revision id: 702)
xtrabackup: Starting InnoDB instance for recovery.
xtrabackup: Using 104857600 bytes for buffer pool (set by --use-memory parameter)
InnoDB: The InnoDB memory heap is disabled
InnoDB: Mutexes and rw_locks use GCC atomic builtins
InnoDB: Compressed tables use zlib 1.2.3
InnoDB: Not using CPU crc32 instructions
……………………………………………………………………………………
[notice (again)]
If you use binary log and don't use any hack of group commit,
the binary log position seems to be:
xtrabackup: starting shutdown with innodb_fast_shutdown = 1
InnoDB: FTS optimize thread exiting.
I……………………………………………………………………………………
innobackupex: Creating directory '/database/mysql'
innobackupex: Copying '/backup/2014-01-19_05-57-08/mysql/help_keyword.frm' to '/database/mysql/help_keyword.frm'
innobackupex: Copying '/backup/2014-01-19_05-57-08/mysql/user.MYI' to '/database/mysql/user.MYI'
innobackupex: Copying '/backup/2014-01-19_05-57-08/mysql/help_relation.frm' to '/database/mysql/help_relation.frm'
innobackupex: Copying '/backup/2014-01-19_05-57-08/mysql/slow_log.CSV' to '/database/mysql/slow_log.CSV'
innobackupex: Copying '/backup/2014-01-19_05-57-08/mysql/time_zone_leap_second.frm' to '/database/mysql/time_zone_leap_second.frm'
innobackupex: Copying '/backup/2014-01-19_05-57-08/mysql/time_zone.MYI' to '/database/mysql/time_zone.MYI'
innobackupex: Copying '/backup/2014-01-19_05-57-08/mysql/time_zone_transition.MYI' to '/database/mysql/time_zone_transition.MYI'
innobackupex: Copying '/backup/2014-01-19_05-57-08/mysql/slave_master_info.frm' to '/database/mysql/slave_master_info.frm'
innobackupex: Copying '/backup/2014-01-19_05-57-08/mysql/help_category.MYI' to '/database/mysql/help_category.MYI'
innobackupex: Copying '/backup/2014-01-19_05-57-08/mysql/procs_priv.MYI' to '/database/mysql/procs_priv.MYI'
innobackupex: Copying '/backup/2014-01-19_05-57-08/mysql/help_category.MYD' to '/database/mysql/help_category.MYD'
innobackupex: Copying '/backup/2014-01-19_05-57-08/mysql/func.MYI' to '/database/mysql/func.MYI'
innobackupex: Copying '/backup/2014-01-19_05-57-08/mysql/tables_priv.frm' to '/database/mysql/tables_priv.frm'
innobackupex: Copying '/backup/2014-01-19_05-57-08/mysql/time_zone_transition.MYD' to '/database/mysql/time_zone_transition.MYD'
…………………………………………此处省略大量数据输出………………………………
innobackupex: Copying '/backup/2014-01-19_05-57-08/performance_schema/performance_timers.frm' to '/database/performance_schema/performance_timers.frm'
innobackupex: Creating directory '/database/test'
innobackupex: Starting to copy InnoDB system tablespace
innobackupex: in '/backup/2014-01-19_05-57-08'
innobackupex: back to original InnoDB data directory '/database'
innobackupex: Copying '/backup/2014-01-19_05-57-08/ibdata1' to '/database/ibdata1'
innobackupex: Starting to copy InnoDB undo tablespaces
innobackupex: in '/backup/2014-01-19_05-57-08'
innobackupex: back to '/database'
innobackupex: Starting to copy InnoDB log files
innobackupex: in '/backup/2014-01-19_05-57-08'
innobackupex: back to original InnoDB log directory '/database'
innobackupex: Copying '/backup/2014-01-19_05-57-08/ib_logfile0' to '/database/ib_logfile0'
innobackupex: Copying '/backup/2014-01-19_05-57-08/ib_logfile1' to '/database/ib_logfile1'
innobackupex: Finished copying back files.
140119 06:01:31 innobackupex: completed OK! ###恢复完成
[root@localhost database]# ls
ibdata1 ib_logfile0 ib_logfile1 mysql performance_schema test
[root@localhost database]# chown -R mysql.mysql /database/
[root@localhost ~]# /etc/init.d/mysql5 restart
Shutting down MySQL.. [ OK ]
Starting MySQL............ [ OK ]
全量备份恢复成功
http://blog.csdn.net/avilifans/article/details/18469549
Xtrabackup全量备份与恢复mysql数据库的更多相关文章
- 15、xtrabackup 全量备份
xtrabackup 全量备份与恢复 安装 yum install https://www.percona.com/downloads/XtraBackup/Percona-XtraBackup-2. ...
- xtrabackup全量备份和增(差)量备份
xtrabackup全量备份和增(差)量备份 1.xtrabackup全量备份和恢复 1)备份: innobackupex --default-file=/PATH/TO/DEFAULT --host ...
- Xtrabackup全量 增量备份详解
xtrabackup是Percona公司CTO Vadim参与开发的一款基于InnoDB的在线热备工具,具有开源,免费,支持在线热备,备份恢复速度快,占用磁盘空间小等特点,并且支持不同情况下的多种备份 ...
- xtrabackup 全量备份、恢复数据
1.全量备份 [root@localhost lib]##innobackupex --defaults-file=$defaults_file --user=$mysql_username --pa ...
- 从零开始的全栈工程师——MySQL数据库( Dos命令 ) ( phpstudy )
MySQL是一个关系型数据库,存在表的概念.结构,数据库可以存放多张表,每个表里可以存放多个字段,每个字段可以存放多个记录. phpstudy使用终端打开数据库的命令行 密码: root 数据库 查看 ...
- Xtrabackup 全量备份脚本
#!/bin/bash #备份文件的名字为当前主机的IP地址+tar.gz,例如172.16.103.1.tar.gz,且每次备份成功之后都会清空本地的备份目录. #相关目录 mkdir -p /xt ...
- xtrabackup全量备份+binlog基于时间点恢复
1.通过xtrabackup的备份恢复数据库. 2.找到start-position和binlog名称 cat xtrabackup_info 3.导出mysqlbinlog为sql文件,并确定恢复的 ...
- 大数据量的Mysql数据库备份策略
Centos下mysql常用的三种备份方法 http://www.centoscn.com/CentOS/Intermediate/2013/0807/1160.html xtrabackup备份 h ...
- 10.Solr4.10.3数据导入(DIH全量增量同步Mysql数据)
转载请出自出处:http://www.cnblogs.com/hd3013779515/ 1.创建MySQL数据 create database solr; use solr; DROP TABLE ...
随机推荐
- 使用wget -i下载多个文件
使用wget -i下载多个文件 命令: wget -i filelist.txt 说明: 首先,保存一份下载链接文件 cat > filelist.txt url1 url2 url3 url4
- python优秀库 - 使用envelopes发送邮件
这里有一个使用python自带lib发送邮件的例子(http://my.oschina.net/leejun2005/blog/74416),这里面讲解的很全面,可以供大家参考. 今天将的是使用env ...
- U-Boot在FL2440上移植(一)----修改系统时钟
<一>U-boot源码结构 图片来自韦东山的<嵌入式linux应用开发完全手册> U-boot下载地址:ftp://ftp.denx.de/pub/u-boot/ 交叉编译工具 ...
- 55. 略谈Lotus Notes的与众不同及系列文章至此的总结
在二十多年的悠久历史里,Lotus Notes发展出一整套独特的概念.技术和思维.由于它早期惊人的领先时代和后续发展中同样惊人的忠于传统,这位软件领域的寿星在如今发展更新速度远超往日和技术愈趋公开互通 ...
- Python用subprocess的Popen来调用系统命令
当我们须要调用系统的命令的时候,最先考虑的os模块.用os.system()和os.popen()来进行操作.可是这两个命令过于简单,不能完毕一些复杂的操作,如给执行的命令提供输入或者读取命令的输出, ...
- php - 微信 - 缓存access_token类。
可扩展性很强. <?php namespace LaneWeChat\Core; /** * 微信Access_Token的获取与过期检查 * Created by Lane. * User: ...
- ThinkPHP - 图片水印
图片添加水印 可以通过使用Image类的水印方法给图片添加水印支持,例如:water 给图片添加水印 用法 water($source, $water, $savename=null, $alph ...
- java读取远程url图片,得到宽高
链接地址:http://blog.sina.com.cn/s/blog_407a68fc0100nrb6.html import java.io.IOException;import java.awt ...
- A*算法(八数码问题)
#include <iostream> #include <cstring> #include <vector> #include <cmath> #i ...
- Week7(10月21日)
Part I:提问 =========================== 1.请为下图编写视图代码,视图中表单提交后,交给当前控制器和动作处理. 2.如何实现点击列标题排序功能? 3.分页时采用了 ...