redo文件误删除后通过逻辑备份进行恢复

问题描述

开发同事让在一个服务器上查找下先前库的备份文件是否存在,如果存在进行下恢复。翻了服务器发现备份文件存在,多愁了一眼竟翻到了该备份文件于2024.6.17日恢复过的日志,赶紧和开发沟通说2024.6.17号已经恢复过了为啥还要恢复,开发这才说出关键:前几天清理磁盘,不小心将log文件删除了现在库不能启动,咨询了另一个DBA说是得重新恢复。可见沟通很关键啊,沟通后可不敢直接开干,多问问多翻翻多核实。

分析过程

查看服务器上备份文件

说明:db_20240617_TOPICIS_5238.dmp是由其他服务器上备份后上传到该服务器上并进行恢复的,db_20240617_TOPICIS_5238_imp.log是恢复日志。

[dmdba@db191 dmbak]$ ls -lhtr TOPICIS

-rw------- 1 dmdba dinstall 91G 6月 17 23:06 db_20240617_TOPICIS_5238.dmp

-rw------- 1 dmdba dinstall 1.8M 6月 17 23:06 db_20240617_TOPICIS_5238_exp.log

-rw-r--r-- 1 dmdba dinstall 3.1M 6月 18 04:37 db_20240617_TOPICIS_5238_imp.log

启动实例

查看配置文件

--查找配置文件

[root@db191 dmbak]# find / -name dm.ini

/opt/dmdb/topicis/topicis/dm.ini

/opt/dmdb/dzzzk/dzzzk/dm.ini

/opt/dmdb/DMSERVER/DAMENG/dm.ini

/opt/dmdb/xzspkp5555/xzspkp/dm.ini

--查看配置文件内容

[root@db191 dmbak]# cat /opt/dmdb/topicis/topicis/dm.ini | grep PORT

PORT_NUM = 5238 #Port number on which the database server will listen

ELOG_REPORT_LINK_SQL = 0 #Whether to write the SQLs that sent to remote database by DBLINKs into error log file

DFS_HUGE_SUPPORT = 1 #Whether support huge table operation in DDFS

EXTERNAL_JFUN_PORT = 6363 #DmAgent port for external java fun.

EXTERNAL_AP_PORT = 4236 #DmAp port for external fun.

DCRS_PORT_NUM = 6236 #Port number on which the database dcrs will listen

AP_PORT_NUM = 0 #Port number on which the database ap will listen

DW_PORT = 0 #Instance tcp port for watch2

HA_INST_CHECK_PORT = 65534 #HA instance check port

查看实例服务

db_20240617_TOPICIS_5238.dmp对应的是DmServiceTOPICIS.service

[root@db191 dmbak]# systemctl list-units D*

UNIT LOAD ACTIVE SUB DESCRIPTION

DmAPService.service loaded active running DM Assistant Plug-In Service(DmAPService).

DmServiceDMSERVER.service loaded active running DM Instance Service

● DmServicedzzzk.service loaded failed failed DM Instance Service

● DmServiceTOPICIS.service loaded failed failed DM Instance Service

DmServicexzspkp.service loaded active running DM Instance Service

启动实例

[root@db191 dmbak]# systemctl start DmServiceTOPICIS

Job for DmServiceTOPICIS.service failed because the control process exited with error code. See "systemctl status DmServiceTOPICIS.service" and "journalctl-xe" for details.

启动失败

查看启动失败日志

日志位置:安装目录/log下

cd /opt/dmdbms/log

tail -300f dm_TOPICIS_202410.log

输出如下:

2024-10-16 13:43:30.587 [INFO] database P0000001716 T0

000000000000001716 DM Database Server 64 V8 03134284044-20230703-194450-20040 startup...

2024-10-16 13:43:31.840 [INFO] database P0000001716 T0000000000000001716 fil_sys_init

2024-10-16 13:43:31.990 [INFO] database P0000001716 T0000000000000001716 Database mode = 0, oguid = 0

2024-10-16 13:43:31.991 [FATAL] database P0000001716 T0000000000000001716 /opt/dmdb/topicis/topicis/topicis01.log not exist,can not startup

2024-10-17 09:07:28.861 [INFO] database P0000020309 T0000000000000020309 INI parameter DPC_2PC changed, the original value 1, new value 0

2024-10-17 09:07:28.866 [INFO] database P0000020309 T0000000000000020309 version info: develop

2024-10-17 09:07:28.868 [INFO] database P0000020309 T0000000000000020309 os_sema2_create_low, create and inc sema success, key:125441262, sem_id:2, sem_value:1!

