XtraBackup備份恢複mysql資料庫的例子

來源:互聯網
上載者:User


Xtrabackup有兩個主要的工具:xtrabackup、innobackupex

(1)xtrabackup只能備份InnoDB和XtraDB兩種資料表,而不能備份MyISAM資料表

(2)innobackupex-1.5.1則封裝了xtrabackup,是一個指令碼封裝,所以能同時備份處理innodb和myisam,但在處理myisam時需要加一個讀鎖


1、下載安裝

http://www.percona.com/downloads/XtraBackup/LATEST/

percona-xtrabackup-2.2.9-5067.el6.x86_64.rpm

在centos6.4_x64上安裝

yum localinstall percona-xtrabackup-2.2.9-5067.el6.x86_64.rpm

安裝完產生

[root@localhost tmp]# rpm -ql percona-xtrabackup
/usr/bin/innobackupex
/usr/bin/xbcrypt
/usr/bin/xbstream
/usr/bin/xtrabackup
/usr/share/doc/percona-xtrabackup-2.2.9
/usr/share/doc/percona-xtrabackup-2.2.9/COPYING
/usr/share/man/man1/innobackupex.1.gz
/usr/share/man/man1/xbcrypt.1.gz
/usr/share/man/man1/xbstream.1.gz
/usr/share/man/man1/xtrabackup.1.gz

官方協助文檔

http://form.percona.com/rs/percona/images/PerconaXtraBackup-2.2.9.pdf?aliId=26490527

2、進行完整備份

備份必須串連mysql,相關選項有
–host=127.0.0.1指定伺服器ip
–port=3306指定連接埠

–socket=/tmp/mysql.sock 如果是本機可以只指定通訊端檔案的路徑
備份可以使用管理員帳號,也可開放一個許可權最小的帳號

grant user 'bkpuser'@'localhost' identified by '123';
grant reload,lock tables,replication client on *.* to 'bkpuser'@'localhost';
flush privileges;

進行一次完整備份,需要指定的相關選項有
–defaults-file=/usr/local/mysql/my.cnf 指定使用的設定檔
指定備份所存放的目標目錄,例如 /tmp

innobackupex --user=root --password=root --socket=/tmp/mysql.sock --defaults-file=/usr/local/mysql/my.cnf /tmp

3、進行增量備份

進行第一次增量備份,需要在有一次完整備份的基礎上進行
–incremental /root/one 指定增量備份存放的目標目錄
–incremental-basedir=/tmp 指定完整備份的目錄


innobackupex --user=root --password=root --socket=/tmp/mysql.sock --defaults-file=/usr/local/mysql/my.cnf --incremental /root/one --incremental-basedir=/tmp

進行第二次增量備份,需要指定上一次增量備份的目錄

–incremental /root/two                         指定這次增量備份目錄
–incremental-basedir=/root/one          知道上次增量備份目錄


innobackupex --user=root --password=root --socket=/tmp/mysql.sock --defaults-file=/usr/local/mysql/my.cnf --incremental /root/two --incremental-basedir=/root/one

4、還原一個增量備份

建立好的完整備份不能直接用來還原資料庫,需要對資料做一些準備工作,其中包括一些已經提交的事務的重放,未提交事務的復原。
–apply-log 準備還原備份的選項
–use-memory=4G 設定準備還原資料時使用的記憶體,可以提高準備所花費的時間
指定備份的資料目錄

innobackupex --apply-log --use-memory=4G /tmp

還原資料,需要指定設定檔,預設會還原到/var/lib/mysql,並且保證,my.cnf中設定的資料目錄下沒有任何檔案

innobackupex --copy-back --defaults-file=/usr/local/mysql/my.cnf /tmp

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.