1. 全量备份恢复:

  • 查看原表内容:
MariaDB [(none)]> select * from testdb.students;
+----+------------+------+--------+
| id | name       | age  | gender |
+----+------------+------+--------+
|  1 | zhangsan   |   15 | f      |
|  2 | lisi       |   15 | m      |
|  3 | wanger     |   25 | m      |
|  4 | liuwu      |   24 | f      |
|  5 | wangermazi |   28 | f      |
+----+------------+------+--------+
5 rows in set (0.00 sec)
  • 备份:
[root@jenkins ~]# innobackupex --user=lxk --host=localhost --password=lxkpass /tmp
180916 11:56:18 innobackupex: Starting the backup operationIMPORTANT: Please check that the backup run completes successfully.At the end of a successful backup run innobackupexprints "completed OK!".
......
中间省略
......180916 11:56:22 Executing UNLOCK TABLES
180916 11:56:22 All tables unlocked
180916 11:56:22 Backup created in directory '/tmp/2018-09-16_11-56-18'
180916 11:56:22 [00] Writing backup-my.cnf
180916 11:56:22 [00]        ...done
180916 11:56:22 [00] Writing xtrabackup_info
180916 11:56:22 [00]        ...done
xtrabackup: Transaction log of lsn (1602080) to (1602080) was copied.
180916 11:56:23 completed OK![root@jenkins ~]# cat /tmp/2018-09-16_11-56-18/xtrabackup_checkpoints
backup_type = full-backuped         #备份类型:全量备份
from_lsn = 0                        #起始lsn
to_lsn = 1602080                    #结束lsn
last_lsn = 1602080                  #总共多少个lsn
compact = 0
recover_binlog_info = 0[root@jenkins ~]# cat /tmp/2018-09-16_11-56-18/xtrabackup_info
uuid = 7a05430c-b964-11e8-889e-000c29080758
name =
tool_name = innobackupex                #备份工具名称
tool_command = --user=lxk --host=localhost --password=... /tmp      #备份时使用的命令
tool_version = 2.3.6                    #工具版本
ibbackup_version = 2.3.6
server_version = 5.5.60-MariaDB
start_time = 2018-09-16 11:56:18        #备份开始时间
end_time = 2018-09-16 11:56:22          #备份结束时间
lock_time = 0
binlog_pos =
innodb_from_lsn = 0
innodb_to_lsn = 1602080
partial = N
incremental = N
format = file
compact = N
compressed = N                          #是否启用压缩
encrypted = N                           #是否加密
  • 准备(apply)备份
[root@jenkins ~]# innobackupex --apply-log /tmp/2018-09-16_11-56-18/
180916 12:06:16 innobackupex: Starting the apply-log operationIMPORTANT: Please check that the apply-log run completes successfully.At the end of a successful apply-log run innobackupexprints "completed OK!".
......
中间省略
......
xtrabackup: starting shutdown with innodb_fast_shutdown = 1
InnoDB: FTS optimize thread exiting.
InnoDB: Starting shutdown...
InnoDB: Shutdown completed; log sequence number 1602582
180916 12:06:19 completed OK!           #此处显示completed OK即表示完成
  • 恢复备份:

    1. 停止mysql服务
    2. 删库
[root@jenkins ~]# rm -rf /var/lib/mysql/*
  1. 通过全量备份恢复数据
[root@jenkins ~]# innobackupex --copy-back /tmp/2018-09-16_11-56-18/
180916 12:11:19 innobackupex: Starting the copy-back operationIMPORTANT: Please check that the copy-back run completes successfully.At the end of a successful copy-back run innobackupexprints "completed OK!".innobackupex version 2.3.6 based on MySQL server 5.6.24 Linux (x86_64) (revision id: )
180916 12:11:19 [01] Copying ib_logfile0 to /var/lib/mysql/ib_logfile0
180916 12:11:19 [01]        ...done
.....
中间省略
.....
180916 12:11:20 [01]        ...done
180916 12:11:20 [01] Copying ./xtrabackup_info to /var/lib/mysql/xtrabackup_info
180916 12:11:20 [01]        ...done
180916 12:11:20 [01] Copying ./test/db.opt to /var/lib/mysql/test/db.opt
180916 12:11:20 [01]        ...done
180916 12:11:20 completed OK!           #显示completed OK即为完成
  1. 修改恢复后文件的属主,属组为mysql