2024-10-17 09:07:28.874 [INFO] database P0000020309 T0000000000000020309 ini_set_secini, ini parameter PWD_POLICY changed, the original value 2, new value0

2024-10-17 09:07:29.650 [INFO] database P0000020309 T0000000000000020309 DM Database Server 64 V8 03134284044-20230703-194450-20040 startup...

2024-10-17 09:07:29.924 [INFO] database P0000020309 T0000000000000020309 fil_sys_init

2024-10-17 09:07:30.075 [INFO] database P0000020309 T0000000000000020309 Database mode = 0, oguid = 0

2024-10-17 09:07:30.075 [FATAL] database P0000020309 T0000000000000020309 /opt/dmdb/topicis/topicis/topicis01.log not exist,can not startup

解决办法

查看初始化参数

着重关注的参数有:

page size:单位字节 而初始化参数界面单位是K,注意转换

extent size:单位页

case sensitive:取值:Y、y、1 表示敏感;N、n、0 表示不敏感。默认值为 Y

charset:0 代表 GB18030,1 代表 UTF-8,2 代表韩文字符集 EUC-KR。默认为 0

length in char:VARCHAR 类型对象的长度是否以字符为单位。取值为 1 或者 Y 表示是,取值为 0 或 N 表示否。默认值为 0

cd /opt/dmdb/topicis/topicis

ls -l dminit*

输出如下:

[dmdba@db191 topicis]$ ls -l dminit*

-rw-r--r-- 1 dmdba dinstall 1009 6月 17 22:09 dminit20240617220946.log

[dmdba@db191 topicis]$ more dminit20240617220946.log

start init database: V8, 2024-06-17 22:09:46

init params:

db path: /opt/dmdb/topicis/topicis

db name: topicis

auto overwrite: 0

page size: 8192

extent size: 16

char_fix_storage: 0

sql_log_forbid: 0

secur_flag: 2

time zone: +08:00

string case sensitive: 1

charset: 1

length in char: 0

page check mode: 0

page check algorithm id: 0

priv flag: 0

env label: 0

rlog enc flag: 0

use new hash: 1

blank pad mode: 0

sec priv mode: 0

huge with delta: 1

rlog gen for huge: 1

pseg_mgr_flag: 0

log file path: /opt/dmdb/topicis/topicis/topicis01.log

log file path: /opt/dmdb/topicis/topicis/topicis02.log

create ini file /opt/dmdb/topicis/topicis/dm.ini success.

create rlog file /opt/dmdb/topicis/topicis/topicis01.log success.

create rlog file /opt/dmdb/topicis/topicis/topicis02.log success.

SYSTEM file : /opt/dmdb/topicis/topicis/SYSTEM.DBF

MAIN file : /opt/dmdb/topicis/topicis/MAIN.DBF

ROLL file : /opt/dmdb/topicis/topicis/ROLL.DBF

create dm database success. 2024-06-17 22:09:50

移除系统服务(重要)

systemctl disable DmServiceTOPICIS

cd /opt/dmdbms/bin

ls -l DmServiceTOPICIS

mv DmServiceTOPICIS DmServiceTOPICIS_bak_date +%F

,不然后面初始化实例提示如下报错:

更改故障实例的端口(重要)

将/opt/dmdb/topicis/topicis/dm.ini中的PORT_NUM更改为未占用的端口,本文档更改为9999,不然后面初始化实例提示如下报错:

创建新的数据目录并赋予权限

mkdir -p /opt/dmdb/topicis/topicisnew

chown -R dmdba:dinstall /opt/dmdb/topicis/topicisnew

初始化新实例

采用的是图形化,避免参数错。

运行Xmanager Power Suite 7下tools文件夹下的Xmanager - Passive工具

su - dmdba

export DISPLAY=192.168.19.74:0.0

cd /opt/dmdbms/tool

./dbca.sh

执行以下脚本

su - root

mv /opt/dmdbms/bin/DmServicetopicis.service /usr/lib/systemd/system/DmServicetopicis.service

systemctl enable DmServicetopicis.service

systemctl start DmServicetopicis.service

创建业务用户

create user topicis identified by "123456789"

limit failed_login_attemps unlimited, password_lock_time unlimited, password_grace_time unlimited;

grant "DBA" to topicis;

逻辑恢复

su - dmdba

nohup /opt/dmdbms/bin/dimp USERID=topicis/123456789:5238 FILE=db_20240617_TOPICIS_5238.dmp DIRECTORY=/opt/dmbak LOG=db_20241017_TOPICIS_5238_imp.log LOG_WRITE=Y PARALLEL=28 &

参考链接:达梦DM8之使用dmmdf恢复误删除的undo/redo文件_file dm.key not found, use default license!-CSDN博客