Home Database Mysql Tutorial xtrabackup 安装及应用_MySQL

xtrabackup 安装及应用_MySQL

Jun 01, 2016 pm 01:49 PM
Install Open source

bitsCN.com


xtrabackup 是 percona 的一个开源项目,可以热备份innodb ,XtraDB,和MyISAM(会锁表)

官方网址http://www.percona.com/docs/wiki/percona-xtrabackup:start

 

 

安装:
rpm -ivh --nodephotoshop/ target=_blank class=infotextkey>ps xtrabackup-1.2-22.rhel5.x86_64.rpm
--nodephotoshop/ target=_blank class=infotextkey>ps(不检查软件间的依赖关系),因为安装xtrabackup需要mysql_client,但是我的是通过源码安装的。

 

前奏:
环境变量要设置正确
比如 export PATH=$PATH:/usr/local/mysql/bin   如果mysql没有设置到PATH里 会报错。

 

1.innobackupex-1.5.1 和 xtrabackup备份详解
========================================================================================
innobackupex-1.5.1会根据/et/my.cnf来确定MySQL的数据位置。

1.普通备份:
innobackupex-1.5.1 [--defaults-file=/etc/my.cnf]  --user=root [--host=192.168.1.52] [--password=xxx] [--port=3306]
 /data/back_data/  2>/data/back_data/1.log   

备份的目录是/data/back_data/
这里的2>/data/back_data/1.log,是将备份过程中的输出信息重定向到1.log

innobackupex-1.5.1 --slave-info .....
--slave-info会记录复制主日志的 复制点,便于重新做复制用。(用在备份从机器用)

备份后的文件:
xtrabackup_binlog_info    -- 存放binlog的信息。(binlog需要另外拷贝备份,如果需要binlog的话)
xtrabackup_checkpoints    -- 存放备份的起始位置和结束位置。


恢复:
首先停掉数据库,然后删除数据库目录下的所有数据库文件.
cd /data/mysql_data
rm -rf *     # 删除数据目录里的所有文件

innobackupex-1.5.1 --user=root --apply-log /data/back_data/2010-10-26_16-09-37   # 应用日志
innobackupex-1.5.1 --user=root --copy-back /data/back_data/2010-10-26_16-09-37

默认innobackupex-1.5.1会将二进制日志信息存放在文件xtrabackup_binlog_info中发(方便做Slave)。
cd /data
chown -R mysql:mysql mysql_data/
重启mysql服务

 


2.打包(Tar)备份:
innobackupex-1.5.1 --user=root [--password=xxx] --stream=tar /data/back_data/2/  2>/data/back_data/2.log  1>/data/back_data/2.tar

还原:
cd /data/back_data/2/
tar ixvf 2.tar
root@mablevi-desktop:/data/back_data/2# ls
2.tar  backup-my.cnf  ibdata1  ibdata2  mablevi  mysql  xtrabackup_binlog_info  xtrabackup_checkpoints  xtrabackup_logfile
准备还原
root@mablevi-desktop:~# innobackupex-1.5.1 --user=xxx [--password=xxx] --apply-log /data/back_data/
......
innobackupex: completed OK!

