设为首页 加入收藏

TOP

使用XtraBackup 备份MySQL数据库(五)
2016-12-28 08:15:44 】 浏览:538
Tags:使用 XtraBackup 备份 MySQL 数据库
2016-12-13_13-16-17
#删除一个测试库
mysql> drop database wl;
Query OK, 0 rows affected (0.07 sec)
#创建增量备份(基于上次增量备份)
[root@rhel7 mysql]# innobackupex --user=root --password=123456 --incremental /mysqlbackup/ --incremental-basedir=/mysqlbackup/2016-12-13_13-16-17/
......
[root@rhel7 mysql]# ls -l /mysqlbackup/
total 12
drwxr-x---. 8 root root 4096 Dec 13 13:10 2016-12-13_13-10-48
drwxr-x---. 7 root root 4096 Dec 13 13:16 2016-12-13_13-16-17
drwxr-x---. 6 root root 4096 Dec 13 13:18 2016-12-13_13-18-30
[root@rhel7 mysql]# du -sm /mysqlbackup/*
90 /mysqlbackup/2016-12-13_13-10-48
3 /mysqlbackup/2016-12-13_13-16-17
4 /mysqlbackup/2016-12-13_13-18-30


2)恢复增量备份


同全量备份一样恢复里也需要prepare


#全量备份的prepare --redo-only表示只提交commit的事务
[root@rhel7 mysql]# innobackupex --apply-log --redo-only /mysqlbackup/2016-12-13_13-10-48/
#第一次增量备份prepare
[root@rhel7 mysql]# innobackupex --apply-log --redo-only /mysqlbackup/2016-12-13_13-10-48/ --incremental-dir=/mysqlbackup/2016-12-13_13-16-17/
#最后一次增量备份prepare 不再需要redo-only参数
[root@rhel7 mysql]# innobackupex --apply-log /mysqlbackup/2016-12-13_13-10-48/ --incremental-dir=/mysqlbackup/2016-12-13_13-18-30/
#停止MySQL服务创建新的data目录
[root@rhel7 mysql]# service mysqld stop
Shutting down MySQL.. SUCCESS!
[root@rhel7 mysql]# rm -rf data
[root@rhel7 mysql]# mkdir data
#恢复数据
[root@rhel7 mysql]# innobackupex --copy-back /mysqlbackup/2016-12-13_13-10-48/
#修改data目录权限
[root@rhel7 mysql]# chown mysql:mysql -R data
#启动MySQL服务并验证
[root@rhel7 mysql]# service mysqld start
Starting MySQL... SUCCESS!
[root@rhel7 mysql]# mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.16 Source distribution

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| test |
| wl |
+--------------------+
6 rows in set (0.00 sec)

mysql> show tables in wl;
Empty set (0.00 sec)
#测试库zx没有了,wl库还在,但是库里的表已经没有了。


前边只是提供了简单的恢复方法,如果数据库备份之后运行了一段时间,数据库宕机了,如果只恢复备份的数据那就会丢失一部分数据。那这部分数据要怎么恢复呢。答案就是应用binlog。


在启用binlog的数据库中,备份完成后日志中会输出关于binlog的信息,生成的备份目录中也会有一个xtrabackup_binlog_info文件保存备份时的binlog位置。


161214 10:24:34 Executing UNLOCK TABLES
161214 10:24:34 All tables unlocked
161214 10:24:34 [00] Copying ib_buffer_pool to /mysqlbackup//2016-12-14_10-24-27/ib_buffer_pool
161214 10:24:34 [00] ...done
161214 10:24:34 Backup created in directory '/mysqlbackup//2016-12-14_10-24-27'
#binlog位置
MySQL binlog position: filename 'mysql-bin.000001', position '154'
161214 10:24:34 [00] Writing backup-my.cnf
161214 10:24:34 [00] ...done
161214 10:24:34 [00] Writing xtrabackup_info
161214 10:24:34 [00] ...done
xtrabackup: Transaction log of lsn (2677865) to (2677874) was copied.
161214 10:24:34 completed OK!

[root@rhel7 2016-12-14_10-24-27]# ls -l
total 77876
-rw-r-----. 1 root root 425 Dec 14 10:24 backup-my.cnf
-rw-r-----. 1 root root 307 Dec 14 10:24 ib_buffer_pool
-rw-r---

首页 上一页 2 3 4 5 下一页 尾页 5/5/5
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Oracle dba_data_files数据字典里.. 下一篇Redis3.0.7集群部署完整版

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目