本篇内容主要讲解“怎么用innobackupex备份mysql数据库”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“怎么用innobackupex备份mysql数据库”吧!
innobackupex类似于Oracle的rman,可以进行热备,需要在服务器端执行,是进行mysql备份最常用的工具之一。
1、安装工具
[root@my ~]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 6.4 (Santiago)
[root@my ~]# rpm -ivh libev-4.15-1.el6.rf.x86_64.rpm percona-xtrabackup-24-2.4.4-1.el6.x86_64.rpm
2、创建备份专用账户并授予权限
(root@localhost)[(none)] create user xtrabk@'localhost' identified by 'xtrabk';
Query OK, 0 rows affected (0.00 sec)
(root@localhost)[(none)] grant reload,process,lock tables,replication client,super on *.* to xtrabk@'localhost';
Query OK, 0 rows affected (0.00 sec)
(root@localhost)[(none)] flush privileges;
Query OK, 0 rows affected (0.00 sec)
3、备份整个数据库
[root@my ~]# innobackupex --defaults-file=/etc/my.cnf --user=xtrabk --password=xtrabk /var/lib/mysql/backup/innobackupex/
将备份文件放在了自动按照时间日期生成的目录下面。
[root@my ~]# ll -rth /var/lib/mysql/backup/innobackupex/2017-06-20_16-33-30/
total 77M
-rw-r----- 1 root root 76M Jun 20 16:33 ibdata1
drwxr-x--- 2 root root 4.0K Jun 20 16:33 test
drwxr-x--- 2 root root 4.0K Jun 20 16:33 performance_schema
drwxr-x--- 2 root root 4.0K Jun 20 16:33 mysql
drwxr-x--- 2 root root 12K Jun 20 16:33 sys
drwxr-x--- 2 root root 4.0K Jun 20 16:33 5ienet
-rw-r----- 1 root root 21 Jun 20 16:33 xtrabackup_binlog_info
-rw-r----- 1 root root 2.5K Jun 20 16:33 xtrabackup_logfile
-rw-r----- 1 root root 119 Jun 20 16:33 xtrabackup_checkpoints
-rw-r----- 1 root root 504 Jun 20 16:33 ib_buffer_pool
-rw-r----- 1 root root 435 Jun 20 16:33 backup-my.cnf
-rw-r----- 1 root root 524 Jun 20 16:33 xtrabackup_info
其中xtrabackup_checkpoints文件记录InnoDB的Log Sequence Number,可以对InnoDB引擎表进行增量备份。
4、进行增量备份
先执行一些操作:
(root@localhost)[test] insert into test1 values('bb');
Query OK, 1 row affected (0.17 sec)
(root@localhost)[test] select * from test1;
+------+
| v1 |
+------+
| aa |
| bb |
+------+
2 rows in set (0.00 sec)
(root@localhost)[test] create table test4 as select * from test1;
Query OK, 2 rows affected (0.81 sec)
Records: 2 Duplicates: 0 Warnings: 0
(root@localhost)[test] select * from test4;
+------+
| v1 |
+------+
| aa |
| bb |
+------+
2 rows in set (0.02 sec)
再进行增量备份:
[root@my ~]# innobackupex --defaults-file=/etc/my.cnf --user=xtrabk --password=xtrabk --incremental --incremental_basedir=/var/lib/mysql/backup/innobackupex/2017-06-20_16-33-30/ /var/lib/mysql/backup/innobackupex/
输入日志有出现:
xtrabackup: Transaction log of lsn (2338925034) to (2338925043) was copied.
表示增量备份从lsn2338925034到2338925043。
到此,相信大家对“怎么用innobackupex备份mysql数据库”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!