一.增量备份
1.前期环境准备工作
mysql -uroot -p"Xp.@123456haha"
create databases xp;
use xp;
create table peng(ip int);
insert into peng values (1);
insert into peng values (2);
\q
select * from peng;
2.完整备份:一
rm -rf /1/
date 09010000 为了试验效果我们将试验效果我们重新设置了时间
innobackupex --user=root --password='Xp.@123456haah/1
ll /1/
3.增量备份:周二
date 09020000
mysql -uroot -p"Xp.@123456haha" -e
"insert into peng valuse (3)
innobackupex --user=root --password='Xp.@123456haha'
--incremental /1/
--incremental-basedir=/2/2019-09-01_00-00-00
ls /1/ (此时文件应该要两个)
4.增量备份:周三
date 09030000
mysql -uroot -p"Xp.@123456haha" -e
"insert into peng valuse (4)
innobackupex --user=root --password='Xp.@123456haha'
--incremental /1/
--incremental-basedir=/2/2019-09-02_00-00-00
以此类推可备份无数
开始增量恢复
systable stop mysql
rm -rf /var/bli/mysql/*
innobackupex --apply-log --redo-only /xtrabackup/2019-09-01_00-00-04
innobackupex --apply-log --redo-only /xtrabackup/2017-09-01_00-00-04
--incremental-dir=/xtrabackup/2019-09-02_00-00-26
innobackupex --copy-back /xtrabackup/2019-09-01_00-00-06
innobackupex --apply-log --redo-only /xtrabackup/2019-09-01_00-00-04
--incremental-dir=/xtrabackup/2019-09-02_00-00-00
innobackupex --copy-back /xtrabackup/2017-09-01_00-00-06
chown -R mysql.mysql /var/lib/mysql
systemctl start mysqld
差异备份
date 10010000
1.完整备份:周一
create database testdb;
use testdb;
create table test2(id int);
insert into test2 values(1);
select * from test2;
innobackupex --user=root --password='QianFeng@123' /xtrabackup
差异备份:周二
date 10020000
mysql -uroot -p'QianFeng@123' -e 'insert into testdb.test2 values(2)'
innobackupex --user=root --password='QianFeng@123'
--incremental /xtrabackup
--incremental-basedir=/xtrabackup/2019-10-01_00-01-12
差异备份:周三
date 10030000
mysql -uroot -p'QianFeng@123' -e 'insert into testdb.test2 values(3)'
innobackupex --user=root --password='QianFeng@123'
--incremental /xtrabackup
--incremental-basedir=/xtrabackup/2017-10-01_00-01-12
systemctl stop mysqld
开始数据还原:
rm -rf /var/lib/mysql/*
innobackupex --apply-log --redo-only /xtrabackup/2017-10-01_00-01-12
innobackupex --apply-log --redo-only
/xtrabackup/2019-10-01_00-01-12
--incremental-dir=/xtrabackup/2019-10-03_00-00-29
innobackupex --copy-back /xtrabackup/2017-10-01_00-01-12
systemctl start mysqld