xtrabackup之Innobackupex全备数据库

一、Xtrabackup是什么:

  • Xtrabackup是一个对InnoDB做数据备份的工具,支持在线热备份(备份时不影响数据读写),是商业备份工具InnoDB Hotbackup的一个很好的替代品。
  • Xtrabackup有两个主要的工具:xtrabackup、innobackupex
  1. xtrabackup只能备份InnoDB和XtraDB两种数据表,而不能备份MyISAM数据表
  2. innobackupex是参考了InnoDB Hotbackup的innoback脚本修改而来的.innobackupex是一个perl脚本封装,封装了xtrabackup。主要是为了方便的 同时备份InnoDB和MyISAM引擎的表,但在处理myisam时需要加一个读锁。并且加入了一些使用的选项。如slave-info可以记录备份恢 复后,作为slave需要的一些信息,根据这些信息,可以很方便的利用备份来重做slave。

二、利用二进制包安装xtrabackup

[[email protected] ~]# tar xvfz percona-xtrabackup-2.0.7-552.tar.gz -C /usr/local
[[email protected] local]# mv percona-xtrabackup-2.0.7 xtrabackup
[[email protected] local]# chown mysql:mysql -R /usr/local/xtrabackup/

在mysql用户下的 .bash_profile文件中添加环境变量
export PATH=/usr/local/xtrabackup/bin:$PATH

三、创建备份专用账户

[[email protected] ~]$ mysql --defaults-file=/mysql/mysqldata/3306/my.cnf -usystem -p‘123456‘
[(none) 10:09:13]>create user [email protected]‘127.0.0.1‘ identified by ‘onlybackup‘;
Query OK, 0 rows affected (0.08 sec)

[(none) 10:09:57]>grant reload,lock tables,Replication client, super on *.* to [email protected]‘127.0.0.1‘;
Query OK, 0 rows affected (0.07 sec)
[(none) 10:10:57]>

四.innobackupex全量备份

[[email protected] ~]$ innobackupex --defaults-file=/mysql/mysqldata/3306/my.cnf --host=127.0.0.1 --user=xtrabk --password=‘onlybackup‘ /mysql/mysqldata/backup/3306_full

InnoDB Backup Utility v1.5.1-xtrabackup; Copyright 2003, 2009 Innobase Oy
and Percona Ireland Ltd 2009-2012.  All Rights Reserved.

This software is published under
the GNU GENERAL PUBLIC LICENSE Version 2, June 1991.

160527 00:22:59  innobackupex: Starting mysql with options:  --defaults-file=‘/mysql/mysqldata/3306/my.cnf‘ --password=xxxxxxxx --user=‘xtrabk‘ --host=‘127.0.0.1‘ --unbuffered --
160527 00:22:59  innobackupex: Connected to database with mysql child process (pid=12647)
160527 00:23:05  innobackupex: Connection to database server closed
IMPORTANT: Please check that the backup run completes successfully.
           At the end of a successful backup run innobackupex
           prints "completed OK!".

innobackupex: Using mysql  Ver 14.12 Distrib 5.0.95, for redhat-linux-gnu (x86_64) using readline 5.1
innobackupex: Using mysql server version Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

innobackupex: Created backup directory /mysql/mysqldata/backup/3306_full/2016-05-27_00-23-05
160527 00:23:05  innobackupex: Starting mysql with options:  --defaults-file=‘/mysql/mysqldata/3306/my.cnf‘ --password=xxxxxxxx --user=‘xtrabk‘ --host=‘127.0.0.1‘ --unbuffered --
160527 00:23:05  innobackupex: Connected to database with mysql child process (pid=12670)
160527 00:23:07  innobackupex: Connection to database server closed

160527 00:23:07  innobackupex: Starting ibbackup with command: xtrabackup_56  --defaults-file="/mysql/mysqldata/3306/my.cnf"  --defaults-group="mysqld" --backup --suspend-at-end --target-dir=/mysql/mysqldata/backup/3306_full/2016-05-27_00-23-05 --tmpdir=/mysql/mysqldata/3306/tmp
innobackupex: Waiting for ibbackup (pid=12676) to suspend
innobackupex: Suspend file ‘/mysql/mysqldata/backup/3306_full/2016-05-27_00-23-05/xtrabackup_suspended‘

