在Centos上安装xtrabackup,对Mysql做备份

根据操作系统版本,下载对应版本的xtrabackup tar包。

注:选择版本时,不一定要选择最新的。---要根据我们Mysql的版本选择对应的xtrabackup软件版本

(我最开始选择的是2.1版本的xtrabackup,但是在执行的时候就有报错,所以最后才会选择到2.0.8版本的xtrabackup

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.)

根据我的环境,我下载的版本为

 
之后安装,
将该软件放到Centos机器上/home/wison/
之后执行sudo tar -zxvf percona-xtrabackup-2.0.8-587.tar.gz -C xtrabackup
注:这里最好不要解压到/usr下面,否则会报错Error: not found in archive
 
解压完成之后,创建到/usr/bin下的软链接。
sudo ln -s /home/ABS_CORP/wh42/xtrabackup/percona-xtrabackup-2.0.8/bin/xtrabackup /usr/bin/xtrabackup

sudo ln -s /home/ABS_CORP/wh42/xtrabackup/percona-xtrabackup-2.0.8/bin/innobackupex /usr/bin/innobackupex

sudo ln -s /home/ABS_CORP/wh42/xtrabackup/percona-xtrabackup-2.0.8/bin/xtrabackup_51 /usr/bin/xtrabackup_51

sudo ln -s /home/ABS_CORP/wh42/xtrabackup/percona-xtrabackup-2.0.8/bin/xtrabackup_55 /usr/bin/xtrabackup_55

sudo ln -s /home/ABS_CORP/wh42/xtrabackup/percona-xtrabackup-2.0.8/bin/xtrabackup_56 /usr/bin/xtrabackup_56

 

切换到/usr/bin下执行innobackupex --user=root --passsword=xxx --defaults-file=/etc/my.cnf --database=mysql /tmp/backup/

报错:

Can't locate Time/HiRes.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at /usr/bin/innobackupex line 23.
BEGIN failed--compilation aborted at /usr/bin/innobackupex line 23.

此时,我们需要安装perl-Time-HiRes

执行sudo yum install perl-Time-HiRes

最后再执行下面的命令

sudo innobackupex --user=root --password=wison --defaults-file=/etc/my.cnf --database test /tmp/backup/

就可以正常的备份出test数据库。

下面是日志:

InnoDB Backup Utility v1.5.1-xtrabackup; Copyright 2003, 2009 Innobase Oy
and Percona LLC and/or its affiliates 2009-2013. All Rights Reserved.

This software is published under
the GNU GENERAL PUBLIC LICENSE Version 2, June 1991.

140327 09:59:21 innobackupex: Starting mysql with options: --defaults-file='/etc/my.cnf' --password=xxxxxxxx --user='root' --unbuffered --
140327 09:59:21 innobackupex: Connected to database with mysql child process (pid=13233)
140327 09:59:27 innobackupex: Connection to database server closed
IMPORTANT: Please check that the backup run completes successfully.
At the end of a successful backup run innobackupex
prints "completed OK!".

innobackupex: Using mysql Ver 14.14 Distrib 5.1.69, for redhat-linux-gnu (x86_64) using readline 5.1
innobackupex: Using mysql server version Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

innobackupex: Created backup directory /tmp/backup/2014-03-27_09-59-27
140327 09:59:27 innobackupex: Starting mysql with options: --defaults-file='/etc/my.cnf' --password=xxxxxxxx --user='root' --unbuffered --
140327 09:59:27 innobackupex: Connected to database with mysql child process (pid=13257)
140327 09:59:29 innobackupex: Connection to database server closed

140327 09:59:29 innobackupex: Starting ibbackup with command: xtrabackup --defaults-file="/etc/my.cnf" --defaults-group="mysqld" --backup --suspend-at-end --target-dir=/tmp/backup/2014-03-27_09-59-27 --tmpdir=/tmp
innobackupex: Waiting for ibbackup (pid=13264) to suspend
innobackupex: Suspend file '/tmp/backup/2014-03-27_09-59-27/xtrabackup_suspended'

