MySQL的xtrabackup備份

來源:互聯網
上載者:User

標籤:Database Backup

########################################################################################  ######恢複資料庫的時候,需要將備份的日誌應用備份的檔案中去,讓後才能進行恢複######備份:innobackupex --user=root --password=banma --defaults-file=/etc/my.cnf  --database=testinnodb  /tmp/data/######恢複2步驟 innobackupex --user=root --password=banma --apply-log /tmp/data/2013-08-23_16-09-10/[[email protected] 2013-08-23_16-09-10]# rsync -avz testinnodb ib* /usr/local/mysql_data/data/chown -R mysql:mysql /usr/local/mysql_data/data/##########################################################################################################一、安裝部署和過程1.下載安裝wget http://www.percona.com/redir/downloads/XtraBackup/XtraBackup-1.6.7/binary/Linux/x86_64/xtrabackup-1.6.7.tar.gz 2.安裝需要的庫yum install cmake gcc gcc-c++ libaio libaio-devel automake autoconf bzr   bison libtool ncurses-devel zlib-devel3、解壓tar zxvf xtrabackup-1.6.7.tar.gz  4、進入目錄cd xtrabackup-1.6.7 5、複製cd bin  cp * /usr/bin  然後就安裝完成了,下面開始備份  注意:檔案解釋innobackupex是我們要使用的備份工具;xtrabackup是被封裝在innobackupex之中的,innobackupex運行時需要調用它;xtrabackup_51是xtrabackup運行時需要調用的工具;tar4ibd是以tar流的形式產生備份時用來打包的工具。二、備份和恢複6、對某個資料庫進行全部備份的命令介紹innobackupex --user=root --password=123456 --defaults-file=/etc/mysql/my.cnf --database=test --stream=tar /tmp/data/ 2>/tmp/data/info.log|gzip 1>/tmp/data/test.tar.gz 說明:      --database=test 單獨對test資料庫做備份 ,若是不添加此參數那就那就是對全庫做備份      2>/tmp/data/info.log 輸出資訊寫入日誌中      1>/tmp/data/test.tar.gz 打包壓縮儲存到該檔案中 ( mysql> create table test (id int);  Query OK, 0 rows affected (0.06 sec)  mysql> insert into test values(1);  Query OK, 1 row affected (0.04 sec)  ) 7、恢複資料庫 (1)建立一個檔案夾 mkdir /tmp/restore cd /tmp/data tar -izxvf test.tar.gz -C /tmp/restore[[email protected] data]# ll /tmp/restore/總用量 131096-rw-r--r-- 1 root  root        263  8月 23 14:38 backup-my.cnf-rw-rw---- 1 mysql mysql 134217728  8月 23 14:22 ibdata1drwxr-xr-x 2 root  root       4096  8月 23 14:53 test-rw-r--r-- 1 root  root         13  8月 23 14:38 xtrabackup_binary-rw-r--r-- 1 root  root         21  8月 23 14:38 xtrabackup_binlog_info-rw-r--r-- 1 root  root         73  8月 23 14:38 xtrabackup_checkpoints-rw-r--r-- 1 root  root       2560  8月 23 14:38 xtrabackup_logfile(2)開始應用日誌(將備份檔案中的日誌,應用到備份檔案中的資料檔案上,--apply-log指明是將日誌應用到資料檔案上,完成之後將備份檔案中的資料恢複到資料庫中)[[email protected] restore]# innobackupex --user=root --password=banma --apply-log /tmp/restore/ [[email protected] restore]# ll總用量 526356-rw-r--r-- 1 root  root        263  8月 23 14:38 backup-my.cnf-rw-rw---- 1 mysql mysql 134217728  8月 23 14:59 ibdata1-rw-r--r-- 1 root  root  134217728  8月 23 14:59 ib_logfile0-rw-r--r-- 1 root  root  134217728  8月 23 14:59 ib_logfile1-rw-r--r-- 1 root  root  134217728  8月 23 14:59 ib_logfile2drwxr-xr-x 2 root  root       4096  8月 23 14:53 test-rw-r--r-- 1 root  root         13  8月 23 14:38 xtrabackup_binary-rw-r--r-- 1 root  root         21  8月 23 14:38 xtrabackup_binlog_info-rw-r--r-- 1 root  root         73  8月 23 14:59 xtrabackup_checkpoints-rw-r--r-- 1 root  root    2097152  8月 23 14:59 xtrabackup_logfile(3)恢複正式開始然後把test目錄複寫到/usr/local/mysql_data/data目錄[[email protected] restore]# rsync -avz test ib* /usr/local/mysql_data/datasending incremental file listib_logfile0ib_logfile1ib_logfile2ibdata1test/test/test.MYDtest/test.MYItest/test.frmsent 529692 bytes  received 149 bytes  13762.10 bytes/sectotal size is 536880534  speedup is 1013.29[[email protected] restore]#chown -R mysql:mysql /usr/local/mysql_data/data三、增量備份和恢複(1)先添加幾條資料insert into test values(10);insert into test values(11);insert into test values(12);insert into test values(13);insert into test values(14);insert into test values(15);(2)增量備份[[email protected] data]# innobackupex --user=root --password=banma --database=test --incremental --incremental-basedir=/tmp/restore/ /tmp/data其中,--incremental指明是增量備份,--incremental-basedir指定上次完整備份或者增量備份檔案的位置。這裡的增量備份其實只針對的是InnoDB,對於MyISAM來說,還是完整備份。在進行增量備份的恢複之前,先關閉資料庫,然後刪除資料庫test(3)增量備份的恢複[[email protected] data]# innobackupex -user=root --password=banma --defaults-file=/etc/my.cnf --apply-log /tmp/restore/ --incremental-dir=/tmp/data/2013-08-23_15-22-54/然後再進入恢複的目錄/tmp/data[[email protected] 2013-08-23_15-22-54]# ll總用量 172-rw-r--r-- 1 root root    263  8月 23 15:22 backup-my.cnf-rw-r--r-- 1 root root 147456  8月 23 15:22 ibdata1.delta-rw-r--r-- 1 root root     18  8月 23 15:22 ibdata1.metadrwxr-xr-x 2 root root   4096  8月 23 15:23 test-rw-r--r-- 1 root root     13  8月 23 15:23 xtrabackup_binary-rw-r--r-- 1 root root     21  8月 23 15:23 xtrabackup_binlog_info-rw-r--r-- 1 root root     75  8月 23 15:23 xtrabackup_checkpoints-rw-r--r-- 1 root root   2560  8月 23 15:23 xtrabackup_logfile[[email protected] 2013-08-23_15-22-54]# rsync -avz test ib* /usr/local/mysql_data/data/


本文出自 “記錄點滴” 部落格,請務必保留此出處http://caozm.blog.51cto.com/1118764/1622108

MySQL的xtrabackup備份

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.