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

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

安装相关包

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

安装 xtrabackup

1
2
3
4
[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 相关备份脚本

1
2
3
4
5
6
[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

1
2
3
[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 使用

创建备份用户

1
2
3
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 是备份用户需要的最小权限。

全量备份

1
2
3
4
5
6
[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
150306 14:58:13 innobackupex: Connection to database server closed
150306 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

三 参考

原创文章,作者:1402239773,如若转载,请注明出处:https://blog.ytso.com/tech/database/239622.html

(0)
上一篇 2022年2月12日 13:53
下一篇 2022年2月12日 13:53

相关推荐

发表回复

登录后才能评论