| 維度 | 類型 | 說明 |
|---|---|---|
| 對資料庫影響 | 線上備份 (Online) | 資料庫持續可用,需歸檔日誌模式。 |
| 離線備份 (Offline) | 需斷開所有連接,支援循環日誌。 | |
| 資料範圍 | 完全備份 | 備份所有資料。 |
| 增量備份 | 僅備份變更資料,分累計與 Delta 兩種。 |
範例:週一完全、週二增量 A、週三增量 B、週四 Delta。
增量 B 包含週二+週三變更;Delta 僅含週四變更。

路徑編碼:資料庫.備份類型.實例.節點.編目.YYYYMMDD.HHMMSS.序號

命名:資料庫.實例.節點.編目.YYYYMMDDHHMMSS.序號
-- 建立測試庫
create database TestDB on 'D:' using codeset gbk territory cn with "TestDB";
-- 建立 DMS 表空間
create regular tablespace Data_SP pagesize 4k managed by database
using (file 'D:\DB2Container\TestDB\UserData\UserData' 2560)
bufferpool ibmdefaultbp;
-- 建立測試表並插入資料
create table TestTable (id int not null generated always as identity, message varchar(100), primary key(id)) in Data_SP;
insert into TestTable(message) values('測試表建立成功');
db2 backup db TestDB to D:\DB2_Train
db2 drop db TestDB
db2 restore db TestDB from D:\DB2_Train taken at 20071121152940
db2 update db cfg using TrackMod YES
db2 backup db TestDB to D:\DB2_Train -- 完全基準備份
insert into TestTable(message) values('開始增量備份測試');
db2 backup db TestDB incremental to D:\DB2_Train -- 增量備份
db2 drop db TestDB
db2 restore db TestDB from D:\DB2_Train taken at 20071121153818 -- 還原完全
db2 restore db TestDB incremental automatic from D:\DB2_Train taken at 20071121154006 -- 還原增量,automatic 自動鏈式恢復
db2 connect to TestDB
insert into TestTable(message) values('線上完全備份測試');
db2 update db cfg for TestDB using logretain on trackmod on
db2 backup db TestDB -- 線上完全備份 (20071121160548)
db2 connect to TestDB
insert into TestTable(message) values('線上增量備份測試');
db2 backup db TestDB online incremental to D:\DB2_Train -- 線上增量 (20071121152922)
-- 災難模擬:備份活動日誌至 C:\db2admin,再刪除資料庫
db2 drop db TestDB
db2 restore db TestDB from D:\DB2_Train taken at 20071121160548
db2 restore db TestDB incremental automatic from D:\DB2_Train taken at 20071121152922
db2 connect to TestDB
db2 rollforward database TestDB to end of logs and complete overflow log path ("C:\db2admin")
logretain 後必須立即做一次離線完全備份,否則資料庫處於 BACKUP PENDING 不可用。ROLL-FORWARD PENDING,必須執行 rollforward ... and complete 並指定歸檔日誌路徑 (overflow log path)。automatic 關鍵字讓增量還原自動尋找鏈路,避免手動多次恢復出錯。