这篇文章将为大家详细讲解有关如何使用Xtrabackup备份MySQL数据库,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

本文则演示如何从xtrabackup的备份中进行恢复。本次恢复的是一个600GB大小的InnoDB数据库,备份的时候没有使用gzip压缩。

首先将备份好的tar文件解开到目标数据库的数据路径下,这一步类似oracle的restore database:

[@more@]

tar-ixvfmysqlbak.tar/opt/mysqldata

(注意这里一定要加i参数,不然无法解压出来)

注意解出来的文件和目录的属主以及权限是否正确。如果是将备份恢复到一台全新的环境,则需要修改/etc/my.cnf,将innodb_data_file_path等参数设置和原备份的库一致。然后执行:

$innobackupex-1.5.1--apply-log/opt/mysqldata

这一步类似于oracle的recover database,从日志来看,差不多一个小时执行完毕,该InnoDB数据库分配空间600GB,实际使用空间约590GB,并且数据的更新量还是比较大的,大约一个小时apply-log完成。运行的日志简单记录如下:

InnoDBBackupUtilityv1.5.1-xtrabackup;Copyright2003,2009InnobaseOy.AllRightsReserved.ThissoftwareispublishedundertheGNUGENERALPUBLICLICENSEVersion2,June1991.IMPORTANT:Pleasecheckthattheapply-logruncompletessuccessfully.Attheendofasuccessfulapply-logruninnobackupprints"innobackupcompletedOK!".09070809:50:44innobackupex:Startingibbackupwithcommand:xtrabackup--prepare--target-dir=/opt/mysqldataxtrabackupVerrc-0.7for5.0.77unknown-linux-gnu(x86_64)xtrabackup:cdto/opt/mysqldataxtrabackup:Thistargetseemstobenotpreparedyet.xtrabackup:xtrabackup_logfiledetected:size=2882535424,start_lsn=(5142288109039)xtrabackup:Temporaryinstanceforrecoveryissetasfollowings.xtrabackup:innodb_data_home_dir=./xtrabackup:innodb_data_file_path=ibdata1:10000M;ibdata2:10000M;ibdata3:10000M...;ibdata60:10000Mxtrabackup:innodb_log_group_home_dir=./xtrabackup:innodb_log_files_in_group=1xtrabackup:innodb_log_file_size=2882535424xtrabackup:StartingInnoDBinstanceforrecovery.xtrabackup:Using104857600bytesforbufferpool(setby--use-memoryparameter)InnoDB:Logscanprogressedpastthecheckpointlsn51422881090390907089:50:45InnoDB:Databasewasnotshutdownnormally!InnoDB:Startingcrashrecovery.InnoDB:Readingtablespaceinformationfromthe.ibdfiles...InnoDB:Doingrecovery:scanneduptologsequencenumber5142293351424(0%)InnoDB:Doingrecovery:scanneduptologsequencenumber5142298594304(0%)InnoDB:Doingrecovery:scanneduptologsequencenumber5142303837184(0%)InnoDB:Doingrecovery:scanneduptologsequencenumber5142309080064(0%)0907089:50:47InnoDB:Startinganapplybatchoflogrecordstothedatabase...InnoDB:Progressinpercents:0123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899InnoDB:ApplybatchcompletedInnoDB:Doingrecovery:scanneduptologsequencenumber5142314322944(1%)InnoDB:Doingrecovery:scanneduptologsequencenumber5142319565824(1%)InnoDB:Doingrecovery:scanneduptologsequencenumber5142324808704(1%)InnoDB:Doingrecovery:scanneduptologsequencenumber5142330051584(1%)InnoDB:Doingrecovery:scanneduptologsequencenumber5142335294464(1%)...这里省略若干行InnoDB:Doingrecovery:scanneduptologsequencenumber5143881944064(62%)InnoDB:Doingrecovery:scanneduptologsequencenumber5143887186944(62%)InnoDB:Doingrecovery:scanneduptologsequencenumber5143887732530(62%)09070810:52:00InnoDB:Startinganapplybatchoflogrecordstothedatabase...InnoDB:Progressinpercents:0123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899InnoDB:ApplybatchcompletedInnoDB:InaMySQLreplicationslavethelastmasterbinlogfileInnoDB:position0350504077,filenamemysql-bin.000748InnoDB:LastMySQLbinlogfileposition036434864,filename/opt/mysqllog/mysql-bin.00301509070810:52:17InnoDB:Started;logsequencenumber5143887732530[notice(again)]Ifyouusebinaryloganddon'tuseanyhackofgroupcommit,thebinarylogpositionseemstobe:InnoDB:LastMySQLbinlogfileposition036434864,filename/opt/mysqllog/mysql-bin.003015xtrabackup:startingshutdownwithinnodb_fast_shutdown=109070810:52:17InnoDB:Startingshutdown...09070810:52:24InnoDB:Shutdowncompleted;logsequencenumber514388773253009070810:52:24innobackupex:Restartingxtrabackupwithcommand:xtrabackup--prepare--target-dir=/opt/mysqldataforcreatingib_logfile*xtrabackupVerrc-0.7for5.0.77unknown-linux-gnu(x86_64)xtrabackup:cdto/opt/mysqldataxtrabackup:Thistargetseemstobealreadyprepared.xtrabackup:notice:xtrabackup_logfilewasalreadyusedto'--prepare'.xtrabackup:Temporaryinstanceforrecoveryissetasfollowings.xtrabackup:innodb_data_home_dir=./xtrabackup:innodb_data_file_path=ibdata1:10000M;ibdata2:10000M;ibdata3:10000M;...;ibdata60:10000Mxtrabackup:innodb_log_group_home_dir=./xtrabackup:innodb_log_files_in_group=4xtrabackup:innodb_log_file_size=104857600xtrabackup:StartingInnoDBinstanceforrecovery.xtrabackup:Using104857600bytesforbufferpool(setby--use-memoryparameter)09070810:52:25InnoDB:Logfile./ib_logfile0didnotexist:newtobecreatedInnoDB:Settinglogfile./ib_logfile0sizeto100MBInnoDB:Databasephysicallywritesthefilefull:wait...InnoDB:ProgressinMB:10009070810:52:25InnoDB:Logfile./ib_logfile1didnotexist:newtobecreatedInnoDB:Settinglogfile./ib_logfile1sizeto100MBInnoDB:Databasephysicallywritesthefilefull:wait...InnoDB:ProgressinMB:10009070810:52:26InnoDB:Logfile./ib_logfile2didnotexist:newtobecreatedInnoDB:Settinglogfile./ib_logfile2sizeto100MBInnoDB:Databasephysicallywritesthefilefull:wait...InnoDB:ProgressinMB:10009070810:52:26InnoDB:Logfile./ib_logfile3didnotexist:newtobecreatedInnoDB:Settinglogfile./ib_logfile3sizeto100MBInnoDB:Databasephysicallywritesthefilefull:wait...InnoDB:ProgressinMB:100InnoDB:ThelogsequencenumberinibdatafilesdoesnotmatchInnoDB:thelogsequencenumberintheib_logfiles!09070810:52:27InnoDB:Databasewasnotshutdownnormally!InnoDB:Startingcrashrecovery.InnoDB:Readingtablespaceinformationfromthe.ibdfiles...InnoDB:InaMySQLreplicationslavethelastmasterbinlogfileInnoDB:position0350504077,filenamemysql-bin.000748InnoDB:LastMySQLbinlogfileposition036434864,filename/opt/mysqllog/mysql-bin.00301509070810:52:27InnoDB:Started;logsequencenumber5143887732748[notice(again)]Ifyouusebinaryloganddon'tuseanyhackofgroupcommit,thebinarylogpositionseemstobe:InnoDB:LastMySQLbinlogfileposition036434864,filename/opt/mysqllog/mysql-bin.003015xtrabackup:startingshutdownwithinnodb_fast_shutdown=109070810:52:27InnoDB:Startingshutdown...09070810:52:29InnoDB:Shutdowncompleted;logsequencenumber514388773274809070810:52:29innobackupex:innobackupcompletedOK!

运行完毕后,启动mysql即可。

关于“如何使用Xtrabackup备份MySQL数据库”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。