删除数据目录里的所有文件
rm -rf /data/mysql_data/*
拷贝:
root@mablevi-desktop:~# innobackupex-1.5.1 --user=xxx [--password=xxx] --copy-back /data/back_data/
......
innobackupex: completed OK!

cd /data
chown -R mysql:mysql mysql_data/
重启mysql服务


3. 压缩(tar gzip)备份
innobackupex-1.5.1 --user=root [--password=xxx] --stream=tar 
/data/back_data/2/  2>/data/back_data/2.log | gzip > /data/back_data/2.tar.gz 
这里使用了管道|将innobackupex-1.5.1作为gzip的标准输入。恢复,只需要使用tar -izxvf 解压对应的文件后,操作完全同普通备份。

还原:
使用tar –izxvf 解压对应的文件后,操作完全同普通备份。
cd /data/back_data/2/
tar ixvf 2.tar

root@mablevi-desktop://data/back_data/2# ls
backup-my.cnf  ibdata1  ibdata2  mablevi  mysql  xtrabackup_binlog_info  xtrabackup_checkpoints  xtrabackup_logfile
准备还原:
root@mablevi-desktop:~# innobackupex-1.5.1 --user=xxx [--password=xxx] --apply-log /data/back_data/2/
......
innobackupex: completed OK!

删除数据目录里的所有文件
rm -rf /data/mysql_data/*

root@mablevi-desktop:/data/back_data/2# innobackupex-1.5.1 --user=xxx [--password=xxx] --copy-back /data/back_data/2/

cd /data
chown -R mysql:mysql mysql_data/
重启mysql服务

 

 

---------------------------------------------------------------------------------------------------------------------
xtrabackup 备份和恢复

备份:
xtrabackup --defaults-file=/etc/my.cnf --backup --target-dir=/data/back_data/

恢复:
需要执行两次xtrabackup --prepare
xtrabackup --defaults-file=/etc/my.cnf --prepare --target-dir=/data/back_data/
xtrabackup --defaults-file=/etc/my.cnf --prepare --target-dir=/data/back_data/

注意,xtrabackup只备份数据文件,并不备份数据表结构(.frm),所以使用xtrabackup恢复的时候,你必须有对应表结构文件(.frm)。


增量备份:
1. 全量备份
xtrabackup --defaults-file=/etc/my.cnf --backup --target-dir=/data/back_data/
2. 增量备份
xtrabackup --defaults-file=/etc/my.cnf --backup --target-dir=/data/back_data_inc/ --incremental-basedir=/data/back_data/
在增量备份的目录下,数据文件都是以.delta结尾的。增量备份只备份上一次全量备份后被修改过的page,所以增量备份只暂用较少的空间。

增量备份可以在增量备份的基础上增量。

 

增量备份恢复:
我们需要分别对全量、增量备份各做一次prepare操作。
xtrabackup --defaults-file=/etc/my.cnf --prepare --target-dir=/data/back_data/2010-10-26_16-09-37
xtrabackup --prepare --target-dir=/data/back_data/2010-10-26_16-09-37 --incremental-dir=/data/back_data_inc
xtrabackup --prepare --target-dir=/data/back_data/ #这一步不是必须的 
这样,/data/back_data/下的数据文件就可以直接放到你的MySQL数据目录下,恢复数据了。
再次提醒,xtrabackup只备份InnoDB数据文件,表结构是不备份的,所以恢复的时候,你必须有对应表结构文件(.frm)。

rm -rf /data/mysql_data/ib*

cp -i /data/back_data/2010-10-26_16-09-37/ib* /data/mysql_data/

cd /data
chown -R mysql:mysql mysql_data/

 

 


2.innobackupex-1.5.1 与 xtrabackup 相结合
=======================================================================================
首先,innobackupex-1.5.1全备份:
innobackupex-1.5.1 --user=root /data/back_data/ 2>/data/back_data/1.log         #会生成一个时间文件夹,这里假如是2010-10-29_15-57-44
然后,xtrabackup 做增量备份:
xtrabackup --defaults-file=/etc/my.cnf --backup --target-dir=/data/back_data_inc/4 --incremental-basedir=/data/back_data/2010-10-29_15-57-44


恢复:
首先停掉数据库,备份二进制日志(如果有的话),然后删除数据库目录下的所有数据库文件.
cd /data/mysql_data
rm -rf *           # 删除数据目录里的所有文件

恢复全量备份:
innobackupex-1.5.1 --user=root --apply-log /data/back_data/2010-10-29_15-57-44   # 应用日志
innobackupex-1.5.1 --user=root --copy-back /data/back_data/2010-10-29_15-57-44   # 拷贝文件
恢复增量备份:
xtrabackup --prepare --target-dir=/data/back_data/2010-10-29_15-57-44 --incremental-dir=/data/back_data_inc/5

cd /data
chown -R mysql:mysql mysql_data/

重启mysql服务。

bitsCN.com
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

Video Face Swap

Video Face Swap

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

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)

Solution to the problem that Win11 system cannot install Chinese language pack Solution to the problem that Win11 system cannot install Chinese language pack Mar 09, 2024 am 09:48 AM

Solution to the problem that Win11 system cannot install Chinese language pack With the launch of Windows 11 system, many users began to upgrade their operating system to experience new functions and interfaces. However, some users found that they were unable to install the Chinese language pack after upgrading, which troubled their experience. In this article, we will discuss the reasons why Win11 system cannot install the Chinese language pack and provide some solutions to help users solve this problem. Cause Analysis First, let us analyze the inability of Win11 system to

Ten recommended open source free text annotation tools Ten recommended open source free text annotation tools Mar 26, 2024 pm 08:20 PM

Text annotation is the work of corresponding labels or tags to specific content in text. Its main purpose is to provide additional information to the text for deeper analysis and processing, especially in the field of artificial intelligence. Text annotation is crucial for supervised machine learning tasks in artificial intelligence applications. It is used to train AI models to help more accurately understand natural language text information and improve the performance of tasks such as text classification, sentiment analysis, and language translation. Through text annotation, we can teach AI models to recognize entities in text, understand context, and make accurate predictions when new similar data appears. This article mainly recommends some better open source text annotation tools. 1.LabelStudiohttps://github.com/Hu

15 recommended open source free image annotation tools 15 recommended open source free image annotation tools Mar 28, 2024 pm 01:21 PM

Image annotation is the process of associating labels or descriptive information with images to give deeper meaning and explanation to the image content. This process is critical to machine learning, which helps train vision models to more accurately identify individual elements in images. By adding annotations to images, the computer can understand the semantics and context behind the images, thereby improving the ability to understand and analyze the image content. Image annotation has a wide range of applications, covering many fields, such as computer vision, natural language processing, and graph vision models. It has a wide range of applications, such as assisting vehicles in identifying obstacles on the road, and helping in the detection and diagnosis of diseases through medical image recognition. . This article mainly recommends some better open source and free image annotation tools. 1.Makesens

Unable to install guest additions in VirtualBox Unable to install guest additions in VirtualBox Mar 10, 2024 am 09:34 AM

You may not be able to install guest additions to a virtual machine in OracleVirtualBox. When we click on Devices>InstallGuestAdditionsCDImage, it just throws an error as shown below: VirtualBox - Error: Unable to insert virtual disc C: Programming FilesOracleVirtualBoxVBoxGuestAdditions.iso into ubuntu machine In this post we will understand what happens when you What to do when you can't install guest additions in VirtualBox. Unable to install guest additions in VirtualBox If you can't install it in Virtua

What should I do if Baidu Netdisk is downloaded successfully but cannot be installed? What should I do if Baidu Netdisk is downloaded successfully but cannot be installed? Mar 13, 2024 pm 10:22 PM

If you have successfully downloaded the installation file of Baidu Netdisk, but cannot install it normally, it may be that there is an error in the integrity of the software file or there is a problem with the residual files and registry entries. Let this site take care of it for users. Let’s introduce the analysis of the problem that Baidu Netdisk is successfully downloaded but cannot be installed. Analysis of the problem that Baidu Netdisk downloaded successfully but could not be installed 1. Check the integrity of the installation file: Make sure that the downloaded installation file is complete and not damaged. You can download it again, or try to download the installation file from another trusted source. 2. Turn off anti-virus software and firewall: Some anti-virus software or firewall programs may prevent the installation program from running properly. Try disabling or exiting the anti-virus software and firewall, then re-run the installation

How to install Android apps on Linux? How to install Android apps on Linux? Mar 19, 2024 am 11:15 AM

Installing Android applications on Linux has always been a concern for many users. Especially for Linux users who like to use Android applications, it is very important to master how to install Android applications on Linux systems. Although running Android applications directly on Linux is not as simple as on the Android platform, by using emulators or third-party tools, we can still happily enjoy Android applications on Linux. The following will introduce how to install Android applications on Linux systems.

Recommended: Excellent JS open source face detection and recognition project Recommended: Excellent JS open source face detection and recognition project Apr 03, 2024 am 11:55 AM

Face detection and recognition technology is already a relatively mature and widely used technology. Currently, the most widely used Internet application language is JS. Implementing face detection and recognition on the Web front-end has advantages and disadvantages compared to back-end face recognition. Advantages include reducing network interaction and real-time recognition, which greatly shortens user waiting time and improves user experience; disadvantages include: being limited by model size, the accuracy is also limited. How to use js to implement face detection on the web? In order to implement face recognition on the Web, you need to be familiar with related programming languages ​​and technologies, such as JavaScript, HTML, CSS, WebRTC, etc. At the same time, you also need to master relevant computer vision and artificial intelligence technologies. It is worth noting that due to the design of the Web side

How to install Podman on Ubuntu 24.04 How to install Podman on Ubuntu 24.04 Mar 22, 2024 am 11:26 AM

If you have used Docker, you must understand daemons, containers, and their functions. A daemon is a service that runs in the background when a container is already in use in any system. Podman is a free management tool for managing and creating containers without relying on any daemon such as Docker. Therefore, it has advantages in managing containers without the need for long-term backend services. Additionally, Podman does not require root-level permissions to be used. This guide discusses in detail how to install Podman on Ubuntu24. To update the system, we first need to update the system and open the Terminal shell of Ubuntu24. During both installation and upgrade processes, we need to use the command line. a simple

See all articles