签到成功

知道了

CNDBA社区CNDBA社区

DM7 达梦数据库 多次故障恢复后使用不同数据库归档恢复 示例

2019-09-04 01:11 2500 1 原创 DM 达梦
作者: dave

在上篇博客中,我们看了DM数据库脱机备份的相关操作,如下:

DM7 达梦数据库 物理备份还原之 脱机备份(DMRMAN工具) 使用手册
https://www.cndba.cn/dave/article/3612

本篇我们看另一种情况就是多次故障恢复后使用不同数据库归档恢复的情况。

1 现象描述

在实际应用中可能会遇到以下还原场景:

1) 创建一个数据库 D1。
2) 操作数据库并执行数据库备份 B1。
3) 继续操作数据库的过程中数据库故障,此时生成的归档为 A1。
4) 利用备份 B1 和归档 A1 将数据库 D1 恢复到目标库 D2,此时数据库 D2 为 D1 故障前的状态。
5) 启动数据库 D2,操作数据库过程中数据库第二次故障,此时生成的归档为 A2。https://www.cndba.cn/dave/article/3615

2 操作示例

1) 创建源库 D1,即待备份的数据库,然后启动数据库并配置归档,归档目录为/dm/dmarch。

https://www.cndba.cn/dave/article/3615

[dave@www.cndba.cn dm]$ dminit PATH=/dm/dmdbms/data DB_NAME=anqing INSTANCE_NAME=anqing
initdb V7.6.0.95-Build(2018.09.13-97108)ENT 
db version: 0x7000a
file dm.key not found, use default license!
License will expire in 14 day(s) on 2029-03-20

 log file path: /dm/dmdbms/data/anqing/anqing01.log


 log file path: /dm/dmdbms/data/anqing/anqing02.log

write to dir [/dm/dmdbms/data/anqing].
create dm database success. 2029-03-06 23:46:42
[dave@www.cndba.cn dm]$ dmserver /dm/dmdbms/data/anqing/dm.ini 
file dm.key not found, use default license!
Global parameter value of RT_HEAP_TARGET is illegal, use min value!
version info: develop
Use normal os_malloc instead of HugeTLB
Use normal os_malloc instead of HugeTLB
DM Database Server x64 V7.6.0.95-Build(2018.09.13-97108)ENT  startup...
License will expire in 14 day(s) on 2029-03-20
ckpt lsn: 0
ndct db load finished
ndct fill fast pool finished
set EP[0]'s pseg state to inactive
iid page's trxid = 1
NEXT TRX ID = 2
pseg recv finished
nsvr_startup end.
aud sys init success.
aud rt sys init success.
systables desc init success.
ndct_db_load_info success.
nsvr_process_before_open begin.
nsvr_process_before_open success.
SYSTEM IS READY.

关于DM 实例初始化更多内容参考我的博客:

https://www.cndba.cn/dave/article/3615

DM7 达梦数据库 通过dminit 创建 并 注册 数据库实例
https://www.cndba.cn/dave/article/3580

—连接数据库配置归档https://www.cndba.cn/dave/article/3615

[dave@www.cndba.cn ~]$ disql SYSDBA/SYSDBA

Server[LOCALHOST:5236]:mode is normal, state is open
login used time: 10.097(ms)
disql V7.6.0.95-Build(2018.09.13-97108)ENT 
Connected to: DM 7.1.6.95
SQL> select name,instance_name from v$instance;

LINEID     NAME   INSTANCE_NAME
---------- ------ -------------
1          ANQING ANQING

used time: 5.302(ms). Execute id is 834.
SQL> ALTER DATABASE MOUNT;
executed successfully
used time: 00:00:01.869. Execute id is 0.
SQL> ALTER DATABASE ADD ARCHIVELOG 'DEST = /dm/dmarch, TYPE = local, FILE_SIZE = 1024, SPACE_LIMIT = 2048';
executed successfully
used time: 2.521(ms). Execute id is 0.
SQL> ALTER DATABASE ARCHIVELOG;
executed successfully
used time: 10.983(ms). Execute id is 0.
SQL> ALTER DATABASE OPEN;
executed successfully
used time: 805.997(ms). Execute id is 0.
SQL>

