基于Innobackupex的增备及恢复
MySQL的热备(物理备份)可以采取全备加增量备份的方式来减轻数据库I/O压力及系统资源的占用。增量备份主要是以全备或增量备份为基
MySQL的热备(物理备份)可以采取全备加增量备份的方式来减轻数据库I/O压力及系统资源的占用。增量备份主要是以全备或增量备份为基础,备份那些变更过的页面。其备份的原理是基于一个不断增长的LSN序列,这个LSN与Oracle的SCN类似。在恢复期间,我们需要将已提交的事务前滚,未提交的事务回滚。本文主要描述了增量备份及增量恢复。
1、增备的相关知识点
As not all information changes between each backup, the incremental backup strategy uses this to reduce the storage needs and the duration of making a backup. This can be done because each InnoDB page has a log sequence number, LSN, which acts as a version number of the entire database. Every time the database is modied, this number gets incremented. An incremental backup copies all pages since a specic LSN. Once the pages have been put together in their respective order, applying the logs will recreate the process that affected the database, yielding the data at the moment of the most recently created backup.
增备是备份上次以来发生变化的页面,通过增备可以减轻存储以及系统资源开销。增量备份主要针对于InnoDB,因为InnoDB采用了日志序列号(LSN)的方式。InnoDB的LSN是一个增长的序列,类似于Oracle的SCN,记录了InnoDB的变化情况。增量备份则是备份特定的LSN之后变化的情况。通过按序重组这些LSN即可将数据库恢复到故障点或任意时刻。
innobackupex --incremental /data/backups --incremental-lsn=1291135
innobackupex --incremental /data/backups --incremental-lsn=1358967
如上,我们可以使用--incremental-lsn选项来实施增量备份
Warning: This procedure only affects XtraDB or InnoDB-based tables. Other tables with a different storage engine, e.g. MyISAM, will be copied entirely each time an incremental backup is performed.
对于非XtraDB或者InnoDB存储引擎,热备方式依旧会全部备份所有的数据文件,索引文件,格式文件等。
Preparing an Incremental Backup with innobackupex Preparing incremental backups is a bit different than full ones. This is, perhaps, the stage where more attention is needed:
• First, only the committed transactions must be replayed on each backup. This will merge the base full backup with the incremental ones.
• Then, the uncommitted transaction must be rolled back in order to have a ready-to-use backup.
对于增量备份的Prepare阶段,有2个需要注意的地方,一个是提交的事务需要replayed,一个未提交的事务需要rollback。
If you replay the committed transactions and rollback the uncommitted ones on the base backup, you will not be able to add the incremental ones. If you do this on an incremental one, you won’t be able to add data from that moment and the remaining increments. Having this in mind, the procedure is very straight-forward using the --redo-only option, starting with the base backup:
如果在Prepare阶段replay了已提交的事务以及回滚了未提交的事务,则后续的增量备份无法添加到当前全备。因此在Prepare阶段全备应使用--redo-only选项。
--redo-only should be used when merging all incrementals except the last one. That’s why the previous line doesn’t contain the --redo-only option. Even if the --redo-only was used on the last step, backup would still be consistent but in that case server would perform the rollback phase.
对于存在多次增量的情形,仅仅只有最后一个增量不需要使用--redo-only 选项。如果使用了的话,rollback将由服务器启动的时候来完成。
2、演示增量备份
a、创建演示环境
robin@localhost[(none)]> create database tempdb;
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');
b、启动一个全备
SHELL> innobackupex --user=robin -password=xxx --port=3606 --socket=/tmp/mysql3606.sock --defaults-file=/etc/my3606.cnf \
> /hotbak/full --no-timestamp
--再新增一条记录,以便区分全备与增备
robin@localhost[tempdb]> insert into tb values(2,'Incbak');
c、启动一个增量备份
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
--........非重要信息忽略........
innobackupex: Using mysql server version 5.6.12-log --当前mysql的版本
innobackupex: Created backup directory /hotbak/inc -- 创建备份目录
innobackupex: Suspend file '/hotbak/inc/xtrabackup_suspended_2' -- 同时会创建相应的suspended目录供临时使用
--........非重要信息忽略........
xtrabackup: using the full scan for incremental backup
[01] Copying ./ibdata1 to /hotbak/inc/ibdata1.delta --可以看到生产了相应的delta文件,即增量部分
[01] ...done
>> log scanned up to (391476794)
xtrabackup: Creating suspend file '/hotbak/inc/xtrabackup_suspended_2' with pid '25001'
--........非重要信息忽略........
141222 14:55:08 innobackupex: Executing FLUSH TABLES WITH READ LOCK... --这个主要是针对非innodb
141222 14:55:08 innobackupex: All tables locked and flushed to disk

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Full table scanning may be faster in MySQL than using indexes. Specific cases include: 1) the data volume is small; 2) when the query returns a large amount of data; 3) when the index column is not highly selective; 4) when the complex query. By analyzing query plans, optimizing indexes, avoiding over-index and regularly maintaining tables, you can make the best choices in practical applications.

Yes, MySQL can be installed on Windows 7, and although Microsoft has stopped supporting Windows 7, MySQL is still compatible with it. However, the following points should be noted during the installation process: Download the MySQL installer for Windows. Select the appropriate version of MySQL (community or enterprise). Select the appropriate installation directory and character set during the installation process. Set the root user password and keep it properly. Connect to the database for testing. Note the compatibility and security issues on Windows 7, and it is recommended to upgrade to a supported operating system.

MySQL and MariaDB can coexist, but need to be configured with caution. The key is to allocate different port numbers and data directories to each database, and adjust parameters such as memory allocation and cache size. Connection pooling, application configuration, and version differences also need to be considered and need to be carefully tested and planned to avoid pitfalls. Running two databases simultaneously can cause performance problems in situations where resources are limited.

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.

Data Integration Simplification: AmazonRDSMySQL and Redshift's zero ETL integration Efficient data integration is at the heart of a data-driven organization. Traditional ETL (extract, convert, load) processes are complex and time-consuming, especially when integrating databases (such as AmazonRDSMySQL) with data warehouses (such as Redshift). However, AWS provides zero ETL integration solutions that have completely changed this situation, providing a simplified, near-real-time solution for data migration from RDSMySQL to Redshift. This article will dive into RDSMySQL zero ETL integration with Redshift, explaining how it works and the advantages it brings to data engineers and developers.

LaravelEloquent Model Retrieval: Easily obtaining database data EloquentORM provides a concise and easy-to-understand way to operate the database. This article will introduce various Eloquent model search techniques in detail to help you obtain data from the database efficiently. 1. Get all records. Use the all() method to get all records in the database table: useApp\Models\Post;$posts=Post::all(); This will return a collection. You can access data using foreach loop or other collection methods: foreach($postsas$post){echo$post->

In MySQL database, the relationship between the user and the database is defined by permissions and tables. The user has a username and password to access the database. Permissions are granted through the GRANT command, while the table is created by the CREATE TABLE command. To establish a relationship between a user and a database, you need to create a database, create a user, and then grant permissions.

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.
