mysql之7xtrabackup
- 1、无需停止数据库进行InnoDB热备
- 2、增量备份MySQL
- 3、流压缩到传输到其它服务器
- 4、能比较容易地创建主从同步
- 5、备份MySQL时不会增大服务器负载
(1)xtrabackup只能备份InnoDB和XtraDB两种数据表,而不能备份MyISAM数据表
(2)innobackupex-1.5.1则封装了xtrabackup,是一个脚本封装,所以能同时备份处理innodb和myisam,但在处理myisam时需要加一个读锁
[root@bogon ~]# cat
/etc/issue
CentOS release 6.5
(Final)
Kernel \r on an \m
[root@bogon ~]# mysql -V
mysql
Ver 14.14
Distrib 5.6.13, for linux-glibc2.5 (x86_64) using
EditLine wrapper
[root@bogon ~]# xtrabackup -v
xtrabackup version 2.1.8 for Percona Server 5.1.73 unknown-linux-gnu
(x86_64) (revision id: 733)
innobackupex: Error: Failed to
connect to MySQL server: DBI connect(‘;mysql_read_default_group=xtrabackup‘,‘root‘,...)
failed: Can‘t connect to
local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘ (2) at /usr/bin/innobackupex line
2945
[root@localhost mysql]# innobackupex --user=root
--password=123456 --socket=/tmp/mysql.sock
/data/back_data/
[root@localhost mysql]# ls
/data/back_data/2014-04-09_19-35-40/
backup-my.cnf ib_logfile0 mysql
test
xtrabackup_checkpoints
ibdata1 ib_logfile1
performance_schema xtrabackup_binary
xtrabackup_logfile
官方解析>>
After creating a backup, the
data is not ready to be restored. There
might be uncommitted transactions to be undone or
transactions in
the logs to be replayed. Doing those pending operations will make the data files
consistent and
it is the purpose of the prepare stage . Once this has been done,
the data is ready to be
used.
首先模拟故障,删除所有数据库,(我这里的路径是/mydata)
[root@localhost mydata]# rm -rf *
[root@localhost mydata]#
ls
开始恢复,停止mysql
[root@localhost
mydata]# service mysqld stop
Shutting down
MySQL... SUCCESS!
从备份文件中启动MySQL服务
[root@localhost mydata]# innobackupex
--user=root --password=123456 --apply-log
/data/back_data/2014-04-09_19-35-40/
从备份文件中copy数据到my.cnf中指定的数据库位置
[root@localhost
mydata]# innobackupex --user=root --password=123456
--copy-back
/data/back_data/2014-04-09_19-35-40/
[root@localhost mydata]# ll
total 110604
-rw-r--r--. 1 root root 12582912 Apr
9 19:40 ibdata1
-rw-r--r--. 1 root root 50331648
Apr 9 19:40 ib_logfile0
-rw-r--r--. 1 root root 50331648 Apr
9 19:40 ib_logfile1
drwxr-xr-x. 2 root root 4096 Apr 9 19:40 mysql
drwxr-xr-x. 2 root root
4096 Apr 9 19:40
performance_schema
drwxr-xr-x. 2 root root
4096 Apr 9 19:40 test
修改数据库权限
[root@localhost
mydata]# chown -R mysql.mysql /mydata
启动成功
[root@localhost
mydata]# service mysqld start
Starting
MySQL...... SUCCESS!
[root@localhost mysql]# mysql
-uroot -p123456
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 1
Server
version: 5.6.13 MySQL Community Server (GPL)
Copyright (c) 2000, 2013, 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>
mysql> show databases;
+--------------------+
| Database
|
+--------------------+
| information_schema
|
| mysql
|
| performance_schema |
| test
|
+--------------------+
4 rows in
set (0.11
sec)
[root@localhost ~]# ls
/data/back_data/
2014-04-09_19-35-40
mysql> CREATE DATABASE in1;
Query OK,
1 row affected (0.07 sec)
mysql> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema
|
| in1
|
| mysql
|
|
performance_schema |
| test
|
+--------------------+
5 rows in set (0.00 sec)
[root@localhost ~]#
innobackupex --user=root --password=123456 --socket=/tmp/mysql.sock
--incremental-basedir=/data/back_data/2014-04-09_19-35-40/ --incremental
/data/back_data/
[root@localhost ~]# ls
/data/back_data/
2014-04-09_19-35-40 2014-04-10_11-25-56
mysql> CREATE DATABASE in2;
Query OK,
1 row affected (0.08 sec)
mysql> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema
|
| in1
|
| in2
|
| mysql
|
|
performance_schema |
| test
|
+--------------------+
6 rows in set (0.05
sec)
[root@localhost ~]#
innobackupex --user=root --password=123456 --socket=/tmp/mysql.sock
--incremental-basedir=/data/back_data/2014-04-10_11-25-56/ --incremental
/data/back_data/
[root@localhost ~]# ls
/data/back_data/
2014-04-09_19-35-40 2014-04-10_11-25-56 2014-04-10_11-48-44
官方解析>>
Note:
--redo-only
should be used when merging all incrementals except the last one. That’s why the
previous
line doesn’t contain the --redo-only option. Even
if the --redo-only was used on the
last step, backup would
still be consistent but in that case
server would perform the rollback
phase.
[root@localhost ~]#
service mysqld stop
Shutting down MySQL................ SUCCESS!
[root@localhost mydata]# rm
-rf *
[root@localhost mydata]#
ls
[root@localhost ~]#
innobackupex --user=root --password=123456 --apply-log --redo-only
/data/back_data/2014-04-09_19-35-40/
[root@localhost ~]# innobackupex --user=root --password=123456 --apply-log
--redo-only --incremental-dir=/data/back_data/2014-04-10_11-25-56/
/data/back_data/2014-04-09_19-35-40/
[root@localhost ~]# innobackupex --user=root --password=123456 --apply-log
--incremental-dir=/data/back_data/2014-04-10_11-48-44/
/data/back_data/2014-04-09_19-35-40/
[root@localhost ~]#
innobackupex --user=root --password=123456 --apply-log
/data/back_data/2014-04-09_19-35-40/
[root@localhost ~]# innobackupex --user=root --password=123456 --copy-back
/data/back_data/2014-04-09_19-35-40/
[root@localhost mydata]# ls
ibdata1
ib_logfile0 ib_logfile1 in1 in2
mysql performance_schema
test
[root@localhost mydata]# chown -R mysql.mysql
.
[root@localhost ~]#
service mysqld start
Starting MySQL....... SUCCESS!
[root@localhost
~]# mysql -uroot
-p123456
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 1
Server version:
5.6.13
MySQL Community Server (GPL)
Copyright (c) 2000, 2013, 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
|
| in1
|
| in2
|
| mysql
|
|
performance_schema |
| test
|
+--------------------+
6 rows in set (0.12
sec)
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。