2) 操作数据库的同时备份数据库,备份集为 B1。此处以向表中循环插入数据为例操作数据库。https://www.cndba.cn/dave/article/3615

SQL>CREATE TABLE TAB_FOR_RECOVER(C1 INT);
SQL>BEGIN
FOR I IN 1..100000 LOOP
INSERT INTO TAB_FOR_RECOVER VALUES(I);
COMMIT;
END LOOP;
END;
/
--插入数据的同时,另外一个会话备份数据库
SQL> backup database full to b1 backupset '/dm/dm_bak/b1' device type disk backupinfo 'dave full backup online' maxpiecesize 2048;
executed successfully
used time: 00:00:01.194. Execute id is 5.
SQL>

3)继续向数据库插入数据一段时间后杀掉数据库进程,模拟数据库故障。从备份后到数据库故障这段时间的生成的归档称为 A1。https://www.cndba.cn/dave/article/3615

4) 创建目标库 D2,即待还原的库,并配置归档,归档目录与数据库 D1 相同。https://www.cndba.cn/dave/article/3615https://www.cndba.cn/dave/article/3615

[dave@www.cndba.cn dm_bak]$ dminit path=/dm/dmdbms/data DB_NAME=dave_for_res
initdb V7.6.0.95-Build(2018.09.13-97108)ENT 
db version: 0x7000a
file dm.key not found, use default license!
License will expire in 14 day(s) on 2029-03-21

 log file path: /dm/dmdbms/data/dave_for_res/dave_for_res01.log


 log file path: /dm/dmdbms/data/dave_for_res/dave_for_res02.log

write to dir [/dm/dmdbms/data/dave_for_res].
create dm database success. 2029-03-07 00:51:12
[dave@www.cndba.cn dm_bak]$

5) 启动DMRMAN工具,利用备份集B1和归档A1恢复数据库D2到D1故障前的状态。

[dave@www.cndba.cn dm_bak]$ cd /dm/dmdbms/bin
[dave@www.cndba.cn bin]$ ./dmrman
dmrman V7.6.0.95-Build(2018.09.13-97108)ENT 
RMAN> restore database '/dm/dmdbms/data/dave_for_res/dm.ini' from backupset '/dm/dm_bak/b1';
restore database '/dm/dmdbms/data/dave_for_res/dm.ini' from backupset '/dm/dm_bak/b1';
file dm.key not found, use default license!
Global parameter value of RT_HEAP_TARGET is illegal, use min value!
checking if the database under system path [/dm/dmdbms/data/dave_for_res] is running, write dmrman info.
RESTORE DATABASE  CHECK......
RESTORE DATABASE , dbf collect......
RESTORE DATABASE , dbf refresh ......
RESTORE BACKUPSET [/dm/dm_bak/b1] START......
total 4 packages processed...
RESTORE DATABASE , UPDATE ctl file......
RESTORE DATABASE , REBUILD key file......
RESTORE DATABASE , CHECK db info......
RESTORE DATABASE , UPDATE db info......
total 5 packages processed!
CMD END.CODE:[0]
restore successfully.
time used: 3137.422(ms)

RMAN> recover database '/dm/dmdbms/data/dave_for_res/dm.ini' with archivedir '/dm/dmarch';
recover database '/dm/dmdbms/data/dave_for_res/dm.ini' with archivedir '/dm/dmarch';
Global parameter value of RT_HEAP_TARGET is illegal, use min value!
checking if the database under system path [/dm/dmdbms/data/dave_for_res] is running...[4].
checking if the database under system path [/dm/dmdbms/data/dave_for_res] is running...[3].
checking if the database under system path [/dm/dmdbms/data/dave_for_res] is running...[2].
checking if the database under system path [/dm/dmdbms/data/dave_for_res] is running...[1].
checking if the database under system path [/dm/dmdbms/data/dave_for_res] is running...[0].
checking if the database under system path [/dm/dmdbms/data/dave_for_res] is running, write dmrman info.
EP[0] max_lsn: 469180
EP[0] Recover LSN from 469181 to 469180.
Recover from archive log finished, time used:0.001s.
recover successfully!
time used: 7034.139(ms)
RMAN>

