xtrabackup 增量备份(InnoDB)

mysql> select * from users;
+----+-----------+----------+--------------+
| id | name      | password | address      |
+----+-----------+----------+--------------+
|  1 | zhang     | 1234     | NULL         |
|  2 | wang      | 4321     | 湖北武汉     |
|  3 | li        | 5678     | 北京海淀     |
|  4 | zhan      | 1234     | NULL         |
|  5 | wan       | 4321     | 湖北武汉     |
|  7 | for       | 777      | kkk          |
|  8 | ck        | 132      | kkk          |
|  9 | kk        | 567      | ddd          |
| 10 | 10t       | 123456   | kkkkdkdkd    |
| 11 | 全备份    | 1234     | full         |
+----+-----------+----------+--------------+
10 rows in set (0.00 sec)
[[email protected] backup]# innobackupex --defaults-file=/etc/my.cnf --user=root --password=123456 /backup/full_data/
mysql> select * from users;
+----+-----------+----------+--------------+
| id | name      | password | address      |
+----+-----------+----------+--------------+
|  1 | zhang     | 1234     | NULL         |
|  2 | wang      | 4321     | 湖北武汉     |
|  3 | li        | 5678     | 北京海淀     |
|  4 | zhan      | 1234     | NULL         |
|  5 | wan       | 4321     | 湖北武汉     |
|  7 | for       | 777      | kkk          |
|  8 | ck        | 132      | kkk          |
|  9 | kk        | 567      | ddd          |
| 10 | 10t       | 123456   | kkkkdkdkd    |
| 11 | 全备份    | 1234     | full         |
| 12 | 第一次    | 123      | first        |
+----+-----------+----------+--------------+
11 rows in set (0.00 sec)
[[email protected] backup]# innobackupex --user=root --password=123456 --defaults-file=/etc/my.cnf --incremental /backup/zl_data/ --incremental-basedir=/backup/full_data/2016-05-02_10-24-53/
mysql> select * from users;
+----+-----------+----------+--------------+
| id | name      | password | address      |
+----+-----------+----------+--------------+
|  1 | zhang     | 1234     | NULL         |
|  2 | wang      | 4321     | 湖北武汉     |
|  3 | li        | 5678     | 北京海淀     |
|  4 | zhan      | 1234     | NULL         |
|  5 | wan       | 4321     | 湖北武汉     |
|  7 | for       | 777      | kkk          |
|  8 | ck        | 132      | kkk          |
|  9 | kk        | 567      | ddd          |
| 10 | 10t       | 123456   | kkkkdkdkd    |
| 11 | 全备份    | 1234     | full         |
| 12 | 第一次    | 123      | first        |
| 13 | 第二次    | 456      | second       |
+----+-----------+----------+--------------+
12 rows in set (0.00 sec)
[[email protected] backup]# mkdir /backup/zl_data2
[[email protected] backup]# innobackupex --user=root --password=123456 --defaults-file=/etc/my.cnf --incremental /backup/zl_data2/ --incremental-basedir=/backup/zl_data/2016-05-02_10-31-50/
[[email protected] backup]# cd full_data/2016-05-02_10-24-53/
[[email protected] 2016-05-02_10-24-53]# pwd
/backup/full_data/2016-05-02_10-24-53
[[email protected] 2016-05-02_10-24-53]# cat xtrabackup_checkpoints
backup_type = full-backuped
from_lsn = 0
to_lsn = 24104664
last_lsn = 24104674
[[email protected] 2016-05-02_10-31-50]# cat xtrabackup_checkpoints
backup_type = incremental
from_lsn = 24104664
to_lsn = 24104694
last_lsn = 24104694
[[email protected] 2016-05-02_10-31-50]# pwd
/backup/zl_data/2016-05-02_10-31-50
[[email protected] 2016-05-02_10-37-12]# cat xtrabackup_checkpoints
backup_type = incremental
from_lsn = 24104694
to_lsn = 24104724
last_lsn = 24104724
[[email protected] 2016-05-02_10-37-12]# pwd
/backup/zl_data2/2016-05-02_10-37-12
[[email protected] backup]# innobackupex --apply-log --redo-only --defaults-file=/etc/my.cnf /backup/full_data/2016-05-02_10-24-53/
[[email protected] backup]# innobackupex --apply-log --redo-only --defaults-file=/etc/my.cnf /backup/full_data/2016-05-02_10-24-53/ --incremental-dir=/backup/zl_data/2016-05-02_10-31-50/
[[email protected] backup]# innobackupex --apply-log --redo-only --defaults-file=/etc/my.cnf /backup/full_data/2016-05-02_10-24-53 --incremental-dir=/backup/zl_data2/2016-05-02_10-37-12/

