生产环境究竟是使用mysqldump还是xtrabackup来备份与恢复数据库Word格式.docx
《生产环境究竟是使用mysqldump还是xtrabackup来备份与恢复数据库Word格式.docx》由会员分享,可在线阅读,更多相关《生产环境究竟是使用mysqldump还是xtrabackup来备份与恢复数据库Word格式.docx(27页珍藏版)》请在冰豆网上搜索。
apt-getinstalldebhelperautotools-devlibaio-devwgetautomakelibtoolbisonlibncurses-devlibz-devcmakebzr
如果是redhat系列的话
yuminstallcmakegccgcc-c++libaiolibaio-develautomakeautoconfbzrbisonlibtoolncurses-develzlib-devel
3、解压
tarzxvfxtrabackup-1.6.7.tar.gz
4、进入目录
cdxtrabackup-1.6.7
5、复制
cdbin
cp*/usr/bin
然后就安装完成了,下面开始备份
其中,
innobackupex是我们要使用的备份工具;
xtrabackup是被封装在innobackupex之中的,innobackupex运行时需要调用它;
xtrabackup_51是xtrabackup运行时需要调用的工具;
tar4ibd是以tar流的形式产生备份时用来打包的工具。
6、对某个数据库进行全部备份的命令介绍
innobackupex--user=root--password=123456--defaults-file=/etc/mysql/f--database=test--stream=tar/tmp/data/2>
/tmp/data/err.log|gzip1>
/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-uroot-p
Enterpassword:
WelcometotheMySQLmonitor.Commandsendwith;
or\g.
YourMySQLconnectionidis40
Serverversion:
5.5.28-0ubuntu0.12.04.3-log(Ubuntu)
Copyright(c)2000,2012,Oracleand/oritsaffiliates.Allrightsreserved.
OracleisaregisteredtrademarkofOracleCorporationand/orits
affiliates.Othernamesmaybetrademarksoftheirrespective
owners.
Type'
help;
'
or'
\h'
forhelp.Type'
\c'
toclearthecurrentinputstatement.
mysql>
dropdatabasetest;
QueryOK,3rowsaffected(0.13sec)
createdatabasetest;
QueryOK,1rowaffected(0.00sec)
usetest;
Databasechanged
createtabletest(idint);
QueryOK,0rowsaffected(0.06sec)
insertintotestvalues
(1);
QueryOK,1rowaffected(0.04sec)
insertintotestvalues
(2);
QueryOK,1rowaffected(0.01sec)
insertintotestvalues(3);
insertintotestvalues(4);
insertintotestvalues(5);
select*fromtest;
+------+
|id|
|1|
|2|
|3|
|4|
|5|
5rowsinset(0.00sec)
flushprivileges;
QueryOK,0rowsaffected(0.00sec)
(2)然后备份test的整个数据库
使用下面的backup.sh脚本
/tmp#catbackup.sh
#!
/bin/bash
user='
root'
passwd='
123456'
database=test
my_config='
/etc/mysql/f'
log=$database-$(date+%Y%m%d%H%M).log
str=$database-$(date+%Y%m%d%H%M).tar.gz
backup_dir='
/tmp/data'
echo"
Starttobackupat$(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_dir2>
$backup_dir/$log|gzip1>
$backup_dir/$str
if[$?
-eq0];
echo"
Backupisfinish!
at$(date+%Y%m%d%H%M)"
exit0
else
BackupisFail!
exit1
现在开始运行此脚本
/tmp#shbackup.sh
Starttobackupat201303072101
at201303072102
然后到data里查看结果
/tmp#cddata
/tmp/data#ll
total3272
drwxr-xr-x2rootroot4096Mar721:
01./
drwxrwxrwt13rootroot4096Mar721:
02../
-rw-r--r--1rootroot3780Mar721:
02test-201303072101.log
-rw-r--r--1rootroot3336909Mar721:
02test-201303072101.tar.gz
/tmp/data#cattest-201303072101.log
InnoDBBackupUtilityv1.5.1-xtrabackup;
Copyright2003,2009InnobaseOy
andPerconaInc2009-2012.AllRightsReserved.
Thissoftwareispublishedunder
theGNUGENERALPUBLICLICENSEVersion2,June1991.
13030721:
01:
39innobackupex:
Startingmysqlwithoptions:
--defaults-file='
--password=xxxxxxxx--user='
--unbuffered--
Connectedtodatabasewithmysqlchildprocess(pid=12441)
45innobackupex:
Connectiontodatabaseserverclosed
IMPORTANT:
Pleasecheckthatthebackupruncompletessuccessfully.
Attheendofasuccessfulbackupruninnobackupex
p