β

MySQL:热备份 XtraBackup 工具初步使用

PostgreSQL DBA 115 阅读

        XtraBackup 是开源的 MySQL 执备份工具,支持 Percona Server, MySQL,  MariaDB ,这篇 blog 介绍 XtraBackup 的安装和简单使用。

一 XtraBackup 工具安装
--下载
http://www.percona.com/downloads/XtraBackup/XtraBackup-2.2.9/source/tarball/percona-xtrabackup-2.2.9.tar.gz

--安装相关包

[root@db1 ~]# yum install cmake gcc gcc-c++ libaio libaio-devel automake autoconf bzr bison libtool ncurses5-devel libgcrypt libgcrypt-devel python-sphinx


--安装 xtrabackup

[root@db1 soft_bak]# tar zxvf percona-xtrabackup-2.2.9.tar.gz [root@db1 soft_bak]# cd percona-xtrabackup-2.2.9 [root@db1 percona-xtrabackup-2.2.9]# cmake -DBUILD_CONFIG=xtrabackup_release && make -j4 [root@db1 percona-xtrabackup-2.2.9]# make install

备注: 默认装到了 /usr/local/xtrabackup/ 目录。

--查看 xtrabackup 相关备份脚本

[root@db1 xtrabackup]# ll /usr/local/xtrabackup/bin total 62104 -rwxr-xr-x 1 root root   185707 Mar  5 20:01 innobackupex -rwxr-xr-x 1 root root  4077080 Mar  6 08:52 xbcrypt -rwxr-xr-x 1 root root  4124543 Mar  6 08:52 xbstream -rwxr-xr-x 1 root root 55200546 Mar  6 09:15 xtrabackup


--问题1: Can't locate Time/HiRes.pm

[mysql@db1 ~]$ innobackupex --help Can't locate Time/HiRes.pm in @INC (@INC contains: /usr/local/lib/perl5 /usr/local/share/perl5 /usr/lib/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib/perl5 /usr/share/perl5 .) at /usr/local/xtrabackup/bin/innobackupex line 24. BEGIN failed--compilation aborted at /usr/local/xtrabackup/bin/innobackupex line 24.

备注:网上查了下,需要安装 perl-Time-HiRes 模块。


二 XtraBackup 使用
--创建备份用户

CREATE USER 'bk_user'@'localhost' IDENTIFIED BY 'bk_user'; GRANT RELOAD, LOCK TABLES, REPLICATION CLIENT ON *.* to 'bk_user'@'localhost'; flush privileges;

备注:RELOAD, LOCK TABLES, REPLICATION CLIENT 是备份用户需要的最小权限。

--全量备份

[mysql@db1 tf]$ innobackupex --host=127.0.0.1 --port=3306 --defaults-file=/opt/mysql/my.cnf --user=bk_user --password=bk_user backup

...最后几行日志 innobackupex: Backup created in directory '/home/mysql/script/tf/backup/2015-03-06_14-58-08' innobackupex: MySQL binlog position: filename 'bin-log.000003', position 1036 14:58:13  innobackupex: Connection to database server closed 14:58:13  innobackupex: completed OK

--查看备份目录

[mysql@db1 tf]$ cd backup/2015-03-06_14-58-08/ [mysql@db1 2015-03-06_14-58-08]$ ll total 77M -rw-rw-r-- 1 mysql mysql  295 Mar  6 14:58 backup-my.cnf drwxrwxr-x 2 mysql mysql 4.0K Mar  6 14:58 binlog drwx------ 2 mysql mysql 4.0K Mar  6 14:58 francs -rw-rw---- 1 mysql mysql  76M Mar  6 14:58 ibdata1 drwxrwxr-x 2 mysql mysql 4.0K Mar  6 14:58 log_bk drwx------ 2 mysql mysql 4.0K Mar  6 14:58 mysql drwxrwxr-x 2 mysql mysql 4.0K Mar  6 14:58 performance_schema drwxrwxr-x 2 mysql mysql 4.0K Mar  6 14:58 test -rw-rw-r-- 1 mysql mysql   20 Mar  6 14:58 xtrabackup_binlog_info -rw-rw---- 1 mysql mysql   91 Mar  6 14:58 xtrabackup_checkpoints -rw-rw-r-- 1 mysql mysql  613 Mar  6 14:58 xtrabackup_info -rw-rw---- 1 mysql mysql 2.5K Mar  6 14:58 xtrabackup_logfile



三 参考
作者:PostgreSQL DBA
Francs 的博客
原文地址:MySQL:热备份 XtraBackup 工具初步使用, 感谢原作者分享。

发表评论