Using XtraBackup for Physical Backup and Restoration

本文涉及的产品
RDS MySQL DuckDB 分析主实例,集群系列 4核8GB
RDS AI 助手,专业版
简介: This article mainly introduces the principles of MySQL database backup and restoration, so that you can better understand the ApsaraDB for RDS backup and restoration mechanisms.

DataWarehouse_FriendlyDatabaseDesign

Abstract: Xtrabackup is a MySQL database backup tool provided by Percona. According to the official introduction, "Percona XtraBackup is the world's only open-source, free MySQL hot backup software that performs non-blocking backups for InnoDB and XtraDB databases."

Background

This article mainly introduces the principles of MySQL database backup and restoration, so that you can better understand the ApsaraDB for RDS backup and restoration mechanisms. ApsaraDB for RDS uses mysqldump to logically back up data to the MySQL database. Xtrabackup can be used for a full physical backup at the instance level.

I. Logical Backup Using Mysqldump

Mysqldump is a powerful and important MySQL backup tool that that performs logical backups. It is worthwhile to fully familiarize yourself with the various backup parameters and restoration policies of mysqldump.

Back up a single database or a specified table in a single database:

mysqldump [OPTIONS] database [tb1] [tb2]…

Back up multiple databases:

mysqldump [OPTIONS] –databases [OPTIONS] DB1 [DB2 DB3...]

Back up all databases:

mysqldump [OPTIONS] –all-databases [OPTIONS]

II. Restoration from Physical Backup Using Xtrabackup

Xtrabackup is a MySQL database backup tool provided by Percona. According to the official introduction, "Percona XtraBackup is the world's only open-source, free MySQL hot backup software that performs non-blocking backups for InnoDB and XtraDB databases." Xtrabackup can be used to perform incremental or full physical backups for MySQL databases.

According to the official manual, you are recommend to use the innobackupex wrapper script and let innobackupex execute xtrabackup for you. If a mode is not specified at startup, innobackupex will start in backup mode by default.

This script starts xtrabackup with the -suspend-at-end option after which xtrabackup starts copying the InnoDB data files. When xtrabackup is finished, innobackupex will find that xtrabackup has created the xtrabackupsuspended2 file and then execute the FLUSH TABLES WITH READ LOCK operation. This statement adds read locks to all database tables and then begins copying other types of files.

If -ibbackup is not specified, innobackupex will automatically try to determine the xtrabackup binary to be used. The logic for determining the binary is as follows: first, determine whether the xtrabackup_binary file in the backup directory exists. If it exists, this script will determine the xtrabackup binary to use based on this file. Otherwise, the script will try to connect to the database server and determine the binary based on the server version. If the connection fails, xtrabackup will fail and you need to specify the binary file manually.

After the binary is determined, innobackupex will check whether the connection to the database server can be established. The execution logic is: establish a connection, execute a query, and close the connection. If everything runs normally, xtrabackup will start as a child process.

The FLUSH TABLES WITH READ LOCK statement serves to back up MyISAM and other non-InnoDB tables. This statement is executed after xtrabackup has backed up InnoDB data and log files. After that, the .frm, .MRG, .MYD, .MYI, .TRG, .TRN, .ARM, .ARZ, .CSM, .CSV, .par, and .opt files will be backed up.

After all of the above files are backed up, the innobackupex script will resume the execution of xtrabackup and wait for the transaction log files generated during its backup of the above logic. In the next step, tables are unlocked, slave nodes are started, and the connection to the server is disconnected. Then the script will delete the xtrabackupsuspended2 file, allowing the xtrabackup process to exit.

III. Database Backup Using innobackupex

Full backup:

innobackupex –user=root -p /home/backup/

Files after the backup:

During the backup, a directory named according to the current data and time will be created under the backup directory to store the backup files.

01

Descriptions of files:

(1) backup-my.cnf — Options and information for configurations used during backup

02

(2) ibdata — The tablespace files backed up

(3) xtrabackup_binary — The xtrabackup executable file used in backup

03

