ITPub博客

首页 > 数据库 > MySQL > Percona XtraBackup的那些事

Percona XtraBackup的那些事

原创 MySQL 作者:l86156117 时间:2015-12-04 13:20:27 0 删除 编辑
  Percona的工具都是管理数据库的利器,安装工具建议使用yum安装,yum源的配置:
 
wget http://www.percona.com/downloads/percona-release/redhat/0.1-3/percona-release-0.1-3.noarch.rpm 
 rpm -ivh percona-release-0.1-3.noarch.rpm
 yum install percona-xtrabakcup-22
 
备份的前的准备
用户名和密码

Connecting to the server The database user used to connect to the server and its password are specified by the --user and --password option,

CHAPTER THREE

$ innobackupex --user=DBUSER --password=SECRET /path/to/backup/dir/
$ innobackupex --user=LUKE  --password=US3TH3F0RC3 --stream=t 
除此之外还要 

			

Option

Description

–port

The port to use when connecting to the database server with TCP/IP.

–socket

The socket to use when connecting to the local database.

–host

The host to use when connecting to the database server with TCP/IP.

全备份
$ innobackupex --user=DBUSER --password=DBUSERPASS /path/to/BACKUP-DIR/ 

			
通常执行上面的命令会生成带时间戳的备份目录
/path/to/BACKUP-DIR/2013-03-25_00-00-09 

						

如果不带时间戳的备份目录的 $ innobackupex --user=DBUSER --password=DBUSERPASS /path/to/BACKUP-DIR/ --no-timestamp 以上的全备是不能立刻使用的,还要回滚所有未提交的事务,在全备后使用以下数据 $ innobackupex --apply-log /path/to/BACKUP-DIR 全备的恢复 $ innobackupex --copy-back /path/to/BACKUP-DIR

这里需要注意的是恢复的指定目录是要求空的,另外注意恢复目录的权限 $ chown -R mysql:mysql /var/lib/mysql
增量备份 基于全备或者上一次增量备份

$ innobackupex --incremental /data/backups --incremental-basedir=BASEDIR  增量备份结束后 Preparing an Incremental Backup with innobackupex Preparing incremental backups is a bit different than full

ones. This is, perhaps, the stage where more attention is needed:

First, only the committed transactions must be replayed on each backup. This will merge the base full backup with the incremental ones.

Then, the uncommitted transaction must be rolled back in order to have a ready-to-use backup.

If you replay the committed transactions and rollback the uncommitted ones on the base backup, you will not be able to add the incremental ones. If you do this on an incremental one, you won’t be able to add data from that moment and the remaining increments.

Having this in mind, the procedure is very straight-forward using the --redo-only option, starting with the base backup: innobackupex --apply-log --redo-only BASE-DIR

上面的官方说明增量备份的恢复过程实际上是不断使用全备份合并增量备份,如下:
innobackupex --apply-log --redo-only BASE-DIR 

																					

innobackupex --apply-log --redo-only BASE-DIR --incremental-dir=INCREMENTAL-DIR-1

innobackupex --apply-log BASE-DIR --incremental-dir=INCREMENTAL-DIR-2

当合并完所有的增量备份后,开始回滚所有未提交的事务

innobackupex --apply-log BASE-DIR 部分备份

 
																					

Using the --include option The regular expression provided to this will be matched against the fully qualified table name, including the database name, in the form databasename.tablename.

For example,

$ innobackupex --include='^mydatabase[.]mytable' /path/to/backup 


The command above will create a timestamped directory with the usual files that innobackupex creates, but only the data files related to the tables matched.

Notethatthisoptionispassedtoxtrabackup --tablesandismatchedagainsteachtableofeachdatabase,the directories of each database will be created even if they are empty.

Using the --tables-file option The text file provided (the path) to this option can contain multiple table names, one per line, in the databasename.tablename format.

For example,

$ echo "mydatabase.mytable" > /tmp/tables.txt 
$ innobackupex --tables-file=/tmp/tables.txt /path/to/backup 


The command above will create a timestamped directory with the usual files that innobackupex creates, but only containing the data-files related to the tables specified in the file.

This option is passed to xtrabackup --tables-file and, unlike the --tables option, only directories of databases of the selected tables will be created.

Using the --databases option This option accepts either a space-separated list of the databases and tables to backup - in the databasename[.tablename] form - or a file containing the list at one element per line.

For example, 

$ innobackupex --databases="mydatabase.mytable mysql" /path/to/backup 
要准备能进行使用的部分备份
 
																					
$ innobackupex --apply-log --export /path/to/partial/backup 
执行以上命令后你会在备份的数据库目录中看到如下文件
 
																					
/data/backups/mysql/test/export_test.exp
/data/backups/mysql/test/export_test.ibd
/data/backups/mysql/test/export_test.cfg 
接下来

Importing tables To import a table to other server, first create a new table with the same structure as the one that will be imported at that server:

OTHERSERVER|mysql> CREATE TABLE mytable (...) ENGINE=InnoDB; 

then discard its tablespace:

OTHERSERVER|mysql> ALTER TABLE mydatabase.mytable DISCARD TABLESPACE; 

After this, copy mytable.ibd and mytable.exp ( or mytable.cfg if importing to MySQL 5.6) files to database’s home, and import its tablespace:

OTHERSERVER|mysql> ALTER TABLE mydatabase.mytable IMPORT TABLESPACE; 

Once this is executed, data in the imported table will be available. 


 







来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/28944233/viewspace-1853353/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: 干货文
请登录后发表评论 登录
全部评论

注册时间:2014-10-22

  • 博文量
    16
  • 访问量
    64074