启动目标库 D2,向数据库中继续插入数据。

[dave@www.cndba.cn bin]$ pwd
/dm/dmdbms/bin
[dave@www.cndba.cn bin]$ ./dmserver /dm/dmdbms/data/dave_for_res/dm.ini

SQL>BEGIN
FOR I IN 1..100000 LOOP
INSERT INTO TAB_FOR_RECOVER VALUES(I);
COMMIT;
END LOOP;
END;
/

6)插入数据一段时间后,杀掉数据库进程,模拟数据库第二次故障。数据库 D2 启动到第二次故障之间产生的归档为 A2。

[dave@www.cndba.cn anqing]$ ps -ef|grep dm.ini
dmdba     7480  6806  1 00:54 pts/7    00:00:01 ./dmserver /dm/dmdbms/data/dave_for_res/dm.ini
dmdba     7541  7099  0 00:55 pts/8    00:00:00 grep dm.ini
[dave@www.cndba.cn anqing]$ kill -9 7480
[dave@www.cndba.cn anqing]$

7) 恢复目标库D2到第一次故障前的状态。恢复一次,目标库的DB_MAGIC都会改变,因此归档 A1、A2 的 DB_MAGIC 不同,属于不同的数据库。第一次恢复只能先重做归档 A1,即恢复到第一次故障前的状态。

RMAN> restore database '/dm/dmdbms/data/dave_for_res/dm.ini' from backupset '/dm/dm_bak/b1';
restore database '/dm/dmdbms/data/dave_for_res/dm.ini' from backupset '/dm/dm_bak/b1';
Global parameter value of RT_HEAP_TARGET is illegal, use min value!
checking if the database under system path [/dm/dmdbms/data/dave_for_res] is running...[4].
checking if the database under system path [/dm/dmdbms/data/dave_for_res] is running...[3].
checking if the database under system path [/dm/dmdbms/data/dave_for_res] is running...[2].
checking if the database under system path [/dm/dmdbms/data/dave_for_res] is running...[1].
checking if the database under system path [/dm/dmdbms/data/dave_for_res] is running...[0].
checking if the database under system path [/dm/dmdbms/data/dave_for_res] is running, write dmrman info.
RESTORE DATABASE  CHECK......
RESTORE DATABASE , dbf collect......
RESTORE DATABASE , dbf refresh ......
RESTORE BACKUPSET [/dm/dm_bak/b1] START......
total 4 packages processed...
RESTORE DATABASE , UPDATE ctl file......
RESTORE DATABASE , REBUILD key file......
RESTORE DATABASE , CHECK db info......
RESTORE DATABASE , UPDATE db info......
total 5 packages processed!
CMD END.CODE:[0]
restore successfully.
time used: 8134.802(ms)
RMAN> recover database '/dm/dmdbms/data/dave_for_res/dm.ini' with archivedir '/dm/dmarch';
recover database '/dm/dmdbms/data/dave_for_res/dm.ini' with archivedir '/dm/dmarch';
Global parameter value of RT_HEAP_TARGET is illegal, use min value!
checking if the database under system path [/dm/dmdbms/data/dave_for_res] is running...[4].
checking if the database under system path [/dm/dmdbms/data/dave_for_res] is running...[3].
checking if the database under system path [/dm/dmdbms/data/dave_for_res] is running...[2].
checking if the database under system path [/dm/dmdbms/data/dave_for_res] is running...[1].
checking if the database under system path [/dm/dmdbms/data/dave_for_res] is running...[0].
checking if the database under system path [/dm/dmdbms/data/dave_for_res] is running, write dmrman info.
EP[0] max_lsn: 469180
EP[0] Recover LSN from 469181 to 469180.
Recover from archive log finished, time used:0.001s.
recover successfully!
time used: 7022.996(ms)
RMAN>