xtrabackup version 2.0.8 for Percona Server 5.1.59 unknown-linux-gnu (x86_64) (revision id: 587)
xtrabackup: uses posix_fadvise().
xtrabackup: cd to /var/lib/mysql
xtrabackup: Target instance is assumed as followings.
xtrabackup: innodb_data_home_dir = ./
xtrabackup: innodb_data_file_path = ibdata1:10M:autoextend
xtrabackup: innodb_log_group_home_dir = ./
xtrabackup: innodb_log_files_in_group = 2
xtrabackup: innodb_log_file_size = 5242880
>> log scanned up to (177282)
[01] Copying ./ibdata1 to /tmp/backup/2014-03-27_09-59-27/ibdata1
[01] ...done
>> log scanned up to (177282)
xtrabackup: Creating suspend file '/tmp/backup/2014-03-27_09-59-27/xtrabackup_suspended' with pid '13264'

140327 09:59:30 innobackupex: Continuing after ibbackup has suspended
140327 09:59:30 innobackupex: Starting mysql with options: --defaults-file='/etc/my.cnf' --password=xxxxxxxx --user='root' --unbuffered --
140327 09:59:30 innobackupex: Connected to database with mysql child process (pid=13279)
>> log scanned up to (177282)
>> log scanned up to (177282)
140327 09:59:32 innobackupex: Starting to lock all tables...
>> log scanned up to (177282)
>> log scanned up to (177282)
>> log scanned up to (177282)
>> log scanned up to (177282)
>> log scanned up to (177282)
>> log scanned up to (177282)
>> log scanned up to (177282)
>> log scanned up to (177282)
>> log scanned up to (177282)
>> log scanned up to (177282)
140327 09:59:42 innobackupex: All tables locked and flushed to disk

140327 09:59:42 innobackupex: Starting to backup non-InnoDB tables and files
innobackupex: in subdirectories of '/var/lib/mysql'
innobackupex: Backing up file '/var/lib/mysql/test/a.MYI'
innobackupex: Backing up file '/var/lib/mysql/test/a.MYD'
innobackupex: Backing up file '/var/lib/mysql/test/a.frm'
140327 09:59:42 innobackupex: Finished backing up non-InnoDB tables and files

140327 09:59:42 innobackupex: Waiting for log copying to finish

xtrabackup: The latest check point (for incremental): '177282'
xtrabackup: Stopping log copying thread.
.>> log scanned up to (177282)

xtrabackup: Creating suspend file '/tmp/backup/2014-03-27_09-59-27/xtrabackup_suspended' with pid '13264'
xtrabackup: Transaction log of lsn (177282) to (177282) was copied.
140327 09:59:45 innobackupex: All tables unlocked
140327 09:59:45 innobackupex: Connection to database server closed

innobackupex: Backup created in directory '/tmp/backup/2014-03-27_09-59-27'
innobackupex: MySQL binlog position: filename '', position
140327 09:59:45 innobackupex: completed OK!

 

我们可以看到/tmp/backup下面就产生了对应的备份文件夹/tmp/backup/2014-03-27_09-59-27

 

 

 也可以使用xtrabackup来进行备份。

比如我们可以执行

sudo xtrabackup --backup --target-dir=/tmp/backup/

xtrabackup version 2.0.8 for Percona Server 5.1.59 unknown-linux-gnu (x86_64) (revision id: 587)
xtrabackup: uses posix_fadvise().
xtrabackup: cd to /var/lib/mysql
xtrabackup: Target instance is assumed as followings.
xtrabackup: innodb_data_home_dir = ./
xtrabackup: innodb_data_file_path = ibdata1:10M:autoextend
xtrabackup: innodb_log_group_home_dir = ./
xtrabackup: innodb_log_files_in_group = 2
xtrabackup: innodb_log_file_size = 5242880
>> log scanned up to (186282)
[01] Copying ./ibdata1 to /tmp/backup/ibdata1
[01] ...done
>> log scanned up to (186282)
xtrabackup: The latest check point (for incremental): '186282'
xtrabackup: Stopping log copying thread.
.>> log scanned up to (186282)

xtrabackup: Transaction log of lsn (186282) to (186282) was copied.

完成完全备份。

 

 

posted @ 2014-03-27 10:23  Wison-Ho  阅读(1324)  评论(0编辑  收藏  举报