xtrabackup_56 version 2.0.7 for MySQL server 5.6.10 Linux (x86_64) (revision id: 552)
xtrabackup: uses posix_fadvise().
xtrabackup: cd to /mysql/mysqldata/3306/data
xtrabackup: Target instance is assumed as followings.
xtrabackup:   innodb_data_home_dir = ./
xtrabackup:   innodb_data_file_path = ibdata01:100M:autoextend
xtrabackup:   innodb_log_group_home_dir = /mysql/mysqldata/3306/redo
xtrabackup:   innodb_log_files_in_group = 3
xtrabackup:   innodb_log_file_size = 134217728
xtrabackup: using O_DIRECT
InnoDB: Allocated tablespace 6, old maximum was 0
InnoDB: Opened 5 undo tablespaces
>> log scanned up to (1527120)
[01] Copying ./ibdata01 to /mysql/mysqldata/backup/3306_full/2016-05-27_00-23-05/ibdata01
>> log scanned up to (1527120)
[01]        ...done
[01] Copying ./mysql/innodb_table_stats.ibd to /mysql/mysqldata/backup/3306_full/2016-05-27_00-23-05/mysql/innodb_table_stats.ibd
>> log scanned up to (1527120)
[01]        ...done
[01] Copying ./mysql/innodb_index_stats.ibd to /mysql/mysqldata/backup/3306_full/2016-05-27_00-23-05/mysql/innodb_index_stats.ibd
[01]        ...done
[01] Copying ./mysql/slave_relay_log_info.ibd to /mysql/mysqldata/backup/3306_full/2016-05-27_00-23-05/mysql/slave_relay_log_info.ibd
[01]        ...done
[01] Copying ./mysql/slave_master_info.ibd to /mysql/mysqldata/backup/3306_full/2016-05-27_00-23-05/mysql/slave_master_info.ibd
[01]        ...done
[01] Copying ./mysql/slave_worker_info.ibd to /mysql/mysqldata/backup/3306_full/2016-05-27_00-23-05/mysql/slave_worker_info.ibd
[01]        ...done
[01] Copying ./pls_innodb/t_polestar02.ibd to /mysql/mysqldata/backup/3306_full/2016-05-27_00-23-05/pls_innodb/t_polestar02.ibd
[01]        ...done
[01] Copying /mysql/mysqldata/3306/undo/undo001 to /mysql/mysqldata/backup/3306_full/2016-05-27_00-23-05/undo001
[01]        ...done
[01] Copying /mysql/mysqldata/3306/undo/undo002 to /mysql/mysqldata/backup/3306_full/2016-05-27_00-23-05/undo002
[01]        ...done
[01] Copying /mysql/mysqldata/3306/undo/undo003 to /mysql/mysqldata/backup/3306_full/2016-05-27_00-23-05/undo003
[01]        ...done
[01] Copying /mysql/mysqldata/3306/undo/undo004 to /mysql/mysqldata/backup/3306_full/2016-05-27_00-23-05/undo004
>> log scanned up to (1527120)
[01]        ...done
[01] Copying /mysql/mysqldata/3306/undo/undo005 to /mysql/mysqldata/backup/3306_full/2016-05-27_00-23-05/undo005
[01]        ...done
>> log scanned up to (1527120)

160527 00:23:12  innobackupex: Continuing after ibbackup has suspended
160527 00:23:12  innobackupex: Starting mysql with options:  --defaults-file=‘/mysql/mysqldata/3306/my.cnf‘ --password=xxxxxxxx --user=‘xtrabk‘ --host=‘127.0.0.1‘ --unbuffered --
160527 00:23:12  innobackupex: Connected to database with mysql child process (pid=12684)
>> log scanned up to (1527120)
>> log scanned up to (1527120)
160527 00:23:14  innobackupex: Starting to lock all tables...
>> log scanned up to (1527120)
>> log scanned up to (1527120)
>> log scanned up to (1527120)
>> log scanned up to (1527120)
>> log scanned up to (1527120)
>> log scanned up to (1527120)
>> log scanned up to (1527120)
>> log scanned up to (1527120)
>> log scanned up to (1527120)
>> log scanned up to (1527120)
160527 00:23:24  innobackupex: All tables locked and flushed to disk

