下载:Xtrabackup
https://www.percona.com/downloads/XtraBackup/Percona-XtraBackup-2.4.8/binary/redhat/7/x86_64/Percona-XtraBackup-2.4.8-r97330f7-el7-x86_64-bundle.tar
解压,yum安装
tar -xvf Percona-XtraBackup-2.4.8-r97330f7-el7-x86_64-bundle.tar
yum install percona-xtrabackup-24-2.4.8-1.el7.x86_64.rpm
完整备份
innobackupex –user=root –password=123456 –no-timestamp /backup/mysql/full
增加数据库中的数据
增加一个数据库db1, 并在db1中建立表t1(表的引擎为innodb),插入数据
MariaDB [(none)]> create database if not exists db1;
MariaDB [(none)]> use db1;
MariaDB [db1]> create table t1(id int,name varchar(20))engine=innodb;
MariaDB [db1]> insert into t1 values(1,‘aa‘);
增量备份第一次
[[email protected] ~]# innobackupex --user=root --password=123456 --no-timestamp --incremental-basedir=/backup/mysql/full --incremental /backup/mysql/01
增加数据库中的数据
mysql -uroot -p123456 -e "insert into db1.t1(id,name)values(2,‘100‘);"
增量备份第二次
[[email protected] ~]# innobackupex --user=root --password=123456 --no-timestamp --incremental-basedir=/backup/mysql/01 --incremental /backup/mysql/02
模拟数据丢失,删除数据库中的所有内容
cd /var/lib/mysql/
rm -rf *
恢复完整备份
[[email protected] mysql]# innobackupex --user=root --password=123456 --apply-log --redo-only /backup/mysql/full/
恢复第一次增量备份
[[email protected] mysql]# innobackupex --user=root --password=123456 --apply-log --redo-only /backup/mysql/full/ --incremental-dir=/backup/mysql/01
恢复第二次增量备份
[[email protected] mysql]# innobackupex --user=root --password=123456 --apply-log /backup/mysql/full/ --incremental-dir=/backup/mysql/02
将合并完的数据整体做一次apply-log
[[email protected] mysql]# innobackupex --user=root --password=123456 --copy-back /backup/mysql/full/
设置权限
[[email protected] mysql]# chown -R mysql.mysql /var/lib/mysql/
重启,看是否恢复成功
[[email protected] mysql]# systemctl restart mariadb
[[email protected] mysql]# mysql -uroot -p123456 -e "select * from db1.t1;"
+------+------+
| id | name |
+------+------+
| 1 | aa |
| 2 | 100 |
+------+------+
原文地址:http://blog.51cto.com/13480443/2310347
时间: 2024-10-10 05:57:18