还原数据库,并非所有行都已还原

时间:2019-01-28 12:10:57

标签: db2 restore db2-luw roll-forward

我在数据库EMPLOYEE.EMPLOYEE中有一个表HELLO,其中包含3条记录,如下所示:

EMP_NO  BIRTH_DATE FIRST_NAME         LAST_NAME            GENDER HIRE_DATE  BANK_ACCOUNT_NUMBER PHONE_NUMBER  
------- ---------- ------------------ -------------------- ------ ---------- ------------------- --------------
     1. 06/05/1998 A                  B                     M     01/02/2019 026201521420        +91X 
     2. 10/14/1997 C                  D                     M     01/07/2019 034212323454        +91Y 
     3. 05/27/1997 E                  F                     F     01/14/2019 92329323123         +91Z 

然后我首先使用以下命令进行脱机备份

mkdir offlinebackup
db2 terminate
db2 deactivate database HELLO
db2 backup database HELLO to ~/offlinebackup/

之后,我得到以下输出:

Backup successful. The timestamp for this backup image is : 20190128115210

现在我使用以下命令进行在线备份

db2 update database configuration for HELLO using LOGARCHMETH1 'DISK:/database/config/db2inst1/onlinebackup'
db2 backup database HELLO online to /database/config/db2inst1/onlinebackup compress include logs

此后,我得到的输出为:

Backup successful. The timestamp for this backup image is : 20190128115616

现在,我回到db2并运行CONNECT TO HELLO,它将我连接到数据库。当我检查EMPLOYEE.EMPLOYEE表中的行时,我仍然得到全部3行。

现在,我用EMP_NO 3删除该行。成功删除了该行。然后,我从db2终端运行quit

然后我使用此命令从脱机备份运行还原:

db2 restore db HELLO from ~/offlinebackup/ replace existing

上面写着DB20000I The RESTORE DATABASE command completed successfully

现在我尝试连接到HELLO,它显示SQL1117N A connection to or activation of database "HELLO" cannot be made because of ROLL-FORWARD PENDING. SQLSTATE=57019

我运行db2 rollforward db HELLO to end of logs and stop

然后我连接到HELLO并尝试找出行,我只得到2行,而不是备份中的3行。

EMP_NO  BIRTH_DATE FIRST_NAME         LAST_NAME             GENDER HIRE_DATE  BANK_ACCOUNT_NUMBER PHONE_NUMBER  
------- ---------- ------------------ --------------------- ------ ---------- ------------------- --------------
     1. 06/05/1998 A                  B                     M      01/02/2019 026201521420        +91X 
     2. 10/14/1997 C                  D                     M      01/07/2019 034212323454        +91Y

第三条记录不可见,该记录已存在于备份中。谁能弄清楚为什么我无法从备份中还原第三条记录

1 个答案:

答案 0 :(得分:1)

您运行的前滚命令:

db2 rollforward db HELLO to end of logs and stop

重放所有可用日志,包括与delete语句相对应的记录。

如果您想在执行备份后立即将数据库还原到状态,则可以运行

db2 rollforward db HELLO to end of backup and stop

或者,由于要从脱机备份还原,因此完全不需要前滚,并且可以使用

db2 rollforward db HELLO stop

或者,完全跳过前滚操作(当然,仅适用于脱机备份):

db2 restore db HELLO from ~/offlinebackup/ replace existing without rolling forward