160527 00:23:24  innobackupex: Starting to backup non-InnoDB tables and files
innobackupex: in subdirectories of ‘/mysql/mysqldata/3306/data‘
innobackupex: Backing up files ‘/mysql/mysqldata/3306/data/mysql/*.{frm,isl,MYD,MYI,MAD,MAI,MRG,TRG,TRN,ARM,ARZ,CSM,CSV,opt,par}‘ (74 files)
innobackupex: Backing up files ‘/mysql/mysqldata/3306/data/performance_schema/*.{frm,isl,MYD,MYI,MAD,MAI,MRG,TRG,TRN,ARM,ARZ,CSM,CSV,opt,par}‘ (53 files)
innobackupex: Backing up file ‘/mysql/mysqldata/3306/data/pls_innodb/db.opt‘
innobackupex: Backing up file ‘/mysql/mysqldata/3306/data/pls_innodb/t_polestar02.frm‘
innobackupex: Backing up file ‘/mysql/mysqldata/3306/data/pls_myisam/t_polestar01.MYD‘
innobackupex: Backing up file ‘/mysql/mysqldata/3306/data/pls_myisam/db.opt‘
innobackupex: Backing up file ‘/mysql/mysqldata/3306/data/pls_myisam/t_polestar01.MYI‘
innobackupex: Backing up file ‘/mysql/mysqldata/3306/data/pls_myisam/t_polestar01.frm‘
160527 00:23:25  innobackupex: Finished backing up non-InnoDB tables and files

160527 00:23:25  innobackupex: Waiting for log copying to finish

xtrabackup: The latest check point (for incremental): ‘1527120‘
xtrabackup: Stopping log copying thread.
.>> log scanned up to (1527120)

xtrabackup: Transaction log of lsn (1527120) to (1527120) was copied.
160527 00:23:28  innobackupex: All tables unlocked
160527 00:23:28  innobackupex: Connection to database server closed

innobackupex: Backup created in directory ‘/mysql/mysqldata/backup/3306_full/2016-05-27_00-23-05‘
innobackupex: MySQL binlog position: filename ‘mysql-bin.000003‘, position 1870
160527 00:23:28  innobackupex: completed OK!
[[email protected] ~]$ 

五、innobackupexe备份产生的相关文件

[[email protected] 2016-05-27_00-23-05]$ ls -l
total 153824
-rw-rw-r-- 1 mysql mysql       290 May 27 00:23 backup-my.cnf
-rw-rw---- 1 mysql mysql 104857600 May 27 00:23 ibdata01
drwx------ 2 mysql mysql      4096 May 27 00:23 mysql
drwxrwxr-x 2 mysql mysql      4096 May 27 00:23 performance_schema
drwx------ 2 mysql mysql      4096 May 27 00:23 pls_innodb
drwxrwxr-x 2 mysql mysql      4096 May 27 00:23 pls_myisam
drwxrwxr-x 2 mysql mysql      4096 May 27 00:23 test
-rw-rw---- 1 mysql mysql  10485760 May 27 00:23 undo001
-rw-rw---- 1 mysql mysql  10485760 May 27 00:23 undo002
-rw-rw---- 1 mysql mysql  10485760 May 27 00:23 undo003
-rw-rw---- 1 mysql mysql  10485760 May 27 00:23 undo004
-rw-rw---- 1 mysql mysql  10485760 May 27 00:23 undo005
-rw-rw-r-- 1 mysql mysql        13 May 27 00:23 xtrabackup_binary
-rw-rw-r-- 1 mysql mysql        24 May 27 00:23 xtrabackup_binlog_info
-rw-rw---- 1 mysql mysql        77 May 27 00:23 xtrabackup_checkpoints
-rw-rw---- 1 mysql mysql      2560 May 27 00:23 xtrabackup_logfile
[[email protected] 2016-05-27_00-23-05]$ 
时间: 2024-10-12 13:21:20

xtrabackup之Innobackupex全备数据库的相关文章

Innobackupex 全备数据库

对于MySQL数据库的热备,xtrabackup是除了MySQL enterprise backup之外的不二之选.该工具提供了基于innodb存储引擎的热备,支持全量,增量备份,部分备份,时点恢复以及使用xtrabackup备份来重做slave等.xtrabackup工具包包含一个innobackupex命令行工具,同时支持InnoDB引擎以及MyISAM引擎.本文主要描述的是trabackup的备份原理并给出了相关演示. 1.安装部署Xtrabackup  下载地址:http://www.p

xtrabackup之Innobackupex全备恢复

一.当前环境 [[email protected] ~]$ mysql --defaults-file=/mysql/mysqldata/3306/my.cnf -uroot -p123456 -P3306 mysql> show variables like 'version'; +---------------+------------+ | Variable_name | Value | +---------------+------------+ | version | 5.6.29-l

Xtrabackup之innobackupex在线热备mysql数据库

XtraBackup简介 Xtrabackup是一个对InnoDB做数据备份的工具,支持在线热备份(备份时不影响数据读写),是商业备份工具InnoDB Hotbackup的一个很好的替代品. Xtrabackup有两个主要的工具:xtrabackup.innobackupex (1)xtrabackup只能备份InnoDB和XtraDB两种数据表,而不能备份MyISAM数据表 (2)innobackupex-1.5.1则封装了xtrabackup,是一个脚本封装,所以能同时备份处理innodb和

XtraBackup 备份还原 MySQL 数据库

下载XtraBackup: # wget https://www.percona.com/downloads/XtraBackup/Percona-XtraBackup-2.4.6/binary/tarball/percona-xtrabackup-2.4.6-Linux-x86_64.tar.gz 解压软件: # tar xvf percona-xtrabackup-2.4.6-Linux-x86_64.tar.gz -C /usr/local/ # cd /usr/local/ # mv p

xtrabackup单库全备&增量

xtrabackup 介绍: xtrabackup有两个主要的工具:innobackupex和xtrabackup,xtrabackup只能备份InnoDB和XtraDB数据表,innobackupex封装了xtrabackup,可以备份MyISAM数据表. 第一步安装: 1.1.下载xtackbackup 地址:http://www.percona.com/downloads/XtraBackup/ 1.2.安装: tar -zxf percona-xtrabackup-2.0.8-587.t

xtrabackup备份还原MySQL数据库

原文:xtrabackup备份还原MySQL数据库 mysqldump 备份鉴于其自身的某些特性(锁表,本质上备份出来insert脚本或者文本,不支持差异备份),不太适合对实时性要求比较高的情况Xtrabackup可以解决mysqldump存在的上述的一些问题,生产环境应用的也会更多一些.本文简单测试一下Xtrabackup对MySQL数据库的备份还原操作. 本着先把功能先撸起来再深入细节的原则,粗略地实现了一个备份还原,并未深入细节. 网上有不少xtrabackup的文章,因为环境不一样,有些

MySQL5.7.18 备份、Mysqldump,mysqlpump,xtrabackup,innobackupex 全量,增量备份,数据导入导出

粗略介绍冷备,热备,温暖,及Mysqldump,mysqlpump,xtrabackup,innobackupex 全量,增量备份 --备份的目的 灾难恢复:意外情况下(如服务器宕机.磁盘损坏等)对损坏的数据进行恢复和还原保证数据不丢失,最小程度地丢失需求改变:因需求改变而需要把数据还原到改变以前测试:测试新功能是否可用 --备份与恢复概述 根据备份的方法可以分为: 1.Hot Backup(热备) 2.Cold Backup(冷备) 3.Warm Backup(温备) Hot Backup是指

使用XtraBackup恢复|备份 Mysql数据库 -- 数据恢复篇

数据恢复篇 XtraBackup工具介绍: 现在我们给MySQL做备份的时候经常会考虑到数据量的增长,数据量较小的时候用mysqldump,随着数据量越来越大mysqldump也就不太合适了.第一不支持增量备份,第二恢复的时候也较慢.这里推荐使用Percona公司的XtraBackup. 简单介绍一下热备份工具XtraBackup,它是Percona公司推出的一款热备份工具,备份的时候不影响数据读写操作,是商业工具HotBackup的一个替代(现在应该叫MySQL Enterprise Back

每天进步一点点——mysql——Percona XtraBackup(innobackupex)

一.  简介 Percona XtraBackup是开源免费的MySQL数据库热备份软件,它能对InnoDB和XtraDB存储引擎的数据库非阻塞地备份(对于MyISAM的备份同样需要加表锁).XtraBackup支持所有的Percona Server.MySQL.MariaDB和Drizzle. XtraBackup优势 : 1.无需停止数据库进行InnoDB热备 2.增量备份MySQL 3.流压缩到传输到其它服务器 4.能比较容易地创建主从同步 5.备份MySQL时不会增大服务器负载 安装Xt