(4) xtrabackup_binlog_info — The binary log file that the MySQL server is currently using and the location of the binary log event as of the moment of the backup

04

(5) xtrabackup_checkpoints — Backup type (such as full or incremental), backup status (whether it is already in the prepared state), and LSN (log sequence number) range information

05

(6) xtrabackup_logfile — The redo log file for the backup

When using innobackupex for backup, you can also use the -no-timestamp option to block the command from automatically creating a directory named by time. This way the innobackupex command will create a BACKUP-DIR directory to store the backup data.

Preparing a full backup

In general, the data cannot be used for restoration operations yet upon the completion of the backup, because the backup data may contain transactions that have not yet been committed or transactions that have been committed but are not yet synchronized to the data file. Therefore, data files are still inconsistent at this moment. The main role of "prepare" is to make data files consistent by rolling back uncommitted transactions and synchronizing committed transactions to data files.

The above function can be executed using the -apply-log option for the innobackupex command.

innobackupex –apply-log /home/backup/2014-05-03_17-21-11/

The result of a successful execution is shown below:

06

In the preparation process, innobackupex usually also uses the -use-memory option to specify the size of the memory available. The default value is usually 100 MB. If there is enough memory available, you can allocate more memory to the prepare process to speed it up.

目录
相关文章
|
编解码 弹性计算 JavaScript
用云服务器实现B站直播录屏
利用云服务器ECS实现B站直播录屏、弹幕记录、投稿上传等操作。
3737 0
|
存储 C语言
【C语言】bool 关键字详解
`bool` 关键字在C语言中用于表示布尔类型(Boolean Type),它只有两个取值:`true`(真)和 `false`(假)。在标准的C90和C99中并没有直接支持布尔类型,但在C99标准中引入了`<stdbool.h>`头文件来提供布尔类型的支持。
545 1
|
存储 缓存 前端开发
前端模块化详解(CommonJS、AMD、CMD、ES Module)
本篇文章介绍了前端模块化的发展过程,以及常用的模块化规范。
1039 1
|
应用服务中间件 Nacos 微服务
阿里微服务注册中心 Nacos 启动报错 Unable to start embedded Tomcat
阿里微服务注册中心 Nacos 启动报错 Unable to start embedded Tomcat
2289 0
STM32:外部中断控制旋转编码器并计次
STM32:外部中断控制旋转编码器并计次
610 0
STM32:外部中断控制旋转编码器并计次
|
监控 网络协议 安全
DoS和DDoS攻击
DoS和DDoS攻击
5953 0
|
测试技术 Python
自动化测试教程(17)生成测试报告
631行print >>sys.stderr, ‘\nTime Elapsed: %s’ % (self.stopTime-self.startTime)改成:print (sys.stderr, ‘\nTime Elapsed: %s’ %(self.stopTime-self.startTime))我们之前的教程学会了,读取csv文件的方法,还有数据驱动,discover方法的使用,然后我们下面的内容讲解一下自动化的高级,这一小节我们学习一下自动化测试的生成测试报告。
自动化测试教程(17)生成测试报告
|
开发者
FTP 上传与解压缩文件 | 学习笔记
快速学习 FTP 上传与解压缩文件
FTP 上传与解压缩文件 | 学习笔记
|
存储 消息中间件 API
下沉式通知的一种实现 | Android悬浮窗Window应用
当你浏览公众号时来了一条新消息,通知在屏幕顶部会以自顶向下动画的形式入场,而且它是跨界面的全局浮窗(效果如下图)。虽然上一篇中抽象的浮窗工具类已经能实现这个需求。但本文在此基础上再封装一些更加友好的
599 0
下沉式通知的一种实现 | Android悬浮窗Window应用
|
分布式计算 数据可视化 搜索推荐
阿里云ACA该怎么考才是最好的选择?
阿里云ACA认证是阿里云大数据助理工程师认证,主要面向使用阿里云大数据产品的专业技术认证,是对学员掌握阿里云大数据产品技术技能水平的全面检验和能力认证。
812 0
阿里云ACA该怎么考才是最好的选择?