Chinaunix首页 | 论坛 | 博客
  • 博客访问: 111749
  • 博文数量: 10
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 54
  • 用 户 组: 普通用户
  • 注册时间: 2013-10-29 16:20
个人简介

新入行DBA,带着强烈的求知欲望混迹于各社区,学习高人经验,愿得高人赐教,必将感激不尽。 真心感谢将宝贵经验分享给我们这些菜鸟的前辈们!

文章分类
文章存档

2014年(1)

2013年(9)

分类: Mysql/postgreSQL

2013-10-31 15:36:06

6.percona xtrabackup 的使用示例:

(1)全备:

[root@test06 backup]# innobackupex-1.5.1 --user=root --password="123" /data/backup/

InnoDB Backup Utility v1.5.1-xtrabackup; Copyright 2003, 2009 Innobase Oy
……………………
innobackupex-1.5.1: Backup created in directory '/data/backup/2013-10-24_17-41-34'
131024 17:41:40  innobackupex-1.5.1: Connection to database server closed
131024 17:41:40  innobackupex-1.5.1: completed OK!

(2)修改数据库

[root@test06 backup]# mysql -uroot -p
Enter password: 
…………

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.02 sec)

mysql> create database test_10291350;
Query OK, 1 row affected (0.01 sec)

mysql> use test_10291350;
Database changed
mysql> create table test01(id int);
Query OK, 0 rows affected (0.12 sec)

mysql> insert into test01 values(1);
Query OK, 1 row affected (0.02 sec)

mysql> commit;
Query OK, 0 rows affected (0.00 sec)

(3)增量备份

[root@test06 backup]# innobackupex --incremental /data/backup/ --user=root --password="123"

InnoDB Backup Utility v1.5.1-xtrabackup; Copyright 2003, 2009 Innobase Oy
………………
innobackupex: Backup created in directory '/data/backup/2013-10-24_17-43-28'
131024 17:43:35  innobackupex: Connection to database server closed
131024 17:43:35  innobackupex: completed OK!

(4)查看检查点信息

[root@test06 backup]# ls
2013-10-24_17-41-34  2013-10-24_17-43-28
[root@test06 backup]# cd 2013-10-24_17-41-34/
[root@test06 2013-10-24_17-41-34]# ls
backup-my.cnf  ibdata1  mysql  performance_schema  test  xtrabackup_binary  xtrabackup_checkpoints  xtrabackup_logfile
[root@test06 2013-10-24_17-41-34]# cat xtrabackup_checkpoints 
backup_type = full-backuped
from_lsn = 0
to_lsn = 1625997
last_lsn = 1625997
compact = 0
[root@test06 2013-10-24_17-41-34]# cat ../2013-10-24_17-43-28/xtrabackup_checkpoints 
backup_type = incremental
from_lsn = 1625997
to_lsn = 1630895
last_lsn = 1630895
compact = 0

(5)全备prepare

[root@test06 2013-10-24_17-41-34]# innobackupex --user=root --password=123 --apply-log /data/backup/2013-10-24_17-41-34/

InnoDB Backup Utility v1.5.1-xtrabackup; Copyright 2003, 2009 Innobase Oy
………………
InnoDB: Shutdown completed; log sequence number 1626134
131024 17:46:24  innobackupex: completed OK!

(6)全备目录生成新文件

[root@test06 2013-10-24_17-41-34]# ls
backup-my.cnf  ib_logfile0  mysql               test               xtrabackup_checkpoints
ibdata1        ib_logfile1  performance_schema  xtrabackup_binary  xtrabackup_logfile


[root@test06 2013-10-24_17-41-34]# cat xtrabackup_checkpoints
backup_type = full-prepared
from_lsn = 0
to_lsn = 1625997
last_lsn = 1625997
compact = 0

(7)增备prepare

[root@test06 backup]# innobackupex --apply-log --redo-only /data/backup/2013-10-24_17-41-34/ --incremental-dir=/data/backup/2013-10-24_17-43-28/ --user=root --password=123

