Home Database Mysql Tutorial 基于Innobackupex的完全恢复

基于Innobackupex的完全恢复

Jun 07, 2016 pm 04:12 PM
mysql based on recover

对于MySQL的完全恢复,我们可以借助于Innobackupex的多重备份加上binlog来将数据库恢复到故障点。这里的完全恢复是相对于时点恢复(也叫不完全恢复)。本文主要演示了基于Innobackupex如何做一个完全恢复,供大家参考。 1、完全恢复的概念 完全恢复是指使用备份

对于MySQL的完全恢复,我们可以借助于Innobackupex的多重备份加上binlog来将数据库恢复到故障点。这里的完全恢复是相对于时点恢复(也叫不完全恢复)。本文主要演示了基于Innobackupex如何做一个完全恢复,供大家参考。
1、完全恢复的概念

 

完全恢复是指使用备份加上binlog日志将数据库恢复到最新的时间点。
2、演示备份过程

 

a、创建演示环境
robin@localhost[(none)]> show variables like 'version';  --当前MySQL版本
+---------------+------------+
| Variable_name | Value      |
+---------------+------------+
| version       | 5.6.12-log |
+---------------+------------+

robin@localhost[(none)]> use tempdb;  
 
robin@localhost[tempdb]> create table tb(id smallint,val varchar(20));  
 
robin@localhost[tempdb]> insert into tb  values(1,'fullbak');  

--创建一个全备
SHELL> innobackupex --user=robin -password=xxx --port=3606 --socket=/tmp/mysql3606.sock --defaults-file=/etc/my3606.cnf \   
> /hotbak/full --no-timestamp   

b、创建一个增备
--在创建增备前插入一条记录到tb
robin@localhost[tempdb]> insert into tb values(2,'Incbak');  
 
SHELL> innobackupex --user=robin -password=xxx --port=3606 --socket=/tmp/mysql3606.sock --defaults-file=/etc/my3606.cnf \   
> --incremental /hotbak/inc --incremental-basedir=/hotbak/full --no-timestamp 
Copy after login
3、演示恢复过程
--再次新增一条记录,该记录在保存在binlog,而不会存在于任何备份,这条记录用于验证完全恢复 robin@localhost[tempdb]> insert into tb values(3,'Inbinlog'); Query OK, 1 row affected (0.01 sec) --当前的binlog位置 robin@localhost[(none)]> show master status; +--------------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +--------------------+----------+--------------+------------------+-------------------+ | inst3606bin.000014 | 1200 | | | | +--------------------+----------+--------------+------------------+-------------------+ --使用binlog events命令来查看我们最后insert的一条记录 robin@localhost[(none)]> show binlog events in 'inst3606bin.000014' limit 7,10; +--------------------+------+------------+-----------+-------------+---------------------------------------------------+ | Log_name | Pos | Event_type | Server_id | End_log_pos | Info | +--------------------+------+------------+-----------+-------------+---------------------------------------------------+ | inst3606bin.000014 | 668 | Query | 3606 | 751 | BEGIN | | inst3606bin.000014 | 751 | Query | 3606 | 862 | use `tempdb`; insert into tb values(2,'Incbak') | | inst3606bin.000014 | 862 | Xid | 3606 | 893 | COMMIT /* xid=449096 */ | | inst3606bin.000014 | 893 | Query | 3606 | 973 | FLUSH ENGINE LOGS | | inst3606bin.000014 | 973 | Query | 3606 | 1056 | BEGIN | | inst3606bin.000014 | 1056 | Query | 3606 | 1169 | use `tempdb`; insert into tb values(3,'Inbinlog') | | inst3606bin.000014 | 1169 | Xid | 3606 | 1200 | COMMIT /* xid=449997 */ | +--------------------+------+------------+-----------+-------------+---------------------------------------------------+ --查看binlog的位置 robin@localhost[(none)]> show variables like 'log_bin_basename'; +------------------+------------------------------------+ | Variable_name | Value | +------------------+------------------------------------+ | log_bin_basename | /data/inst3606/log/bin/inst3606bin | +------------------+------------------------------------+ a、先做基于全备的apply,注意,此时使用了--redo-only SHELL> innobackupex --apply-log --redo-only --user=robin -password=xxx --port=3606 \ > --defaults-file=/etc/my3606.cnf /hotbak/full b、基于增备的apply, --此时没有--redo-only,如果有多个增备,仅仅最后一个增备无需指定--redo-only SHELL> innobackupex --apply-log --user=robin -password=xxx --port=3606 --defaults-file=/etc/my3606.cnf \ > /hotbak/full --incremental-dir=/hotbak/inc c、进行copy back SHELL> mysqldown -P3606 --copy back前关闭实例 SHELL> netstat -nltp|grep mysql|grep 3606 SHELL> mv /data/inst3606/data3606 /data/inst3606/data3606bk SHELL> mkdir -p /data/inst3606/data3606 SHELL> innobackupex --user=robin -password=xxx --port=3606 --copy-back /hotbak/full --defaults-file=/etc/my3606.cnf SHELL> chown -R mysql:mysql /data/inst3606/data3606 d、启动恢复后的实例 SHELL> mysqld_safe --defaults-file=/etc/my3606.cnf & SHELL> sql -P3606 robin@localhost[(none)]> use tempdb; --如下,我们可以看到记录3, 'Inbinlog'记录并没有被恢复 robin@localhost[tempdb]> se【本文来自鸿网互联 (http://www.68idc.cn)】lect * from tb; +------+---------+ | id | val | +------+---------+ | 1 | fullbak | --Author: Leshami | 2 | Incbak | --Blog : http://blog.csdn.net/leshami +------+---------+ 2 rows in set (0.00 sec) e、使用binlog做完全恢复 SHELL> cd /hotbak/inc/ SHELL> more xtrabackup_binlog_info --从innobackupex获得binlog的位置 inst3606bin.000014 893 --使用mysqlbinlog 追加的最新 SHELL> mysqlbinlog /data/inst3606/log/bin/inst3606bin.000014 --start-position=893 \ > |mysql -urobin -pxxx -P3606 -S /tmp/mysql3606.sock --验证,可以看到第3条记录以及被恢复 SHELL> mysql -urobin -pxxx -P3606 -S /tmp/mysql3606.sock -e "select * from tempdb.tb" Warning: Using a password on the command line interface can be insecure. +------+----------+ | id | val | +------+----------+ | 1 | fullbak | | 2 | Incbak | | 3 | Inbinlog | +------+----------+ 4、小结
f、使用mysqlbinlog方式将日志追加到最新时刻

 

 

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months 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)

