Home Database Mysql Tutorial Percona Xtrabackup实现数据库备份和灾难恢复

Percona Xtrabackup实现数据库备份和灾难恢复

Jun 07, 2016 pm 04:07 PM

percona-xtrabackup软件包中中包含了两个工具,一个是xtrabackup,另一个是innobackupex,innobackupex由per进行封装,在对innod

目录
1、工具介绍
2、工具安装
3、备份策略及准备测试数据
4、全备份数据
5、增量备份数据
6、灾难恢复
7、总结

1、工具介绍
percona-xtrabackup软件包中中包含了两个工具,一个是xtrabackup,另一个是innobackupex,innobackupex由per进行封装,在对innodb表进行备份时会自动调用xtraback工具,所以对InnoDB表做备份的实际是xtrabackup这个工具,,xtrabackup也只能对innodb表做备份,这是一个专门对innodb开发的热备工具,而对myisam这样的其他引擎的表则由innobackupex来负责备份,若是全备份加增量的方案,那每次增量innobackupex工具对非innodb表都是全备份且会请求读锁。
xtrabackup对innodb表进行备份时不再只是简单复制文件,而是利用在innodb存储引擎层中的LSN(日志序列号)的新旧来识别这一数据页是否需要备份。
xtraback工具对innodb引擎完美支持真正的热备份,备份好的数据中数据文件与事务日志的文件因innodb cache等因素的存在,所以备份好的数据和事务日志中的数据往往是不一致的,所以,在做数据恢复时需要把事务日志中已提交的事务做redo,没有提交的事务做undo操作,这就是在做数据恢复时要做的准备工作,即prepare。
2、工具安装
系统环境:
[root@mariadb ~]# cat /etc/issue
CentOS release 6.4 (Final)
Kernel \r on an \m
[root@mariadb software]# uname -r
2.6.32-358.el6.x86_64

安装依赖包及percona-xtrabackup:
12 [root@mariadb ~]# yum -y install perl perl-devel libaio libaio-devel perl-Time-HiRes perl-DBD-MySQL
[root@mariadb ~]# rpm -ivh percona-xtrabackup-2.1.9-744.rhel6.x86_64.rpm  #安装的2.1.9版本

顺便把percona的工具集装上:
12 [root@mariadb ~]# yum -y install perl-IO-Socket-SSL  #percona-toolkit依赖包
[root@mariadb ~]# rpm -ivh percona-toolkit-2.2.13-1.noarch.rpm

3、备份策略及准备测试数据
采用先全备份加增量备份的方案。在利用xtrabackup对innodb表做备份工作时,建议mysql启用“innodb_file_per_table=1”变量,这样使每表都有一个自己的表空间,不然很难进行单表备份和还原。还有一点建议,二进制日志文件就不要与数据文件放在同一个目录了,你不想当数据丢失时,二进制日志也一同丢了。
测试数据:
mysql> SELECT VERSION();
+------------+
| VERSION()  |
+------------+
| 5.5.36-log |
+------------+
1 row in set (0.00 sec)
mysql> SHOW DATABASES; #创建了一个mydb1数据库
+--------------------+
| Database          |
+--------------------+
| information_schema |
| mydb1              |
| mysql              |
| performance_schema |
| test              |
+--------------------+
mysql> SELECT * FROM mydb1.tb1; #表中只有一条数据
+----+------+------+
| id | name | age  |
+----+------+------+
|  1 | tom  |  10 |
+----+------+------+

创建备份数据存放目录:
[root@mariadb ~]# mkdir -pv /backup/{fullbackup,incremental}
#fullbackup  存放全备份数据
#incremental 存放增量备份数据

创建复制用户:

mysql> GRANT RELOAD,LOCK TABLES,REPLICATION CLIENT ON *.* TO 'bkuser'@'localhost' IDENTIFIED BY '123456';
mysql> FLUSH PRIVILEGES;

4、全备份数据
[root@mariadb ~]# innobackupex --user=bkuser --password=123456 /backup/fullbackup/
#最后出现“150415 16:30:23  innobackupex: completed OK!”这样的信息表示备份完成
[root@mariadb ~]# ls /backup/fullbackup/2015-04-15_16-30-19/
backup-my.cnf  mysql              xtrabackup_binary      xtrabackup_logfile
ibdata1        performance_schema  xtrabackup_binlog_info
mydb1          test                xtrabackup_checkpoints
[root@mariadb ~]# cat /backup/fullbackup/2015-04-15_16-30-19/xtrabackup_checkpoints
backup_type = full-backuped
from_lsn = 0
to_lsn = 1644877
last_lsn = 1644877
compact = 0

