mysql中l(wèi)nnobackupex怎么進(jìn)行全備加上增量的備份恢復(fù)

MySQL中l(wèi)nnobackupex怎么進(jìn)行全備加上增量的備份恢復(fù),很多新手對(duì)此不是很清楚,為了幫助大家解決這個(gè)難題,下面小編將為大家詳細(xì)講解,有這方面需求的人可以來(lái)學(xué)習(xí)下,希望你能有所收獲。

成都創(chuàng)新互聯(lián)公司自2013年起,先為永豐等服務(wù)建站,永豐等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢(xún)服務(wù)。為永豐企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問(wèn)題。

MySQL的熱備(物理備份)可以采取全備加增量備份的方式來(lái)減輕數(shù)據(jù)庫(kù)I/O壓力及系統(tǒng)資源的占用。增量備份主要是以全備或增量備份為基礎(chǔ),備份那些變更過(guò)的頁(yè)面。其備份的原理是基于一個(gè)不斷增長(zhǎng)的LSN序列,這個(gè)LSN與Oracle的SCN類(lèi)似。在恢復(fù)期間,我們需要將已提交的事務(wù)前滾,未提交的事務(wù)回滾。這里主要描述了增量備份及增量恢復(fù)。
 
1、增備的相關(guān)知識(shí)點(diǎn)
    As not all information changes between each backup, the incremental backup strategy uses this to reduce the storage needs and the duration of making a backup. This can be done because each InnoDB page has a log sequence number, LSN, which acts as a version number of the entire database. Every time the database is modi?ed, this number gets incremented. An incremental backup copies all pages since a speci?c LSN. Once the pages have been put together in their respective order, applying the logs will recreate the process that affected the database, yielding the data at the moment of the most recently created backup.
    增備是備份上次以來(lái)發(fā)生變化的頁(yè)面,通過(guò)增備可以減輕存儲(chǔ)以及系統(tǒng)資源開(kāi)銷(xiāo)。增量備份主要針對(duì)于InnoDB,因?yàn)镮nnoDB采用了日志序列號(hào)(LSN)的方式。InnoDB的LSN是一個(gè)增長(zhǎng)的序列,類(lèi)似于Oracle的SCN,記錄了InnoDB的變化情況。增量備份則是備份特定的LSN之后變化的情況。通過(guò)按序重組這些LSN即可將數(shù)據(jù)庫(kù)恢復(fù)到故障點(diǎn)或任意時(shí)刻。


    innobackupex --incremental /data/backups --incremental-lsn=1291135
    innobackupex --incremental /data/backups --incremental-lsn=1358967  
    如上,我們可以使用--incremental-lsn選項(xiàng)來(lái)實(shí)施增量備份
 
    Warning: This procedure only affects XtraDB or InnoDB-based tables. Other tables with a different storage engine, e.g. MyISAM, will be copied entirely each time an incremental backup is performed.
    對(duì)于非XtraDB或者InnoDB存儲(chǔ)引擎,熱備方式依舊會(huì)全部備份所有的數(shù)據(jù)文件,索引文件,格式文件等。
 
    Preparing an Incremental Backup with innobackupex Preparing incremental backups is a bit different than full ones. This is, perhaps, the stage where more attention is needed:
    ? First, only the committed transactions must be replayed on each backup. This will merge the base full backup with the incremental ones.
    ? Then, the uncommitted transaction must be rolled back in order to have a ready-to-use backup.
    對(duì)于增量備份的Prepare階段,有2個(gè)需要注意的地方,一個(gè)是提交的事務(wù)需要replayed,一個(gè)未提交的事務(wù)需要rollback。
 
    If you replay the committed transactions and rollback the uncommitted ones on the base backup, you will not be able to add the incremental ones. If you do this on an incremental one, you won’t be able to add data from that moment and the remaining increments. Having this in mind, the procedure is very straight-forward using the --redo-only option, starting with the base backup:
    如果在Prepare階段replay了已提交的事務(wù)以及回滾了未提交的事務(wù),則后續(xù)的增量備份無(wú)法添加到當(dāng)前全備。因此在Prepare階段全備應(yīng)使用--redo-only選項(xiàng)。
 
    --redo-only should be used when merging all incrementals except the last one. That’s why the previous line doesn’t contain the --redo-only option. Even if the --redo-only was used on the last step, backup would still be consistent but in that case server would perform the rollback phase.
    對(duì)于存在多次增量的情形,僅僅只有最后一個(gè)增量不需要使用--redo-only 選項(xiàng)。如果使用了的話(huà),rollback將由服務(wù)器啟動(dòng)的時(shí)候來(lái)完成。


二、 演示
1. 準(zhǔn)備實(shí)驗(yàn)環(huán)境
mysql> select version();
+------------+
| version()  |
+------------+
| 5.6.25-log |
+------------+
1 row in set (0.00 sec)
mysql> create database inc_rec;
Query OK, 1 row affected (0.00 sec)
mysql> use inc_rec;
Database changed
mysql> create table andy (id int);
Query OK, 0 rows affected (0.08 sec)
mysql> insert into andy values(1),(2);
Query OK, 2 rows affected (0.00 sec)
Records: 2  Duplicates: 0  Warnings: 0
2. 全備
[root@mysql02 full]# innobackupex --defaults-file=/etc/my.cnf --user=root --password=oracle --port=3606 /xtrabackup/full/
xtrabackup: Transaction log of lsn (1648193) to (1648193) was copied.
170609 03:53:56 completed OK!
3. 查看全備生成文件
[root@mysql02 full]# ll /xtrabackup/full/
total 4
drwxr-x---. 6 root root 4096 Jun  9 03:53 2017-06-09_03-53-51
4. 模擬業(yè)務(wù)新數(shù)據(jù)
mysql> insert into andy values(3),(4);
Query OK, 2 rows affected (0.14 sec)
Records: 2  Duplicates: 0  Warnings: 0
mysql> commit;
Query OK, 0 rows affected (0.00 sec)
5. 增量備份
-- 創(chuàng)建存放增量備份目錄并賦權(quán)
[root@mysql02 full]# mkdir -p /xtrabackup/increament/
[root@mysql02 full]# chown -R mysql:mysql /xtrabackup/increament/
[root@mysql02 full]# ll /xtrabackup/
total 8
drwxr-xr-x. 3 mysql mysql 4096 Jun  9 03:53 full
drwxr-xr-x. 2 mysql mysql 4096 Jun  9 04:00 increament
-- 正式開(kāi)始增量備份
[root@mysql02 full]# innobackupex --defaults-file=/etc/my.cnf --user=root --password=oracle  --incremental  \
--incremental-basedir=/xtrabackup/full/2017-06-09_03-53-51/ /xtrabackup/increament/
########################################下面是增量備份輸出
170609 04:02:21 Backup created in directory '/xtrabackup/increament/2017-06-09_04-02-16/'
MySQL binlog position: filename 'binlog.000003', position '894'
。。。省略
xtrabackup: Transaction log of lsn (1652210) to (1652210) was copied.
170609 04:02:22 completed OK!


補(bǔ)充:
[root@mysql02 2017-06-09_04-02-16]# pwd
/xtrabackup/increament/2017-06-09_04-02-16
-- 查看增備產(chǎn)生的相關(guān)文件  
[root@mysql02 2017-06-09_04-02-16]# ll
total 8580
-rw-r-----. 1 root root     418 Jun  9 04:02 backup-my.cnf
-rw-r-----. 1 root root  360448 Jun  9 04:02 ibdata1.delta
-rw-r-----. 1 root root      44 Jun  9 04:02 ibdata1.meta
drwxr-x---. 2 root root    4096 Jun  9 04:02 inc_rec
drwxr-x---. 2 root root    4096 Jun  9 04:02 mysql
drwxr-x---. 2 root root    4096 Jun  9 04:02 performance_schema
drwxr-x---. 2 root root    4096 Jun  9 04:02 test
-rw-r-----. 1 root root      18 Jun  9 04:02 xtrabackup_binlog_info
-rw-r-----. 1 root root     117 Jun  9 04:02 xtrabackup_checkpoints
-rw-r-----. 1 root root     584 Jun  9 04:02 xtrabackup_info
-rw-r-----. 1 root root 8388608 Jun  9 04:24 xtrabackup_logfile
-- 文件 xtrabackup_info 含有備份類(lèi)型
[root@mysql02 2017-06-09_04-02-16]# more xtrabackup_info|grep ^incremental 
incremental = Y
-- 文件xtrabackup_checkpoints包含了備份的相關(guān)檢查點(diǎn)信息  
[root@mysql02 2017-06-09_04-02-16]# more xtrabackup_checkpoints  
backup_type = incremental
from_lsn = 1648193
to_lsn = 1652210
last_lsn = 1652210
compact = 0
recover_binlog_info = 0
-- 文件xtrabackup_binlog_info包含了binlog的位置  
[root@mysql02 2017-06-09_04-02-16]# more xtrabackup_binlog_info  
binlog.000003 894
6. 誤操作,truncate表
mysql> truncate table andy;
Query OK, 0 rows affected (0.22 sec)
mysql> select * from andy;
Empty set (0.01 sec)
7. 停止mysql數(shù)據(jù)庫(kù)
[root@mysql02 ~]# service mysql stop
[root@mysql02 ~]# ps -ef|grep mysql
8.恢復(fù)數(shù)據(jù)庫(kù)  (先恢復(fù)全備,再按增量備份時(shí)間先后順序,依次恢復(fù)增量備份)
8.1 先恢復(fù)完整的備份集:
[root@mysql02 full]#  innobackupex --defaults-file=/etc/my.cnf --user=root --apply-log --redo-only /xtrabackup/full/2017-06-09_03-53-51/
170609 04:19:30 completed OK!
8.2 在恢復(fù)增量備份集:   (如果有多份增量備份,最好最后一份增量不用 --redo-only , 其他的都用 --redo-only)
[root@mysql02 full]# innobackupex --defaults-file=/etc/my.cnf --user=root --apply-log  /xtrabackup/full/2017-06-09_03-53-51  --incremental-dir=/xtrabackup/increament/2017-06-09_04-02-16/
170609 04:24:45 completed OK!  #結(jié)果出現(xiàn)completed OK表示完全成功
說(shuō)明: /xtrabackup/full/2017-06-09_03-53-51 為全備基目錄 , incremental-dir 為增量備份目錄
9.將原有文件夾重命名到新位置,并創(chuàng)建原文件夾 
[root@mysql02 full]# mv /data/mysql /data/mysqlbak
[root@mysql02 full]# mkdir -p /data/mysql
10.執(zhí)行拷貝恢復(fù)的文件到原來(lái)的數(shù)據(jù)位置
[root@mysql02 full]# innobackupex --defaults-file=/etc/my.cnf --user=root --copy-back  /xtrabackup/full/2017-06-09_03-53-51/
170609 04:33:06 completed OK! #結(jié)果出現(xiàn)completed OK表示完全成功
說(shuō)明: /xtrabackup/full/2017-06-09_03-53-51/ 為全備基目錄
11. 權(quán)限修改
[root@mysql02 ~]# mkdir -p /data/mysql/binarylog (說(shuō)明:這里我binlog在datadir在路徑下,所以要單獨(dú)為binlog創(chuàng)建目錄)
chown -R mysql:mysql /data/mysql 
12. 啟動(dòng)被恢復(fù)的實(shí)例
[root@mysql02 mysql]# mysqld_safe --defaults-file=/etc/my.cnf & 
[root@mysql02 ~]# mysql -uroot -poracle
mysql> use inc_rec;
mysql> select * from andy;
+------+
| id   |
+------+
|    1 |
|    2 |
|    3 |     > 恢復(fù)成功!
|    4 |
+------+
總結(jié):
a、增量備份是基于增量或全備的基礎(chǔ)之上完成的。
b、增量備份的基礎(chǔ)是InnoDB引擎使用了LSN機(jī)制,非InnoDB引擎不存在增量備份的說(shuō)法,每次都是全備。
c、對(duì)于增量備份的恢復(fù)期間需要對(duì)已提交的事務(wù)前滾,未提交的事務(wù)回滾。
d、增量備份的恢復(fù)應(yīng)按照備份的順利逐個(gè)逐個(gè)replay,需要使用--apply-log --redo-only選項(xiàng)。
e、僅僅最后一個(gè)增量備份不需要使用--redo-only選項(xiàng)。
f、如果要做完全恢復(fù)或時(shí)點(diǎn)恢復(fù),需要結(jié)合binlog來(lái)實(shí)現(xiàn)。

看完上述內(nèi)容是否對(duì)您有幫助呢?如果還想對(duì)相關(guān)知識(shí)有進(jìn)一步的了解或閱讀更多相關(guān)文章,請(qǐng)關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝您對(duì)創(chuàng)新互聯(lián)的支持。

網(wǎng)站欄目:mysql中l(wèi)nnobackupex怎么進(jìn)行全備加上增量的備份恢復(fù)
標(biāo)題路徑:http://bm7419.com/article36/gejcpg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供定制開(kāi)發(fā)、域名注冊(cè)、App設(shè)計(jì)、網(wǎng)站改版品牌網(wǎng)站設(shè)計(jì)、網(wǎng)站內(nèi)鏈

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

h5響應(yīng)式網(wǎng)站建設(shè)