InnoDB Backup Utility v1.5.1-xtrabackup; Copyright 2003, 2009 Innobase Oy
……………………
innobackupex: Copying '/data/backup/2013-10-24_17-43-28/mysql/user.frm' to '/data/backup/2013-10-24_17-41-34/mysql/user.frm'
131024 18:43:20  innobackupex: completed OK!

(8)查看全备目录

[root@test06 2013-10-24_17-43-28]# cd ../2013-10-24_17-41-34/

[root@test06 2013-10-24_17-41-34]# ll
total 112668
-rw-r--r--. 1 root root      293 Oct 24 17:41 backup-my.cnf
-rw-r-----. 1 root root 12582912 Oct 24 18:43 ibdata1
-rw-r--r--. 1 root root 50331648 Oct 24 17:46 ib_logfile0
-rw-r--r--. 1 root root 50331648 Oct 24 17:46 ib_logfile1
drwx------. 2 root root     4096 Oct 24 17:41 mysql
drwxr-xr-x. 2 root root     4096 Oct 24 17:41 performance_schema
drwxr-xr-x. 2 root root     4096 Oct 24 17:41 test
drwxr-x---. 2 root root     4096 Oct 24 18:43 test_10291350
-rw-r--r--. 1 root root       13 Oct 24 17:41 xtrabackup_binary
-rw-r-----. 1 root root       89 Oct 24 18:43 xtrabackup_checkpoints
-rw-r-----. 1 root root  2097152 Oct 24 17:46 xtrabackup_logfile

[root@test06 2013-10-24_17-41-34]# cat xtrabackup_checkpoints 
backup_type = full-prepared
from_lsn = 0
to_lsn = 1630895
last_lsn = 1630895
compact = 0

已恢复至增备后的检查点


[root@test06 2013-10-24_17-41-34]# date
Thu Oct 24 18:48:08 CST 2013

(9)破坏数据库

注:恢复举例时未设置root密码

[root@test06 ~]# cd /data/mysql/
[root@test06 mysql]# ll
total 110608
-rw-r--r--. 1 root root 12582912 Oct 24 14:21 ibdata1
-rw-r--r--. 1 root root 50331648 Oct 24 14:21 ib_logfile0
-rw-r--r--. 1 root root 50331648 Oct 24 14:21 ib_logfile1
drwxr-xr-x. 2 root root     4096 Oct 24 14:21 mysql
drwxr-xr-x. 2 root root     4096 Oct 24 14:21 performance_schema
drwxr-xr-x. 2 root root     4096 Oct 24 14:21 test
drwxr-xr-x. 2 root root     4096 Oct 24 14:21 test01
[root@test06 mysql]# rm -fr *            必须清空/data/mysql
[root@test06 mysql]# mysql -uroot 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.6.13-56 Percona Server (GPL), Release rel61.0, Revision 461

Copyright (c) 2009-2013 Percona LLC and/or its affiliates
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 |
+--------------------+
1 row in set (0.00 sec)

mysql> exit;
Bye


(10)用全备+增备恢复数据库

[root@test06 mysql]# innobackupex --copy-back /data/backup/2013-10-24_14-12-53/

InnoDB Backup Utility v1.5.1-xtrabackup; Copyright 2003, 2009 Innobase Oy
……………………
innobackupex: Copying '/data/backup/2013-10-24_14-12-53/performance_schema/events_stages_summary_by_account_by_event_name.frm' to '/data/mysql/performance_schema/events_stages_summary_by_account_by_event_name.frm'
……………………
131024 14:22:41  innobackupex: completed OK!


(11)查看恢复结果

[root@test06 mysql]# mysql -uroot 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.6.13-56 Percona Server (GPL), Release rel61.0, Revision 461

Copyright (c) 2009-2013 Percona LLC and/or its affiliates
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 |
| mysql              |
| performance_schema |
| test               |
| test01             |
+--------------------+
5 rows in set (0.00 sec)

mysql> exit;
Bye




阅读(6941) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~