此时所有的redo执做者还原在完全备份中了,所以只要还原,完全备份就可以:

[[email protected] backup]# service mysqld stop
Shutting down MySQL.. SUCCESS!
[[email protected] backup]# rm -rf /alidata/server/mysql/data/*
[[email protected] backup]# innobackupex --copy-back --defaults-file=/etc/my.cnf /backup/full_data/2016-05-02_10-24-53
[[email protected] backup]# chown -R mysql.mysql /alidata/server/mysql/data/
[[email protected] backup]# ls -l /alidata/server/mysql/data/
total 26664
drwxr-xr-x. 2 mysql mysql     4096 May  2 10:46 2016-04-30_15-25-34
drwxr-xr-x. 2 mysql mysql     4096 May  2 10:46 ceshi
-rw-r-----. 1 mysql mysql 27262976 May  2 10:43 ibdata1
drwxr-xr-x. 2 mysql mysql     4096 May  2 10:46 image
drwxr-xr-x. 2 mysql mysql     4096 May  2 10:46 mysql
drwxr-xr-x. 2 mysql mysql     4096 May  2 10:46 performance_schema
drwxr-xr-x. 2 mysql mysql     4096 May  2 10:46 sx
drwxr-xr-x. 2 mysql mysql     4096 May  2 10:46 test
drwxr-xr-x. 2 mysql mysql     4096 May  2 10:46 test2
-rw-r--r--. 1 mysql mysql       24 May  2 10:46 xtrabackup_binlog_pos_innodb
-rw-r--r--. 1 mysql mysql       79 May  2 10:46 xtrabackup_checkpoints
[[email protected] backup]# service mysqld start
Starting MySQL... SUCCESS!
[[email protected] backup]# mysql -uroot -p123456 -e "select * from ceshi.users;"
+----+-----------+----------+--------------+
| id | name      | password | address      |
+----+-----------+----------+--------------+
|  1 | zhang     | 1234     | NULL         |
|  2 | wang      | 4321     | 湖北武汉     |
|  3 | li        | 5678     | 北京海淀     |
|  4 | zhan      | 1234     | NULL         |
|  5 | wan       | 4321     | 湖北武汉     |
|  7 | for       | 777      | kkk          |
|  8 | ck        | 132      | kkk          |
|  9 | kk        | 567      | ddd          |
| 10 | 10t       | 123456   | kkkkdkdkd    |
| 11 | 全备份    | 1234     | full         |
+----+-----------+----------+--------------+

好像失败了!!!

mysql> show create table users;
+-------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                                                                                                                                                                                       |
+-------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| users | CREATE TABLE `users` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(20) NOT NULL,
  `password` varchar(100) NOT NULL,
  `address` varchar(200) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `name` (`name`)
) ENGINE=MyISAM AUTO_INCREMENT=12 DEFAULT CHARSET=utf8 |
+-------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> use test2
Database changed
mysql> show tables ;
+-----------------+
| Tables_in_test2 |
+-----------------+
| articles        |
+-----------------+
1 row in set (0.00 sec)

mysql> show create table articles;
+----------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table    | Create Table                                                                                                                                                                 |
+----------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| articles | CREATE TABLE `articles` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `content` longtext NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8 |
+----------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> select * from articles;
+----+--------------+
| id | content      |
+----+--------------+
| 11 | hahahaha     |
| 12 | xixixi       |
| 13 | aiaiaiaiaiai |
| 14 | hohohoho     |
+----+--------------+
4 rows in set (0.00 sec)

