XtraBackup备份mysql5.1.73

一、基础介绍

mysql5.1在源码中配备了两个版本的innodb存储引擎源码:innobase和innodb_plugin,编译安装的时候可以通过参数--with-plugins=innobase,innodb_plugin来指定是否将innodb存储引擎引入,具体这两个参数引入对编译后的mysql产生怎样的差异,后面再做解析。然而对于PerconaXtraBackup,在release版本中有2.0,2.1,2.2三个大版本,然后每个版本都是与mysql发布的innodb存储引擎版本对应,举例来说:

percona-xtrabackup-2.0.8在BUILD.txt中指定了utils/build.sh参数如下:

The script needs the codebase for which the building is targeted, you must
provide it with one of the following values or aliases:

  ================== =========  =============================================
  Value              Alias      Server
  ================== =========  =============================================
  innodb51_builtin   5.1    build against built-in InnoDB in MySQL 5.1
  innodb51           plugin build against InnoDB plugin in MySQL 5.1
  innodb55           5.5    build against InnoDB in MySQL 5.5
  xtradb51           xtradb     build against Percona Server with XtraDB 5.1
  xtradb55           xtradb55   build against Percona Server with XtraDB 5.5
  innodb56           5.6        build against InnoDB in MySQL 5.6
  ================== =========  =============================================

而在percona-xtrabackup-2.1.9在BUILD.txt中指定了utils/build.sh参数如下:

The script needs the codebase for which the building is targeted, you must
provide it with one of the following values or aliases:

  ================== =========  =============================================
  Value              Alias      Server
  ================== =========  =============================================
  innodb51           plugin build against InnoDB plugin in MySQL 5.1
  innodb55           5.5    build against InnoDB in MySQL 5.5
  xtradb51           xtradb     build against Percona Server with XtraDB 5.1
  xtradb55           xtradb55   build against Percona Server with XtraDB 5.5
  innodb56           5.6        build against InnoDB in MySQL 5.6
  ================== =========  =============================================

解释一下:从percona-xtrabackup2.1开始取消对innodb built-in版本支持,即:用Percona-Xtrabackup2.1备份5.1built-in版本将会出现如下报错:

innobackupex: Error: Support for MySQL 5.1 with builtin InnoDB (not the plugin) was removed in Percona XtraBackup 2.1. The last version to support MySQL 5.1 with builtin InnoDB was Percona XtraBackup 2.0.

二、Percona-Xtrabackup2.0.8编译安装

cd percona-xtrabackup-2.0.8
./utils/build.sh 5.1

编译安装完,备份工具保存在 src/xtrabackup_51,打包xtrabackup_51和innobackupex 到目的服务器的/usr/local/bin目录下,即可执行备份

三、用innobackupex备份多实例mysql数据库

前面讲过,mysql多实例数据库配置文件写在同一个文件中,而这个my.cnf必须位于/etc/my.cnf,否则需要在启动时指定配置文件路径。对于innobackex来说,使用--defaults-file需要读取单个数据库实例的配置文件信息,对于多个实例混合无法识别,故而需要将单实例配置抽出,单独存放,例如将mysql5.1.73多实例安装启动的配置文件抽出如下部分:

[mysqld]
server-id   = 3307
port        = 3307

socket      = /data/mysql_multi/mysql_exa1/mysql.sock
pid-file = /data/mysql_multi/mysql_exa1/mysql.pid
datadir = /data/mysql_multi/mysql_exa1/data
log-error = /data/mysql_multi/mysql_exa1/log/error.log

long_query_time = 1
slow_query_log_file = /data/mysql_multi/mysql_exa1/log/slow-query.log

log-bin = /data/mysql_multi/mysql_exa1/binlog/mysql-bin
log-bin-index = /data/mysql_multi/mysql_exa1/binlog/mysql-bin.index
expire_logs_days = 2
binlog_format=mixed

skip-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M

innodb_buffer_pool_size = 1G
innodb_additional_mem_pool_size = 2M
#Set .._log_file_size to 25 % of buffer pool size
innodb_log_file_size = 80M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 2
innodb_lock_wait_timeout = 50
innodb_file_per_table = 1
innodb_flush_method = O_DIRECT
innodb_file_io_threads = 4

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout

单独保存在 /data/mysql_multi/mysql_exa1/my.cnf,下面开始执行备份

innobackupex --defaults-file=/data/mysql_multi/mysql_exa1/my.cnf --user=root --password=1234 --socket=/data/mysql_multi/mysql_exa1/mysql.sock --databases="dinner" --datadir= /data/mysql_multi/

备份完成后将产生如下目录:/data/mysql_multi/2015-03-03_15-05-56/

下面将备份出来的库恢复到另一个实例中,同样需要做一份第二个实例的单独配置文件 /data/mysql_multi/mysql_exa2/my.cnf,内容和第一份类似,在此不做复述。

执行恢复前的prepare操作:

# innobackupex --defaults-file=/data/mysql_multi/mysql_exa2/my.cnf --user=root --password=1234 --socket=/data/mysql_multi/mysql_exa2/mysql.sock --apply-log --export /data/mysql_multi/2015-03-03_15-05-56

然后停掉第二个实例,复制prepare后的ibdata、ib_log和dinner目录到实例2的data目录下,修改权限,重启实例2即可。

四、总结

a. mysql5.1在实现插件式存储引擎时,在标准源码中附带了innobase和innodb_plugin两个版本,而不是像个别书中讲述的删掉innobase目录,将innodb_plugin重命名为innobase,这样操作在对编译configure参数不熟的情况下,很可能导致编译失败。

b. innobackupex是一个调用xtrabackup的perl脚本,当用2.0.8编译完成后,生成的xtrabackup***需要重命名为xtrabackup,并和innobackupex一并放在系统$PATH可找到的bin目录下(个人推荐将这两个工具放在/usr/local/xtrabackup目录下,再用软连接将其连接到/usr/local/bin下面)。

c. Xtrabackup在处理数据库整体迁移时很方便,但是在处理将多个机器上的数据库合并到同一台机器上时,鄙人暂时还没有完全测试成功。

原文地址:https://www.cnblogs.com/forilen/p/4312572.html