使用XtraBackup备份恢复MariaDB数据库
使用innobakupex备份时,其会调用xtrabackup备份所有的InnoDB表,复制所有关于表结构定义的相关文件(.frm)、以及MyISAM、MERGE、
使用xtrabackup进行备份
Xtrabackup简介
Xtrabackup是由percona提供的mysql数据库备份工具,据官方介绍,这也是世界上惟一一款开源的能够对innodb和xtradb数据库进行热备的工具。特点:
(1)备份过程快速、可靠;
(2)备份过程不会打断正在执行的事务;
(3)能够基于压缩等功能节约磁盘空间和流量;
(4)自动实现备份检验;
(5)还原速度快;
官方介绍和下载地址:https://www.percona.com/software/percona-xtrabackup
xtrabackup安装
官方有系统rpm包版的软件,可以下载rpm包版的软件直接安装,由于xtrabackup是使用perl脚本编写的所以需要安装perl-DBD-MySQL否则会报依赖。
[root@MariaDB~]# yum -y install perl-DBD-MySQL
[root@MariaDB~]# rpm -ivh percona-xtrabackup-2.2.3-4982.el6.x86_64.rpm
innobackupex: 客户端工具, 以mysql协议连入mysqld,不支持离线备份,但是支持离线恢复
--------------------------------------分割线 --------------------------------------
在 CentOS/RHEL/Scientific Linux 6 下安装 LAMP (Apache with MariaDB and PHP)
MariaDB Proxy读写分离的实现
Linux下编译安装配置MariaDB数据库的方法
CentOS系统使用yum安装MariaDB数据库
安装MariaDB与MySQL并存
MySQL管理之使用XtraBackup进行热备
MySQL开源备份工具Xtrabackup备份部署
MySQL Xtrabackup备份和恢复
用XtraBackup实现MySQL的主从复制快速部署【主不锁表】
安装和使用 Percona 推出的 Xtrabackup 备份 MySQL
[翻译]Ubuntu 14.04 (Trusty) Server 安装 MariaDB
--------------------------------------分割线 --------------------------------------
一次完全备份和恢复
1、完全备份
使用innobakupex备份时,其会调用xtrabackup备份所有的InnoDB表,复制所有关于表结构定义的相关文件(.frm)、以及MyISAM、MERGE、CSV和ARCHIVE表的相关文件,同时还会备份触发器和数据库配置信息相关的文件。这些文件会被保存至一个以时间命令的目录中。
在使用innobackupex进行备份时,还可以使用--no-timestamp选项来阻止命令自动创建一个以时间命名的目录;如此一来,innobackupex命令将会创建一个BACKUP-DIR目录来存储备份数据。
示例:
[root@MariaDB~]# innobackupex --user=root --password=centos /backup/
[root@MariaDB~]# ll /backup/
total4
drwxr-xr-x2 root root 4096 Jun 16 02:28 2015-06-16_02-28-54
备份时报了一个错
innobackupex:Error: The xtrabackup child process has died at /usr/bin/innobackupex line2672.
解决方法:修改innodb日志文件大小为5M,修改完成重启服务生效
12 [root@MariaDB~]# vim /etc/my.cnf
innodb_log_file_size= 5M
备份完成之后在/backup目录下就有了如下内容
[root@MariaDB ~]# ll /backup/2015-06-15_23-49-43/
total 18468
-rw-r--r-- 1 root root 356 Jun 15 23:49 backup-my.cnf
drwxr-xr-x 2 root root 4096 Jun 15 23:49 hellodb
-rw-r----- 1 root root 18874368 Jun 15 23:49ibdata1
drwxr-xr-x 2 root root 4096 Jun 15 23:49 mysql
drwxr-xr-x 2 root root 4096 Jun 15 23:49 performance_schema
drwxr-xr-x 2 root root 4096 Jun 15 23:49 test
-rw-r--r-- 1 root root 23 Jun 15 23:49 xtrabackup_binlog_info
-rw-r----- 1 root root 89 Jun 15 23:49 xtrabackup_checkpoints
-rw-r--r-- 1 root root 559 Jun 15 23:49 xtrabackup_info
-rw-r----- 1 root root 2560 Jun 15 23:49 xtrabackup_logfile
文件说明:
(1)xtrabackup_checkpoints—— 备份类型(如完全或增量)、备份状态(如是否已经为prepared状态)和LSN(日志序列号)范围信息;
每个InnoDB页(通常为16k大小)都会包含一个日志序列号,即LSN。LSN是整个数据库系统的系统版本号,每个页面相关的LSN能够表明此页面最近是如何发生改变的。
[root@MariaDB 2015-06-15_23-49-43]# catxtrabackup_checkpoints
backup_type = full-backuped #备份类型,full-backuped表示完全备份
from_lsn = 0 #日志序列开始
to_lsn = 1597945 #最大日志序列号
last_lsn = 1597945 #当前日志序列号
compact = 0 #表示没有打包
(2)xtrabackup_binlog_info —— mysql服务器当前正在使用的二进制日志文件及至备份这一刻为止二进制日志事件的位置。
[root@MariaDB 2015-06-15_23-49-43]# catxtrabackup_binlog_info
mysql-bin.000005 245
(3)backup-my.cnf —— 备份命令用到的配置选项信息和备份无关的不会记录,备份配置文件的话需要单独备份
[root@MariaDB 2015-06-15_23-49-43]# catbackup-my.cnf
# This MySQL options file was generated byinnobackupex.
# The MySQL server
[mysqld]
innodb_checksum_algorithm=innodb
innodb_log_checksum_algorithm=innodb
innodb_data_file_path=ibdata1:10M:autoextend
innodb_log_files_in_group=2
innodb_log_file_size=5242880
innodb_fast_checksum=0
innodb_page_size=16384
innodb_log_block_size=512
innodb_undo_tablespaces=0
(4)xtrabackup_info —— 记录了mariadb的版本信息和一些属性信息,还原是检测版本匹配度时用到
[root@MariaDB 2015-06-15_23-49-43]# catxtrabackup_info
uuid = 25b79086-1376-11e5-980a-000c29bad792
name =
tool_name = innobackupex
tool_command = --user=root --password=... /backup/
tool_version = 1.5.1-xtrabackup
ibbackup_version = xtrabackup version 2.2.3 basedon MySQL server 5.6.17 Linux (x86_64) (revision id: )
server_version = 5.5.43-MariaDB-log
start_time = 2015-06-15 23:49:43
end_time = 2015-06-15 23:49:46
lock_time = 1
binlog_pos = filename 'mysql-bin.000005', position245
innodb_from_lsn = 0
innodb_to_lsn = 1597945
partial = N
incremental = N
format = file
compact = N
compressed = N
encrypted = N

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