mysql> insert into articles (id,content) values (15,‘全备‘);
Query OK, 1 row affected (0.16 sec)

mysql> select * from articles;
+----+--------------+
| id | content      |
+----+--------------+
| 11 | hahahaha     |
| 12 | xixixi       |
| 13 | aiaiaiaiaiai |
| 14 | hohohoho     |
| 15 | 全备         |
+----+--------------+
5 rows in set (0.00 sec)
innobackupex --defaults-file=/etc/my.cnf --user=root --password=123456 /backup/full_data/
mysql> insert into articles (id,content) values (16,‘增一‘);
Query OK, 1 row affected (0.14 sec)

mysql> select * from articles;
+----+--------------+
| id | content      |
+----+--------------+
| 11 | hahahaha     |
| 12 | xixixi       |
| 13 | aiaiaiaiaiai |
| 14 | hohohoho     |
| 15 | 全备         |
| 16 | 增一         |
+----+--------------+
6 rows in set (0.00 sec)
[[email protected] backup]# innobackupex --defaults-file=/etc/my.cnf --user=root --password=123456 --incremental /backup/zl_data/ --incremental-basedir=/backup/full_data/2016-05-02_11-13-54/
mysql> use test2;
Database changed
mysql> insert into articles (id,content) values (17,‘增二‘);
Query OK, 1 row affected (0.10 sec)

mysql> select * from articles;
+----+--------------+
| id | content      |
+----+--------------+
| 11 | hahahaha     |
| 12 | xixixi       |
| 13 | aiaiaiaiaiai |
| 14 | hohohoho     |
| 15 | 全备         |
| 16 | 增一         |
| 17 | 增二         |
+----+--------------+
7 rows in set (0.00 sec)
# mkdir /backup/zl_data2/
[[email protected] backup]# innobackupex --defaults-file=/etc/my.cnf --user=root --password=123456 --incremental /backup/zl_data2/ --incremental-basedir=/backup/zl_data/2016-05-02_11-18-06/
[[email protected] backup]# innobackupex --apply-log --redo-only --defaults-file=/etc/my.cnf /backup/full_data/2016-05-02_11-13-54/
[[email protected] backup]# innobackupex --apply-log --redo-only --defaults-file=/etc/my.cnf /backup/full_data/2016-05-02_11-13-54/ --incremental-dir=/backup/zl_data/2016-05-02_11-18-06/
[[email protected] backup]# innobackupex --apply-log --redo-only --defaults-file=/etc/my.cnf /backup/full_data/2016-05-02_11-13-54/ --incremental-dir=/backup/zl_data2/2016-05-02_11-21-30/
[[email protected] backup]# service mysqld stop
[[email protected] backup]# rm -rf /alidata/server/mysql/data/*
[[email protected] backup]# innobackupex --copy-back /backup/full_data/2016-05-02_11-13-54
[[email protected] backup]# chown -R mysql.mysql /alidata/server/mysql/data/
[[email protected] backup]# service mysqld start
Starting MySQL... SUCCESS!
mysql> select * from articles;
+----+--------------+
| id | content      |
+----+--------------+
| 11 | hahahaha     |
| 12 | xixixi       |
| 13 | aiaiaiaiaiai |
| 14 | hohohoho     |
| 15 | 全备         |
| 16 | 增一         |
| 17 | 增二         |
+----+--------------+
7 rows in set (0.00 sec)
成功了!!!!!!证明MyISAM不支持增量备份。
时间: 2024-10-26 07:43:58

xtrabackup 增量备份(InnoDB)的相关文章

Xtrabackup 增量备份、恢复、原理

整合了网上的一些资料,结合自己的理解,并进行了实验验证 理解一: 1,Xtrabackup是什么 Xtrabackup是一个对InnoDB做数据备份的工具,支持在线热备份(备份时不影响数据读写),是商业备份工具InnoDB Hotbackup的一个很好的替代品. Xtrabackup有两个主要的工具:xtrabackup.innobackupex (1).xtrabackup只能备份InnoDB和XtraDB两种数据表,而不能备份MyISAM数据表 (2). innobackupex是参考了In

在线热备份数据库之innobackupex 增量备份InnoDB