[root@jenkins ~]# ls /var/lib/mysql -l
total 28692
-rw-r----- 1 root root 18874368 Sep 16 12:11 ibdata1
-rw-r----- 1 root root  5242880 Sep 16 12:11 ib_logfile0
-rw-r----- 1 root root  5242880 Sep 16 12:11 ib_logfile1
drwx------ 2 root root     4096 Sep 16 12:11 mysql
drwx------ 2 root root     4096 Sep 16 12:11 performance_schema
drwx------ 2 root root     4096 Sep 16 12:11 test
drwx------ 2 root root     4096 Sep 16 12:11 testdb
-rw-r----- 1 root root      437 Sep 16 12:11 xtrabackup_info
[root@jenkins ~]# chown -R mysql.mysql /var/lib/mysql/*
[root@jenkins ~]# ll /var/lib/mysql/
total 28692
-rw-r----- 1 mysql mysql 18874368 Sep 16 12:11 ibdata1
-rw-r----- 1 mysql mysql  5242880 Sep 16 12:11 ib_logfile0
-rw-r----- 1 mysql mysql  5242880 Sep 16 12:11 ib_logfile1
drwx------ 2 mysql mysql     4096 Sep 16 12:11 mysql
drwx------ 2 mysql mysql     4096 Sep 16 12:11 performance_schema
drwx------ 2 mysql mysql     4096 Sep 16 12:11 test
drwx------ 2 mysql mysql     4096 Sep 16 12:11 testdb
-rw-r----- 1 mysql mysql      437 Sep 16 12:11 xtrabackup_info
  1. 启动MySQL并查看
[root@jenkins ~]# systemctl start mariadb
[root@jenkins ~]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.60-MariaDB MariaDB ServerCopyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.MariaDB [(none)]> select * from testdb.students;
+----+------------+------+--------+
| id | name       | age  | gender |
+----+------------+------+--------+
|  1 | zhangsan   |   15 | f      |
|  2 | lisi       |   15 | m      |
|  3 | wanger     |   25 | m      |
|  4 | liuwu      |   24 | f      |
|  5 | wangermazi |   28 | f      |
+----+------------+------+--------+
5 rows in set (0.00 sec)

2. 增量备份及恢复:

  1. 全量备份:
[root@jenkins ~]# innobackupex --user=lxk --host=localhost --password=lxkpass /tmp/
180916 12:17:01 innobackupex: Starting the backup operationIMPORTANT: Please check that the backup run completes successfully.At the end of a successful backup run innobackupexprints "completed OK!".
.....
中间省略
.....180916 12:17:03 Executing UNLOCK TABLES
180916 12:17:03 All tables unlocked
180916 12:17:03 Backup created in directory '/tmp//2018-09-16_12-17-01'
180916 12:17:03 [00] Writing backup-my.cnf
180916 12:17:03 [00]        ...done
180916 12:17:03 [00] Writing xtrabackup_info
180916 12:17:03 [00]        ...done
xtrabackup: Transaction log of lsn (1602592) to (1602592) was copied.
180916 12:17:03 completed OK!
  1. 修改数据库,进行第一次增量备份
  • 在testdb.students中添加一条数据:
MariaDB [testdb]> insert into students values (6,'xiaoming',20,'f');
Query OK, 1 row affected (0.00 sec)MariaDB [testdb]> select * from students;
+----+------------+------+--------+
| id | name       | age  | gender |
+----+------------+------+--------+
|  1 | zhangsan   |   15 | f      |
|  2 | lisi       |   15 | m      |
|  3 | wanger     |   25 | m      |
|  4 | liuwu      |   24 | f      |
|  5 | wangermazi |   28 | f      |
|  6 | xiaoming   |   20 | f      |
+----+------------+------+--------+
6 rows in set (0.00 sec)
  • 增量备份:
[root@jenkins ~]# innobackupex --incremental /tmp --incremental-basedir=/tmp/2018-09-16_12-17-01/
180916 12:23:28 innobackupex: Starting the backup operationIMPORTANT: Please check that the backup run completes successfully.At the end of a successful backup run innobackupexprints "completed OK!".
.....
中间省略
.....
180916 12:23:30 [00]        ...done
xtrabackup: Transaction log of lsn (1602735) to (1602735) was copied.
180916 12:23:30 completed OK!
  1. 再添加一条数据,进行第二次增量备份:
  • 增加一条数据
MariaDB [testdb]> insert into students values (8,'daming',20,'m');
Query OK, 1 row affected (0.00 sec)
  • 第二次增量备份(若此时--incremental-basedir指的是第一次全量备份路径,则为差异备份):
[root@jenkins ~]# innobackupex --incremental /tmp --incremental-basedir=/tmp/2018-09-16_12-23-28/
180916 12:29:08 innobackupex: Starting the backup operationIMPORTANT: Please check that the backup run completes successfully.At the end of a successful backup run innobackupexprints "completed OK!".
.....
中间省略
.....
180916 12:29:10 [00] Writing xtrabackup_info
180916 12:29:10 [00]        ...done
xtrabackup: Transaction log of lsn (1603615) to (1603615) was copied.
180916 12:29:10 completed OK!
  1. 准备(prepare)数据:

    • 需要在每个备份(包括完全和各个增量备份)上,将已经提交的事务进行“重放”。“重放”之后,所有的备份数据将合并到完全备份上。
    • 基于所有的备份将未提交的事务进行“回滚”