8) 使用dmrachk 工具查看归档 A2 的 DB_MAGIC。

https://www.cndba.cn/dave/article/3615

[dave@www.cndba.cn dmarch]$ dmrachk arch_fil=/dm/dmarch/ARCHIVE_LOCAL1_20290307003048118_0.log
rachk V7.6.0.95-Build(2018.09.13-97108)ENT 
/*******************************************************************/
archive file /dm/dmarch/ARCHIVE_LOCAL1_20290307003048118_0.log itemize.
version        : 0x7004
status         : ACTIVE
n_rpags        : 1037
db_magic       : 1687445662
pemnt_magic    : 1317091524
arch_lsn       : 464212
arch_seq       : 119523
clsn           : 469180
next_seq       : 120559
file len       : 1073741824
file free      : 535040
create time    : 2029-03-07 00:30:47
close time     : 2029-03-07 00:30:48
crc_check      : TRUE
/*******************************************************************/

The SUMMARY(seqno[0]):
total files: 1
okey files: 1
fail file: 0
repeat file: 0

the rachk tool running cost 2.594 ms
[dave@www.cndba.cn dmarch]$

DM7 达梦数据库 dmrachk 工具 使用说明
https://www.cndba.cn/dave/article/3601

9)修改目标库 D2 的 DB_MAGIC 与归档 A2 一致。
若要利用归档恢复,必须保证数据库的 DB_MAGIC 与归档的 DB_MAGIC 一致。由步骤 8 的查询可知,归档 A2 的 DB_MAGIC为 1687445662。修改数据库的 DB_MAGIC 需要修改 SYSTEM.DBF 和2个重做日志文件,步骤如下:

[dave@www.cndba.cn dave_for_res]$ pwd
/dm/dmdbms/data/dave_for_res
[dave@www.cndba.cn dave_for_res]$ ls
bak      dave_for_res01.log  dm.ctl  dminit20290307005106.log  dm_service.prikey  MAIN.DBF          ROLL.DBF    SYSTEM.DBF  trace
ctl_bak  dave_for_res02.log  dm.ini  dminst.sys                HMAIN              rep_conflict.log  sqllog.ini  TEMP.DBF
[dave@www.cndba.cn dave_for_res]$ 

--修改文件 SYSTEM.DBF
[dave@www.cndba.cn dave_for_res]$ dmmdf TYPE=1 FILE=/dm/dmdbms/data/dave_for_res/SYSTEM.DBF 
dmmdf V7.6.0.95-Build(2018.09.13-97108)ENT 
**********************************************************
1 db_magic=-889287476
2 next_trxid=101217
3 pemnt_magic=1317091524
**********************************************************
Please input which parameter you want to change(1-3), q to quit: 1
Please input new value: 1687445662
**********************************************************
1 db_magic=1687445662
2 next_trxid=101217
3 pemnt_magic=1317091524
**********************************************************
Do you want to save the change to file (y/n): Y
Save to file success!
[dave@www.cndba.cn dave_for_res]$ 

--修改文件2个重做日志文件:重复2次,修改2个文件:
[dave@www.cndba.cn dave_for_res]$ dmmdf TYPE=2 FILE=/dm/dmdbms/data/dave_for_res/dave_for_res01.log
dmmdf V7.6.0.95-Build(2018.09.13-97108)ENT 
**********************************************************
1 sig = DMRLOG
2 ver = 7004
3 chksum = 0
4 dbversion = 0x7000a
5 sta = 1
6 n_magic = 14
7 db_magic = -889287476
8 clsn_fil = 0
10 next_seq = 0
11 arch_seq = 0
12 len = 268435456
13 free = 4096
14 clsn = 469180
15 clsn_off = 4096
16 arch_lsn = 0
17 pemnt_magic = 1317091524
18 fil_id = 0
19 crc_check = 1
**********************************************************
You can only reset sta(5) or db_magic (7) or clsn (14) or pemnt_magic(17) or fil_id(18).
Please input the num which one you want to change, q to quit: 7
Input the new value: 1687445662
**********************************************************
1 sig = DMRLOG
2 ver = 7004
3 chksum = 0
4 dbversion = 0x7000a
5 sta = 1
6 n_magic = 14
7 db_magic = 1687445662
8 clsn_fil = 0
10 next_seq = 0
11 arch_seq = 0
12 len = 268435456
13 free = 4096
14 clsn = 469180
15 clsn_off = 4096
16 arch_lsn = 0
17 pemnt_magic = 1317091524
18 fil_id = 0
19 crc_check = 1
**********************************************************
Do you want to quit and save the change to file (y/n): y
Save to file success!
[dave@www.cndba.cn dave_for_res]$