在线热备份数据库之innobackupex 增量备份InnoDB 什么是增量备份?其原理是什么? 增量备份是基于上一次备份后对新增加的内容进行备份,优点相较于完整备份而言备份内容少时间短,能够节省磁盘空间.但相较于完整备份而言可靠性有所降低,不能缺失基于完整备份的增量备份区间备份包,建议完整备份区间时间不可大于一周,通常情况下如果数据库非常庞大个人建议三天到七天完整备份一次,期间每天进行增量备份.如果数据库小那么每天进行完整备份才是最安全的选择. 增量备份原理是什么?他是如何记录上次备份的位置?

xtrabackup增量备份恢复

一.安装percona-xtrabackup 1.下载软件 percona-xtrabackup-2.2.10.tar.gz 下载网址 http://www.percona.com/downloads/XtraBackup/Percona-XtraBackup-2.2.10/source/ 2.修改profile export LD_LIBRARY_PATH=/opt/mysql/lib 3.编译安装 tar zxvf percona-xtrabackup-2.2.10.tar.gz cd pe

XtraBackup增量备份

mysql:5.6.29xtrabackup:2.2.10mysql数据目录:/data/mysqlmysql备份目录:/data/dbbak/ #确保有足够的磁盘空间 官方文档:https://www.percona.com/doc/percona-xtrabackup/2.2/innobackupex/incremental_backups_innobackupex.html 1.安装依赖 yum -y install libaio perl-Time-HiRes perl-DBD-MySQ

Xtrabackup增量备份、恢复以及时间点恢复

1.记录当前的status信息 | master.000001 |      120 | 2.制作一个完整的备份文件 # innobackupex /backup 备份的文件:/backup/2016-11-16_16-18-54 查看其status信息 # cat xtrabackup_binlog_info master.000001 120 # 3.修改数据库信息以使得status发生变化 比如:创建了一个表tb1,并插入2条记录 mysql> select * from tb1 ; +-

xtrabackup 全备份,增量备份,恢复 mysql数据库

Xtrabackup使用指南 InnoDB数据备份工具 Xtrabackup是一个对InnoDB做数据备份的工具,支持在线热备份(备份时不影响数据读写,也就是不加锁),是商业备份工具InnoDB Hotbackup的一个很好的替代品 一.Xtrabackup介绍  A.Xtrabackup是什么 Xtrabackup是一个对InnoDB做数据备份的工具,支持在线热备份(备份时不影响数据读写),是商业备份工具InnoDB Hotbackup的一个很好的替代品. Xtrabackup有两个主要的工具

XtraBackup全备与增量备份

一.XtraBackup安装 下载地址:http://www.percona.com/downloads/XtraBackup/XtraBackup-2.2.8/source/ 安装步骤: ================================ How to build XtraBackup on Linux ================================ Prerequisites -------------$ yum install cmake gcc gcc-c

Xtrabackup数据库备份工具

Xtrabackup 官方原理 在InnoDB内部会维护一个redo日志文件,我们也可以叫做事务日志文件.事务日志会存储每一个InnoDB表数据的记录修改.当InnoDB启动时,InnoDB会检查数据文件和事务日志,并执行两个步骤:它应用(前滚)已经提交的事务日志到数据文件,并将修改过但没有提交的数据进行回滚操作. Xtrabackup在启动时会记住log sequencenumber(LSN),并且复制所有的数据文件.复制过程需要一些时间,所以这期间如果数据文件有改动,那么将会使数据库处于一个

XtraBackup物理备份(未测试)

XtraBackup物理备份 Percona XtraBackup是世界上唯一的开源,免费的MySQL热备份软件,为InnoDB和XtraDB 数据库执行非阻塞备份.使用Percona XtraBackup,可以实现以下优势: 快速可靠地完成的备份 备份期间的不间断事务处理 节省磁盘空间和网络带宽 自动备份验证 创建热InnoDB备份,而不暂停数据库 对MySQL进行增量备份 将压缩的MySQL备份压缩到另一个服务器 在MySQL服务器之间移动表 轻松创建新的MySQL主从 备份MySQL,而不