(1) 准备全量备份文件

[root@jenkins tmp]# innobackupex --apply-log --redo-only 2018-09-16_12-17-01
180916 12:34:06 innobackupex: Starting the apply-log operationIMPORTANT: Please check that the apply-log run completes successfully.At the end of a successful apply-log run innobackupexprints "completed OK!".
.....
中间省略
.....
InnoDB: Starting shutdown...
InnoDB: Shutdown completed; log sequence number 1602592
180916 12:34:06 completed OK!

(2) 准备第一次增量备份文件:

注: --incremental-dir所指的目录必须为绝对路径

[root@jenkins 2018-09-16_12-17-01]# innobackupex --apply-log --redo-only ./ --incremental-dir=/tmp/2018-09-16_12-23-28
180916 12:38:17 innobackupex: Starting the apply-log operationIMPORTANT: Please check that the apply-log run completes successfully.At the end of a successful apply-log run innobackupexprints "completed OK!"......
中间省略
.....180916 12:38:18 [00] Copying /tmp/2018-09-16_12-23-28/xtrabackup_info to ./xtrabackup_info
180916 12:38:18 [00]        ...done
180916 12:38:18 completed OK!

(3) 准备第二次增量备份文件:

[root@jenkins 2018-09-16_12-17-01]# innobackupex --apply-log --redo-only ./ --incremental-dir=/tmp/2018-09-16_12-29-08/
180916 12:42:56 innobackupex: Starting the apply-log operationIMPORTANT: Please check that the apply-log run completes successfully.At the end of a successful apply-log run innobackupexprints "completed OK!".
.....
中间省略
.....180916 12:42:57 [01]        ...done
180916 12:42:57 [00] Copying /tmp/2018-09-16_12-29-08//xtrabackup_info to ./xtrabackup_info
180916 12:42:57 [00]        ...done
180916 12:42:57 completed OK!

(4) 执行回滚操作

[root@jenkins tmp]# innobackupex --apply-log /tmp/2018-09-16_12-17-01
180916 12:46:15 innobackupex: Starting the apply-log operationIMPORTANT: Please check that the apply-log run completes successfully.At the end of a successful apply-log run innobackupexprints "completed OK!".
.....
中间省略
.....
xtrabackup: starting shutdown with innodb_fast_shutdown = 1
InnoDB: FTS optimize thread exiting.
InnoDB: Starting shutdown...
InnoDB: Shutdown completed; log sequence number 1604128
180916 12:46:18 completed OK!

(5) 关闭MySQL并删除/var/lib/mysql/下所有文件

(6) 恢复数据:

[root@jenkins tmp]# innobackupex --copy-back 2018-09-16_12-17-01/
180916 12:48:39 innobackupex: Starting the copy-back operationIMPORTANT: Please check that the copy-back run completes successfully.At the end of a successful copy-back run innobackupexprints "completed OK!".
.....
中间省略
.....
180916 12:48:40 [01] Copying ./test/db.opt to /var/lib/mysql/test/db.opt
180916 12:48:40 [01]        ...done
180916 12:48:40 completed OK!

(6) 修改/var/lib/mysql/下文件的属主、属组并启动数据库并查看

[root@jenkins mysql]# chown -R mysql.mysql /var/lib/mysql/*
[root@jenkins mysql]# ll
total 28692
-rw-r----- 1 mysql mysql 18874368 Sep 16 12:48 ibdata1
-rw-r----- 1 mysql mysql  5242880 Sep 16 12:48 ib_logfile0
-rw-r----- 1 mysql mysql  5242880 Sep 16 12:48 ib_logfile1
drwx------ 2 mysql mysql     4096 Sep 16 12:48 mysql
drwx------ 2 mysql mysql     4096 Sep 16 12:48 performance_schema
drwx------ 2 mysql mysql     4096 Sep 16 12:48 test
drwx------ 2 mysql mysql     4096 Sep 16 12:48 testdb
-rw-r----- 1 mysql mysql      462 Sep 16 12:48 xtrabackup_info
[root@jenkins mysql]# systemctl start mariadb
[root@jenkins mysql]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.60-MariaDB MariaDB ServerCopyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.MariaDB [(none)]> select * from testdb.students;
+----+------------+------+--------+
| id | name       | age  | gender |
+----+------------+------+--------+
|  1 | zhangsan   |   15 | f      |
|  2 | lisi       |   15 | m      |
|  3 | wanger     |   25 | m      |
|  4 | liuwu      |   24 | f      |
|  5 | wangermazi |   28 | f      |
|  6 | xiaoming   |   20 | f      |
|  8 | daming     |   20 | m      |
+----+------------+------+--------+
7 rows in set (0.00 sec)

