没有合适的资源?快使用搜索试试~ 我知道了~
生产环境究竟是使用mysqldump还是xtrabackup来备份与恢复数据库.doc
需积分: 50 31 下载量 184 浏览量
2017-12-15
13:10:12
上传
评论 1
收藏 106KB DOC 举报
温馨提示
试读
19页
生产环境究竟是使用mysqldump还是xtrabackup来备份与恢复数据库 一个合格的运维工程师或者dba工程师,如果有从事数据库方面的话,首先需要做的就是备份,如果没有备份,出现问题的话,你的业务就会出问题,你的工作甚至会。。。 所以备份是重要的,但光有备份还不行,备份后如果出现问题,你还得使用备份数据来恢复,但恢复数据的时间一般都是很长的,不符合业务需求,所以一个快速备份与恢复的软件就很有必要
资源推荐
资源详情
资源评论
生产环境究竟是使用 mysqldump 还是 xtrabackup 来备份与恢复数据库
一个合格的运维工程师或者 dba 工程师,如果有从事数据库方面的话,首先需要做的就是
备份,如果没有备份,出现问题的话,你的业务就会出问题,你的工作甚至会。。。
所以备份是重要的,但光有备份还不行,备份后如果出现问题,你还得使用备份数据来恢
复,但恢复数据的时间一般都是很长的,不符合业务需求,所以一个快速备份与恢复的软
件就很有必要。
之前我在维护 mysql 数据库的时候,使用 mysqldump 来进行备份与恢复,在备份的时候锁
住表,然后全部备份,在数据少的时候没问题,但如果数据很多,不允许锁表,同时需要
恢复数据块的情况,mysqldump 就不适合了,我在恢复一个 4G 数据文件的数据库的时候,
恢复的数据是使用 mysqldump 的数据,恢复了 3 个小时还没有反应,造成的影响很严重,
所以我开始寻找其他的别发软件来满足以上的需求,幸好找到了,就是使用 xtrabackup 来
进行备份与恢复,恢复 4G 数据文件的数据库,仅需要 14 秒,同时在备份的时候不会锁表,
而且支持增量备份,所以把我的比较分享给大家,希望对大家有益!
Xtrabackup 是 percona 公司的开源项目,用以实现类似 innodb 官方的热备份工具 InnoDB
Hot Backup 的功能,能够非常快速地备份与恢复 mysql 数据库。 Xtrabackup 中包含两个工
具:
xtrabackup 是用于热备份 innodb, xtradb 表中数据的工具,不能备份其他类型的表,也不能
备份数据表结构;
innobackupex 是将 xtrabackup 进行封装的 perl 脚本,提供了备份 myisam 表的能力。
由于 innobackupex 的功能更为全面和完善,所以,本文以 innobackupex 作为基础进行研究
描述。
下面介绍 xtrabackup 的全部、增量的备份与恢复。
一、下载与安装
1、下载
wget
2、安装依赖库
如果是 debian 系列的话
apt-get install debhelper autotools-dev libaio-dev wget automake libtool bison libncurses-dev
libz-dev cmake bzr
如果是 redhat 系列的话
yum install cmake gcc gcc-c++ libaio libaio-devel automake autoconf bzr bison libtool ncurses-
devel zlib-devel
3、解压
tar zxvf xtrabackup-1.6.7.tar.gz
4、进入目录
cd xtrabackup-1.6.7
5、复制
cd bin
cp * /usr/bin
然后就安装完成了,下面开始备份
其中,
innobackupex 是我们要使用的备份工具;
xtrabackup 是被封装在 innobackupex 之中的,innobackupex 运行时需要调用它;
xtrabackup_51 是 xtrabackup 运行时需要调用的工具;
tar4ibd 是以 tar 流的形式产生备份时用来打包的工具。
6、对某个数据库进行全部备份的命令介绍
innobackupex --user=root --password=123456 --defaults-file=/etc/mysql/my.cnf --database=test --
stream=tar /tmp/data/ 2>/tmp/data/err.log|gzip 1>/tmp/data/test.tar.gz
说明:
--database=test 单独对 test 数据库做备份 ,若是不添加此参数那就那就是对全库做备份
2>/tmp/data/err.log 输出信息写入日志中
1>/tmp/data/test.tar.gz 打包压缩存储到该文件中
二、对数据库的全部备份与恢复
下面开始测试 xtrabackup 的全部备份
(1)先进入 mysql 里创建一个新的 test 数据库
root@client2:/tmp# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 40
Server version: 5.5.28-0ubuntu0.12.04.3-log (Ubuntu)
Copyright (c) 2000, 2012, 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> drop database test;
Query OK, 3 rows affected (0.13 sec)
mysql> create database test;
Query OK, 1 row affected (0.00 sec)
mysql> use test;
Database changed
mysql> create table test (id int);
Query OK, 0 rows affected (0.06 sec)
mysql> insert into test values(1);
Query OK, 1 row affected (0.04 sec)
mysql> insert into test values(2);
Query OK, 1 row affected (0.01 sec)
mysql> insert into test values(3);
Query OK, 1 row affected (0.00 sec)
mysql> insert into test values(4);
Query OK, 1 row affected (0.00 sec)
mysql> insert into test values(5);
Query OK, 1 row affected (0.01 sec)
mysql> select * from test;
+------+
| id |
+------+
| 1 |
| 2 |
| 3 |
| 4 |
| 5 |
+------+
5 rows in set (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
(2)然后备份 test 的整个数据库
使用下面的 backup.sh 脚本
root@client2:/tmp# cat backup.sh
#!/bin/bash
user='root'
passwd='123456'
database=test
my_config='/etc/mysql/my.cnf'
log=$database-$(date +%Y%m%d%H%M).log
str=$database-$(date +%Y%m%d%H%M).tar.gz
backup_dir='/tmp/data'
echo "Start to backup at $(date +%Y%m%d%H%M)"
if [ ! -d "$backup_dir" ];then
mkdir $backup_dir
fi
innobackupex --user=$user --password=$passwd --defaults-file=$my_config --
database=$database --stream=tar $backup_dir 2>$backup_dir/$log | gzip 1>$backup_dir/$str
if [ $? -eq 0 ];then
echo "Backup is finish! at $(date +%Y%m%d%H%M)"
exit 0
else
echo "Backup is Fail! at $(date +%Y%m%d%H%M)"
exit 1
fi
现在开始运行此脚本
root@client2:/tmp# sh backup.sh
Start to backup at 201303072101
Backup is finish! at 201303072102
然后到 data 里查看结果
root@client2:/tmp# cd data
root@client2:/tmp/data# ll
total 3272
drwxr-xr-x 2 root root 4096 Mar 7 21:01 ./
drwxrwxrwt 13 root root 4096 Mar 7 21:02 ../
-rw-r--r-- 1 root root 3780 Mar 7 21:02 test-201303072101.log
-rw-r--r-- 1 root root 3336909 Mar 7 21:02 test-201303072101.tar.gz
root@client2:/tmp/data# cat test-201303072101.log
InnoDB Backup Utility v1.5.1-xtrabackup; Copyright 2003, 2009 Innobase Oy
and Percona Inc 2009-2012. All Rights Reserved.
This software is published under
the GNU GENERAL PUBLIC LICENSE Version 2, June 1991.
130307 21:01:39 innobackupex: Starting mysql with options: --defaults-file='/etc/mysql/my.cnf'
--password=xxxxxxxx --user='root' --unbuffered --
130307 21:01:39 innobackupex: Connected to database with mysql child process (pid=12441)
130307 21:01:45 innobackupex: Connection to database server closed
IMPORTANT: Please check that the backup run completes successfully.
At the end of a successful backup run innobackupex
prints "completed OK!".
innobackupex: Using mysql Ver 14.14 Distrib 5.5.28, for debian-linux-gnu (x86_64) using
readline 6.2
innobackupex: Using mysql server version Copyright (c) 2000, 2012, Oracle and/or its affiliates.
All rights reserved.
innobackupex: Created backup directory /tmp/data
130307 21:01:45 innobackupex: Starting mysql with options: --defaults-file='/etc/mysql/my.cnf'
--password=xxxxxxxx --user='root' --unbuffered --
130307 21:01:45 innobackupex: Connected to database with mysql child process (pid=12471)
130307 21:01:47 innobackupex: Connection to database server closed
130307 21:01:47 innobackupex: Starting ibbackup with command: xtrabackup_55 --defaults-
file="/etc/mysql/my.cnf" --backup --suspend-at-end --log-stream --target-dir=/tmp
innobackupex: Waiting for ibbackup (pid=12478) to suspend
innobackupex: Suspend file '/tmp/xtrabackup_suspended'
剩余18页未读,继续阅读
资源评论
可爱的空心菜
- 粉丝: 0
- 资源: 9
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功