AI Hentai Generator
Generate AI Hentai for free.

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

This article explores optimizing MySQL memory usage in Docker. It discusses monitoring techniques (Docker stats, Performance Schema, external tools) and configuration strategies. These include Docker memory limits, swapping, and cgroups, alongside

This article addresses MySQL's "unable to open shared library" error. The issue stems from MySQL's inability to locate necessary shared libraries (.so/.dll files). Solutions involve verifying library installation via the system's package m

The article discusses using MySQL's ALTER TABLE statement to modify tables, including adding/dropping columns, renaming tables/columns, and changing column data types.

This article compares installing MySQL on Linux directly versus using Podman containers, with/without phpMyAdmin. It details installation steps for each method, emphasizing Podman's advantages in isolation, portability, and reproducibility, but also

This article provides a comprehensive overview of SQLite, a self-contained, serverless relational database. It details SQLite's advantages (simplicity, portability, ease of use) and disadvantages (concurrency limitations, scalability challenges). C

This guide demonstrates installing and managing multiple MySQL versions on macOS using Homebrew. It emphasizes using Homebrew to isolate installations, preventing conflicts. The article details installation, starting/stopping services, and best pra

Article discusses configuring SSL/TLS encryption for MySQL, including certificate generation and verification. Main issue is using self-signed certificates' security implications.[Character count: 159]

Article discusses popular MySQL GUI tools like MySQL Workbench and phpMyAdmin, comparing their features and suitability for beginners and advanced users.[159 characters]