转载于:https://blog.51cto.com/11975865/2296436

xtrabackup备份恢复MySQL数据库相关推荐

  1. xtrabackup备份还原MySQL数据库

    原文:xtrabackup备份还原MySQL数据库 mysqldump 备份鉴于其自身的某些特性(锁表,本质上备份出来insert脚本或者文本,不支持差异备份),不太适合对实时性要求比较高的情况 Xt ...

  2. xtrabackup全量、增量备份恢复mysql数据库

    一. 全量备份恢复: 查看原表内容: MariaDB [(none)]> select * from testdb.students; +----+------------+------+--- ...

  3. mysql怎么备份和恢复_如何优雅的备份和恢复Mysql数据库?

    谢邀,个人认为从标题看,是个比较大而且值得数据库从业者思考的问题:从问题描述看,又是一个比较浅显的问题. 先从问题描述看,mysqldump 备份和恢复时往往会有各种错误,如何避免?mysqldump ...

  4. php备份mysql页面_如何用PHP的页面备份、恢复Mysql数据库_php

    //备份数据 $i   =   0; $crlf="/r/n"; $dbname="xgtqr"; global     $dbconn; http://www ...

  5. mysql meb_教你如何恢复使用MEB备份的MySQL数据库

    恢复使用MEB备份的MySQL数据库,执行一个普通备份 [root@test bin]# ./mysqlbackup --defaults-file=/service/mysql5.5/my.cnf ...

  6. meb备份mysql_恢复使用MEB备份的MySQL数据库

    恢复使用MEB备份的MySQL数据库,执行一个普通备份 [root@test bin]# ./mysqlbackup --defaults-file=/service/mysql5.5/my.cnf ...

  7. meb备份mysql_教你如何恢复使用MEB备份的MySQL数据库【第1/3页】

    恢复使用MEB备份的MySQL数据库,执行一个普通备份[root@test bin]# ./mysqlbackup --defaults-file=/service/mysql5.5/my.cnf - ...

  8. 从xtrabackup备份恢复单表【转】

    目前对MySQL比较流行的备份方式有两种,一种上是使用自带的mysqldump,另一种是xtrabackup,对于数据时大的环境,普遍使用了xtrabackup+binlog进行全量或者增量备份,那么 ...

  9. mysql 刷新二进制日志_使用binlog日志恢复MySQL数据库删除数据的方法

    binlog日志简介: binlog 就是binary log,二进制日志文件,这个文件记录了MySQL所有的DDL和DML(除了数据查询语句)语句,以事件形式记录,还包含语句所执行的消耗的时间. b ...

最新文章

  1. j2ee mysql 图片_实战 J2EE 开发购物网站 二_MySQL
  2. 电脑模拟器哪个好_《英雄聯盟:激鬥峽谷》电脑版哪个安卓模拟器好用?《英雄聯盟:激鬥峽谷》手游电脑版怎么玩...
  3. Dell sc1425安装ESXi 5不成功
  4. bentley 二次开发_Bentley的基本概念
  5. 如何选择主机操作系统?
  6. 三维重建:SLAM的尺度和方法论问题
  7. 如何需求分析和编写测试用例
  8. 10 种最流行的 Web 挖掘工具
  9. python大家都是怎么学的_你们都是怎么学 Python 的?
  10. 推荐几款好用的文本编辑器
  11. BJ模拟 Different Trips【树上后缀数组】
  12. springbooot使用google验证码
  13. loadstring的用法
  14. 按键android手机排行榜,【直板全键盘手机推荐】直板键盘手机排行榜
  15. VS Code 下载和安装教程
  16. java数组和字符串相互转换
  17. 如何构建Pebble应用程序
  18. 第101篇 盲盒智能合约(ERC1155)
  19. 动态规划简单例子——国王与金矿(c++)
  20. python笛卡尔坐标系_将GPS的WGS84坐标(大地坐标系)转换为平面坐标(笛卡尔坐标系)的方法...

热门文章

  1. 16位转10位c语言,10进制数转换为16位二进制数
  2. zigzag扫描matlab,ZIGZAG扫描的MATLAB实现
  3. linux下的文件搜索功能
  4. 机械指令 对应 汇编指令
  5. latex从入门到精通
  6. Vultr VPS添加额外的IPv4地址
  7. mysql 命令行 h_mysql-命令行
  8. css3帧(雪碧图)动画实现
  9. CVX工具下载及测试
  10. 卷积神经网络在句子分类上的应用[翻译]