5、增量备份数据
先做一些数据修改:
mysql> INSERT INTO mydb1.tb1 (name,age) VALUES ('jack',20);
mysql> SELECT * FROM tb1;  #增加一条数据
+----+------+------+
| id | name | age  |
+----+------+------+
|  1 | tom  |  10 |
|  2 | jack |  20 |
+----+------+------+

做第一次增量备份:
[root@mariadb ~]# innobackupex --user=bkuser --password=123456 --incremental /backup/incremental/ --incremental-basedir=/backup/fullbackup/2015-04-15_16-30-19/
[root@mariadb ~]# ls /backup/incremental/2015-04-15_16-42-00/
backup-my.cnf  mydb1              test                    xtrabackup_checkpoints
ibdata1.delta  mysql              xtrabackup_binary      xtrabackup_logfile
ibdata1.meta  performance_schema  xtrabackup_binlog_info
[root@mariadb ~]# cat /backup/incremental/2015-04-15_16-42-00/xtrabackup_checkpoints
backup_type = incremental
from_lsn = 1644877  #这是全备时的"to_lsn"值
to_lsn = 1645178
last_lsn = 1645178
compact = 0

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1673
14
PHP Tutorial
1277
29
C# Tutorial
1257
24
MySQL's Role: Databases in Web Applications MySQL's Role: Databases in Web Applications Apr 17, 2025 am 12:23 AM

The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

Explain the role of InnoDB redo logs and undo logs. Explain the role of InnoDB redo logs and undo logs. Apr 15, 2025 am 12:16 AM

InnoDB uses redologs and undologs to ensure data consistency and reliability. 1.redologs record data page modification to ensure crash recovery and transaction persistence. 2.undologs records the original data value and supports transaction rollback and MVCC.

MySQL vs. Other Programming Languages: A Comparison MySQL vs. Other Programming Languages: A Comparison Apr 19, 2025 am 12:22 AM

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages ​​such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages ​​have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

MySQL for Beginners: Getting Started with Database Management MySQL for Beginners: Getting Started with Database Management Apr 18, 2025 am 12:10 AM

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA

MySQL vs. Other Databases: Comparing the Options MySQL vs. Other Databases: Comparing the Options Apr 15, 2025 am 12:08 AM

MySQL is suitable for web applications and content management systems and is popular for its open source, high performance and ease of use. 1) Compared with PostgreSQL, MySQL performs better in simple queries and high concurrent read operations. 2) Compared with Oracle, MySQL is more popular among small and medium-sized enterprises because of its open source and low cost. 3) Compared with Microsoft SQL Server, MySQL is more suitable for cross-platform applications. 4) Unlike MongoDB, MySQL is more suitable for structured data and transaction processing.

Explain the InnoDB Buffer Pool and its importance for performance. Explain the InnoDB Buffer Pool and its importance for performance. Apr 19, 2025 am 12:24 AM

InnoDBBufferPool reduces disk I/O by caching data and indexing pages, improving database performance. Its working principle includes: 1. Data reading: Read data from BufferPool; 2. Data writing: After modifying the data, write to BufferPool and refresh it to disk regularly; 3. Cache management: Use the LRU algorithm to manage cache pages; 4. Reading mechanism: Load adjacent data pages in advance. By sizing the BufferPool and using multiple instances, database performance can be optimized.

MySQL: Structured Data and Relational Databases MySQL: Structured Data and Relational Databases Apr 18, 2025 am 12:22 AM

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.

Learning MySQL: A Step-by-Step Guide for New Users Learning MySQL: A Step-by-Step Guide for New Users Apr 19, 2025 am 12:19 AM

MySQL is worth learning because it is a powerful open source database management system suitable for data storage, management and analysis. 1) MySQL is a relational database that uses SQL to operate data and is suitable for structured data management. 2) The SQL language is the key to interacting with MySQL and supports CRUD operations. 3) The working principle of MySQL includes client/server architecture, storage engine and query optimizer. 4) Basic usage includes creating databases and tables, and advanced usage involves joining tables using JOIN. 5) Common errors include syntax errors and permission issues, and debugging skills include checking syntax and using EXPLAIN commands. 6) Performance optimization involves the use of indexes, optimization of SQL statements and regular maintenance of databases.

See all articles