Using XtraBackup for Physical Backup and Restoration

简介: 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.

目录
相关文章
|
开发工具 Android开发 数据安全/隐私保护
搞机:AS自带模拟器AVD Root 和 Xposed安装(上)
AS自带模拟器AVD Root 和 Xposed安装
2017 0
|
5月前
|
存储 JSON 缓存
告别数据混乱!数据库设计三范式从入门到实践
数据库小学妹带你轻松入门三范式!用“建房打地基”比喻,讲清1NF(列不可分)、2NF(消除部分依赖)、3NF(消除传递依赖),直击数据冗余、更新异常等痛点。附实战拆表案例与反范式化提醒,助你设计出结构清晰、稳定高效的数据库!
|
人工智能 算法 测试技术
轻量高效,8B 性能强劲书生科学多模态模型Intern-S1-mini开源
继 7 月 26 日开源『书生』科学多模态大模型 Intern-S1 之后,上海人工智能实验室(上海AI实验室)在8月23日推出了轻量化版本 Intern-S1-mini。
1723 49
Java 数组学习笔记
本文整理Java数组常用操作:遍历、求和、查找、最值及二维数组行求和等典型练习,涵盖静态初始化、元素翻倍、去极值求平均等实例,帮助掌握数组基础与应用。
|
人工智能 自然语言处理 前端开发
从前端视角聊聊通义灵码使用经验,如何更好地提升研发效率
从前端视角聊聊通义灵码使用经验,如何更好地提升研发效率
|
iOS开发 MacOS Windows
硬盘变卡疑似坏道?教你快速检测坏道的方法
怎么判断是不是硬盘出了问题?有没有简单实用的方法来检测硬盘坏道?今天这篇文章就来教你几种快速检测坏道的方法,推荐几款靠谱工具,普通用户也能轻松上手。
|
机器学习/深度学习
苹果发布高效双EMA梯度优化方法,适配Transformer、Mamba模型
苹果公司在arXiv上发布论文《The AdEMAMix Optimizer: Better, Faster, Older》,提出了一种基于双指数移动平均(EMA)的新型优化器AdEMAMix。该优化器通过使用快速和慢速EMA,同时利用近期和远期梯度信息,显著提升了模型训练的速度和效果。实验表明,AdEMAMix在语言建模和图像分类等任务上表现出色,尤其在大型语言模型的训练中,相比传统优化器如AdamW,训练效率提高了95%。
505 32
|
数据挖掘 项目管理 调度
「软件项目管理」一文详解软件项目质量计划
该文章全面介绍了软件项目质量计划的制定方法,涵盖了质量模型、质量管理过程、质量保证与控制技术,并提出了软件质量改善的具体建议,帮助项目管理人员有效地提升软件产品的质量水平。
「软件项目管理」一文详解软件项目质量计划
|
安全 搜索推荐
ChatGPT高效提问—prompt实践(健康助手)
ChatGPT高效提问—prompt实践(健康助手)
695 0
|
监控 数据处理 API
提升DataFrame处理性能:高效数据操作的实战技巧
【5月更文挑战第19天】本文介绍了优化Pandas DataFrame性能的7个技巧:选择合适的数据类型、避免使用循环、使用查询优化、减少内存使用、利用并行处理、使用适当索引以及监控和分析性能。通过这些策略,可以提升数据处理效率,尤其适用于大规模数据集。例如,选择正确的数据类型、使用向量化操作和优化索引能有效提高DataFrame的操作速度。

热门文章

最新文章