MySQL: The Ease of Data Management for Beginners MySQL: The Ease of Data Management for Beginners Apr 09, 2025 am 12:07 AM

MySQL is suitable for beginners because it is simple to install, powerful and easy to manage data. 1. Simple installation and configuration, suitable for a variety of operating systems. 2. Support basic operations such as creating databases and tables, inserting, querying, updating and deleting data. 3. Provide advanced functions such as JOIN operations and subqueries. 4. Performance can be improved through indexing, query optimization and table partitioning. 5. Support backup, recovery and security measures to ensure data security and consistency.

MySQL: Simple Concepts for Easy Learning MySQL: Simple Concepts for Easy Learning Apr 10, 2025 am 09:29 AM

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

How to open phpmyadmin How to open phpmyadmin Apr 10, 2025 pm 10:51 PM

You can open phpMyAdmin through the following steps: 1. Log in to the website control panel; 2. Find and click the phpMyAdmin icon; 3. Enter MySQL credentials; 4. Click "Login".

How to create navicat premium How to create navicat premium Apr 09, 2025 am 07:09 AM

Create a database using Navicat Premium: Connect to the database server and enter the connection parameters. Right-click on the server and select Create Database. Enter the name of the new database and the specified character set and collation. Connect to the new database and create the table in the Object Browser. Right-click on the table and select Insert Data to insert the data.

MySQL and SQL: Essential Skills for Developers MySQL and SQL: Essential Skills for Developers Apr 10, 2025 am 09:30 AM

MySQL and SQL are essential skills for developers. 1.MySQL is an open source relational database management system, and SQL is the standard language used to manage and operate databases. 2.MySQL supports multiple storage engines through efficient data storage and retrieval functions, and SQL completes complex data operations through simple statements. 3. Examples of usage include basic queries and advanced queries, such as filtering and sorting by condition. 4. Common errors include syntax errors and performance issues, which can be optimized by checking SQL statements and using EXPLAIN commands. 5. Performance optimization techniques include using indexes, avoiding full table scanning, optimizing JOIN operations and improving code readability.

How to create a new connection to mysql in navicat How to create a new connection to mysql in navicat Apr 09, 2025 am 07:21 AM

You can create a new MySQL connection in Navicat by following the steps: Open the application and select New Connection (Ctrl N). Select "MySQL" as the connection type. Enter the hostname/IP address, port, username, and password. (Optional) Configure advanced options. Save the connection and enter the connection name.

How to recover data after SQL deletes rows How to recover data after SQL deletes rows Apr 09, 2025 pm 12:21 PM

Recovering deleted rows directly from the database is usually impossible unless there is a backup or transaction rollback mechanism. Key point: Transaction rollback: Execute ROLLBACK before the transaction is committed to recover data. Backup: Regular backup of the database can be used to quickly restore data. Database snapshot: You can create a read-only copy of the database and restore the data after the data is deleted accidentally. Use DELETE statement with caution: Check the conditions carefully to avoid accidentally deleting data. Use the WHERE clause: explicitly specify the data to be deleted. Use the test environment: Test before performing a DELETE operation.

How to use single threaded redis How to use single threaded redis Apr 10, 2025 pm 07:12 PM

Redis uses a single threaded architecture to provide high performance, simplicity, and consistency. It utilizes I/O multiplexing, event loops, non-blocking I/O, and shared memory to improve concurrency, but with limitations of concurrency limitations, single point of failure, and unsuitable for write-intensive workloads.

See all articles