程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> MYSQL數據庫 >> MYSQL入門知識 >> MySQL備份與恢復之percona-xtrabackup軟件的使用基礎教程

MySQL備份與恢復之percona-xtrabackup軟件的使用基礎教程

編輯:MYSQL入門知識
 

一 使用percona-xtrabackup的原因

在前面,我們講到MySQL冷備、熱備、mysqldump、熱拷貝、保證數據的一致性。因為mysql冷備、mysqldump、mysql熱拷貝均不能實現增量備份,在實際環境中增量備份是使用較多的,percona-xtrabackup就是為實現增量備份而生,因此我們需要使用percona-xtrabackup。

本文講解percona-xtrabackup軟件的使用,下一篇文章講解percona-xtrabackup實現增量備份及恢復。

二 什麼是percona-xtrabackup


Percona XtraBackup is an open-source hot backup utility for MySQL -based servers that doesn’t lock your database during the backup.

It can back up data from InnoDB, XtraDB,and MyISAM tableson MySQL 5.1 [1], 5.5 and5.6 servers, as well as Percona Server with XtraDB. For a high-level overview of many of its advanced features, including a featurecomparison, please see About Percona Xtrabackup.

Whether it is a 24x7 highly loaded server or alow-transaction-volume environment, Percona XtraBackup isdesigned to make backups a seamless procedure without disrupting theperformance of the server in a production environment.Commercial support contracts areavailable.

Percona XtraBackup is a combination of the xtrabackup C program,and the innobackupex Perl script. The xtrabackup programcopies and manipulates InnoDB and XtraDB datafiles, and the Perl script enables enhanced functionality,such as interacting with a running MySQL server and backing up MyISAM tables.

三 軟件及文檔獲取

軟件獲取

percona-xtrabackup

percona-xtrabackup

文檔獲取

percona-xtrabackup

percona-xtrabackup

四 軟件使用講解

注:本文采用的percona-xtrabackup版本為2.0.2,操作系統版本為RHEL 6.1 Server,MySQL版本為5.1

第一步,准備文件並拷貝文件

ll percona-xtrabackup-2.0.2-461.rhel6.x86_64.rpm
scp percona-xtrabackup-2.0.2-461.rhel6.x86_64.rpm 192.168.1.11:/opt

第二步,該軟件需要依賴MySQL客戶端,所以使用yum安裝。注意,此處安裝的只是MySQL的客戶端,和本身使用源碼安裝的MySQL不沖突。

yum install percona-xtrabackup-2.0.2-461.rhel6.x86_64.rpm -y
Installed:
percona-xtrabackup.x86_64 0:2.0.2-461.rhel6
Dependency Installed:
mysql.x86_64 0:5.1.52-1.el6_0.1

第三步,初始化備份。

innobackupex --user=root --password=123456 /databackup/
InnoDB Backup Utility v1.5.1-xtrabackup; Copyright 2003, 2009 Innobase Oy
and Percona Inc 2009-2012. All Rights Reserved.

……
innobackupex: Backup created in directory '/databackup/2013-09-10_21-49-44'
innobackupex: MySQL binlog position: filename 'mysql-bin.000001', position 7312
130910 21:50:03 innobackupex: completed OK!

第四步,這樣的備份文件無法使用,我們需要做統一檢查。

ls
2013-09-10_21-49-44

# 做統一檢查
innobackupex --apply-log /databackup/2013-09-10_21-49-44/

InnoDB Backup Utility v1.5.1-xtrabackup; Copyright 2003, 2009 Innobase Oy
and Percona Inc 2009-2012. All Rights Reserved.
……
xtrabackup: starting shutdown with innodb_fast_shutdown = 1
130910 21:51:52 InnoDB: Starting shutdown...
130910 21:51:56 InnoDB: Shutdown completed; log sequence number 2098188
130910 21:51:56 innobackupex: completed OK!

第五步,模擬數據丟失。

rm -rf /usr/local/mysql/data/*
ll /usr/local/mysql/data/

第六步,恢復數據。

innobackupex --copy-back /databackup/2013-09-10_21-49-44/
InnoDB Backup Utility v1.5.1-xtrabackup; Copyright 2003, 2009 Innobase Oy
and Percona Inc 2009-2012. All Rights Reserved.
……
innobackupex: Starting to copy InnoDB system tablespace
innobackupex: in '/databackup/2013-09-10_21-49-44'
innobackupex: back to original InnoDB data directory '/usr/local/mysql/data'
innobackupex: Copying file '/databackup/2013-09-10_21-49-44/ibdata1'

innobackupex: Starting to copy InnoDB log files
innobackupex: in '/databackup/2013-09-10_21-49-44'
innobackupex: back to original InnoDB log directory '/usr/local/mysql/data'
innobackupex: Finished copying back files.

130910 22:02:29 innobackupex: completed OK!

第七步,重啟mysql服務,發現報錯,pkill掉,然後啟動一切正常。

/etc/init.d/mysqld restart
ERROR! MySQL server PID file could not be found!
Starting MySQL. ERROR! The server quit without updating PID file
(/usr/local/mysql/data/serv01.host.com.pid).

查看恢復的數據目錄,擁有者和所屬組不是mysql用戶,我們更改擁有者和所屬組。

ll /usr/local/mysql/data/
chown mysql.mysql /usr/local/mysql/data/ -R

再次啟動,仍然失敗,我們殺掉進程,再次啟動mysql,正常。

/etc/init.d/mysqld restart
ERROR! MySQL server PID file could not be found!
Starting MySQL.. ERROR! The server quit without updating PID file
(/usr/local/mysql/data/serv01.host.com.pid).

ps -ef | grep mysql
pkill -9 mysql

/etc/init.d/mysqld start
Starting MySQL.. SUCCESS!

登錄到MySQL。

mysql -uroot -p123456
Server version: 5.5.29-log Source distribution
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| game |
| hello |
| larrydb |
| mnt |
| mysql |
| performance_schema |
| test |
+--------------------+
8 rows in set (0.00 sec)

 
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved