久久精品人人爽,华人av在线,亚洲性视频网站,欧美专区一二三

mysql中lnnobackupex怎么進行全備加上增量的備份恢復

164次閱讀
沒有評論

共計 6861 個字符,預計需要花費 18 分鐘才能閱讀完成。

mysql 中 lnnobackupex 怎么進行全備加上增量的備份恢復,很多新手對此不是很清楚,為了幫助大家解決這個難題,下面丸趣 TV 小編將為大家詳細講解,有這方面需求的人可以來學習下,希望你能有所收獲。

MySQL 的熱備 (物理備份) 可以采取全備加增量備份的方式來減輕數據庫 I / O 壓力及系統資源的占用。增量備份主要是以全備或增量備份為基礎,備份那些變更過的頁面。其備份的原理是基于一個不斷增長的 LSN 序列,這個 LSN 與 Oracle 的 SCN 類似。在恢復期間,我們需要將已提交的事務前滾,未提交的事務回滾。這里主要描述了增量備份及增量恢復。
 
1、增備的相關知識點
    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.
    增備是備份上次以來發生變化的頁面,通過增備可以減輕存儲以及系統資源開銷。增量備份主要針對于 InnoDB,因為 InnoDB 采用了日志序列號(LSN) 的方式。InnoDB 的 LSN 是一個增長的序列,類似于 Oracle 的 SCN,記錄了 InnoDB 的變化情況。增量備份則是備份特定的 LSN 之后變化的情況。通過按序重組這些 LSN 即可將數據庫恢復到故障點或任意時刻。

    innobackupex –incremental /data/backups –incremental-lsn=1291135
    innobackupex –incremental /data/backups –incremental-lsn=1358967  
    如上,我們可以使用 –incremental-lsn 選項來實施增量備份
 
    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.
    對于非 XtraDB 或者 InnoDB 存儲引擎,熱備方式依舊會全部備份所有的數據文件,索引文件,格式文件等。
 
    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.
    對于增量備份的 Prepare 階段,有 2 個需要注意的地方,一個是提交的事務需要 replayed,一個未提交的事務需要 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 了已提交的事務以及回滾了未提交的事務,則后續的增量備份無法添加到當前全備。因此在 Prepare 階段全備應使用 –redo-only 選項。
 
    –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.
    對于存在多次增量的情形,僅僅只有最后一個增量不需要使用 –redo-only 選項。如果使用了的話,rollback 將由服務器啟動的時候來完成。

二、演示
1. 準備實驗環境
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. 模擬業務新數據
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. 增量備份
— 創建存放增量備份目錄并賦權
[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
— 正式開始增量備份
[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!

補充:
[root@mysql02 2017-06-09_04-02-16]# pwd
/xtrabackup/increament/2017-06-09_04-02-16
— 查看增備產生的相關文件  
[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 含有備份類型
[root@mysql02 2017-06-09_04-02-16]# more xtrabackup_info|grep ^incremental 
incremental = Y
— 文件 xtrabackup_checkpoints 包含了備份的相關檢查點信息  
[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 數據庫
[root@mysql02 ~]# service mysql stop
[root@mysql02 ~]# ps -ef|grep mysql
8. 恢復數據庫  (先恢復全備,再按增量備份時間先后順序,依次恢復增量備份)
8.1 先恢復完整的備份集:
[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 在恢復增量備份集:  (如果有多份增量備份,最好最后一份增量不用 –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!  # 結果出現 completed OK 表示完全成功
說明:/xtrabackup/full/2017-06-09_03-53-51 為全備基目錄,incremental-dir 為增量備份目錄
9. 將原有文件夾重命名到新位置,并創建原文件夾  
[root@mysql02 full]# mv /data/mysql /data/mysqlbak
[root@mysql02 full]# mkdir -p /data/mysql
10. 執行拷貝恢復的文件到原來的數據位置
[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! #結果出現 completed OK 表示完全成功
說明:/xtrabackup/full/2017-06-09_03-53-51/ 為全備基目錄
11. 權限修改
[root@mysql02 ~]# mkdir -p /data/mysql/binarylog(說明:這里我 binlog 在 datadir 在路徑下,所以要單獨為 binlog 創建目錄)
chown -R mysql:mysql /data/mysql 
12. 啟動被恢復的實例
[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 |     恢復成功!
|    4 |
+——+
總結:
a、增量備份是基于增量或全備的基礎之上完成的。
b、增量備份的基礎是 InnoDB 引擎使用了 LSN 機制,非 InnoDB 引擎不存在增量備份的說法,每次都是全備。
c、對于增量備份的恢復期間需要對已提交的事務前滾,未提交的事務回滾。
d、增量備份的恢復應按照備份的順利逐個逐個 replay,需要使用 –apply-log –redo-only 選項。
e、僅僅最后一個增量備份不需要使用 –redo-only 選項。
f、如果要做完全恢復或時點恢復,需要結合 binlog 來實現。

看完上述內容是否對您有幫助呢?如果還想對相關知識有進一步的了解或閱讀更多相關文章,請關注丸趣 TV 行業資訊頻道,感謝您對丸趣 TV 的支持。

正文完
 
丸趣
版權聲明:本站原創文章,由 丸趣 2023-07-19發表,共計6861字。
轉載說明:除特殊說明外本站除技術相關以外文章皆由網絡搜集發布,轉載請注明出處。
評論(沒有評論)
主站蜘蛛池模板: 金寨县| 淮北市| 乌拉特后旗| 台东市| 梅河口市| 南充市| 云安县| 云浮市| 恩平市| 大余县| 西吉县| 惠安县| 麦盖提县| 灵宝市| 景宁| 安远县| 板桥市| 永兴县| 吴忠市| 基隆市| 北宁市| 隆安县| 德江县| 富平县| 元江| 桃园市| 日土县| 灵丘县| 娱乐| 大城县| 关岭| 延庆县| 太保市| 绥阳县| 宣恩县| 盐城市| 兴化市| 东丰县| 右玉县| 察哈| 化州市|