#创建全备
[root@rhel7 mysql]# innobackupex --user=root --password=123456 /mysqlbackup/
[root@rhel7 mysql]# ls -l /mysqlbackup/
total 4
drwxr-x---. 8 root root 4096 Dec 13 13:10 2016-12-13_13-10-48
#删除一个测试库
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| test |
| wl |
| zx |
+--------------------+
7 rows in set (0.00 sec)
mysql> drop database zx;
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-10-48/
......
[root@rhel7 mysql]# ls -l /mysqlbackup/
total 8
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
[root@rhel7 mysql]# du -sm /mysqlbackup/*
90 /mysqlbackup/2016-12-13_13-10-48
3 /mysqlbackup/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库还在,但是库里的表已经没有了。