10) 利用归档 A2 恢复数据库至第二次故障前的状态。https://www.cndba.cn/dave/article/3615

RMAN> recover database '/dm/dmdbms/data/dave_for_res/dm.ini' with archivedir '/dm/dmarch';
recover database '/dm/dmdbms/data/dave_for_res/dm.ini' with archivedir '/dm/dmarch';
Global parameter value of RT_HEAP_TARGET is illegal, use min value!
checking if the database under system path [/dm/dmdbms/data/dave_for_res] is running...[4].
checking if the database under system path [/dm/dmdbms/data/dave_for_res] is running...[3].
checking if the database under system path [/dm/dmdbms/data/dave_for_res] is running...[2].
checking if the database under system path [/dm/dmdbms/data/dave_for_res] is running...[1].
checking if the database under system path [/dm/dmdbms/data/dave_for_res] is running...[0].
checking if the database under system path [/dm/dmdbms/data/dave_for_res] is running, write dmrman info.
EP[0] max_lsn: 469180
EP[0] Recover LSN from 469181 to 469180.
Recover from archive log finished, time used:0.001s.
recover successfully!
time used: 7046.663(ms)
RMAN>

11)起库查询:

[dave@www.cndba.cn bin]$ ./dmserver /dm/dmdbms/data/dave_for_res/dm.ini
file dm.key not found, use default license!
Global parameter value of RT_HEAP_TARGET is illegal, use min value!
version info: develop
Use normal os_malloc instead of HugeTLB
Use normal os_malloc instead of HugeTLB
DM Database Server x64 V7.6.0.95-Build(2018.09.13-97108)ENT  startup...
License will expire in 14 day(s) on 2029-03-21
ckpt lsn: 469180
ndct db load finished
ndct fill fast pool finished
EP[0] pseg_collect_items end, collect 0 trx, 0 committed pages, 0 active pages
EP[0] undo over, total 0 page rollbacked
purge over, total 0 page purged
set EP[0]'s pseg state to inactive
iid page's trxid = 101217
NEXT TRX ID = 101218
pseg recv finished
nsvr_startup end.
aud sys init success.
aud rt sys init success.
systables desc init success.
ndct_db_load_info success.
nsvr_process_before_open begin.
nsvr_process_before_open success.
SYSTEM IS READY.

版权声明:本文为博主原创文章,未经博主允许不得转载。

用户评论
* 以下用户言论只代表其个人观点,不代表CNDBA社区的观点或立场
dave

dave

关注

人的一生应该是这样度过的:当他回首往事的时候,他不会因为虚度年华而悔恨,也不会因为碌碌无为而羞耻;这样,在临死的时候,他就能够说:“我的整个生命和全部精力,都已经献给世界上最壮丽的事业....."

  • 2241
    原创
  • 3
    翻译
  • 550
    转载
  • 187
    评论
  • 访问:6767756次
  • 积分:4258
  • 等级:核心会员
  • 排名:第1名
精华文章
    最新问题
    查看更多+
    热门文章
      热门用户
      推荐用户
        Copyright © 2016 All Rights Reserved. Powered by CNDBA · 皖ICP备2022006297号-1·

        QQ交流群

        注册联系QQ