DM数据库全库迁移方式之冷拷贝

达梦数据库主要可以通过DMRMAN备份还原、dexp/dimp逻辑备份方式、冷拷贝的方式进行去全库的迁移。DTS工具更适用于单个或者部分对象的迁移。

一、环境说明

操作系统 Centos 7.8
数据库软件安装路径 /dm/dmdbms
数据库文件路径 /dm/data02
数据库版本 DM V8
新的数据库文件路径 /dm/data

二、目的

通过冷拷贝的方式迁移整个数据库,新的数据库文件路径为/dm/data。
此处只记录迁移到同一台机器的不同目录。迁移到不同的机器上需要先安装相同版本的数据库软件,迁移的操作过程一样。

三、操作过程

1、关闭数据库

[dmdba@localhost ~]$ cd /dm/dmdbms/bin
[dmdba@localhost bin]$ ./DmService stop
Stopping DmService:                                        [ OK ]

2、拷贝所有的数据库文件

拷贝所有的数据文件、日志文件、控制文件等数据库文件。
这里是将整个数据库文件目录从/dm/data02拷贝至/dm/data目录

[dmdba@localhost ~]$ cd /dm/data02/
[dmdba@localhost data02]$ cp -r DAMENG /dm/data

3、将控制文件转换为文本文件

控制文件dm.ctl默认是二进制格式,需要通过dmctlcvt工具将其转换为文本文件,然后对文本文件进行修改之后再转换为二进制文件。
DM8 的dmctlcvt工具使用帮助如下:

[dmdba@localhost bin]$ ./dmctlcvt help
DMCTLCVT V8

格式: ./dmctlcvt KEYWORD=value
注意: 控制文件名称必须指定为dm.ctl、dmmpp.ctl、dss.ctl

关键字              说明
--------------------------------------------------------------------------------
TYPE                1 转换控制文件为文本文件(源文件路径中控制文件名称必须是dm.ctl或dmmpp.ctl或dss.ctl)
                    2 转换文本文件为控制文件(目标文件路径中控制文件名称必须是dm.ctl或dmmpp.ctl或dss.ctl)
SRC                 源文件路径
DEST                目标文件路径
DCR_INI             dmdcr.ini文件路径
DFS_INI             dmdfs.ini文件路径
HELP                打印帮助信息

示例:
./dmctlcvt TYPE=1 SRC=/opt/dmdbms/data/dameng/dm.ctl DEST=/opt/dmdbms/data/dameng/dmctl.txt
./dmctlcvt TYPE=2 SRC=/opt/dmdbms/data/dameng/dmctl.txt DEST=/opt/dmdbms/data/dameng/dm.ctl

使用dmctlcvt工具进行转换:

[dmdba@localhost dm]$ cd dmdbms/bin
[dmdba@localhost bin]$ ./dmctlcvt TYPE=1 SRC=/dm/data/DAMENG/dm.ctl DEST=/home/dmdba/dm_ctl.txt
DMCTLCVT V8
convert ctl to txt success!
或者使用下面语句:
[dmdba@localhost bin]$ ./dmctlcvt c2t /dm/data/DAMENG/dm.ctl /home/dmdba/dm_ctl.txt
DMCTLCVT V8
convert ctl to txt success!
两个语句作用相同。

控制文件文本内容如下:

##############################################################################
## please do not adjust parameter order, ensure the ctl have no difference ###
##########################################################################


# database name
dbname=DAMENG
# server mode
svr_mode=0
#OGUID
oguid=0
# db server version
version=117507927
# database version
db_version=458762
# pseg version
pseg_version=458762
#SGUID
sguid=1311874053
#NEXT_TS_ID
next_ts_id=6
#RAC_NODES
rac_nodes=1
#NEXT_HTS_ID
next_htsid=129
#TIME_FLAG
time_flag=170
#MDIR_FLAG
mdir_flag=31
#STARTUP_CNT
startup_cnt=2
#LAST_STARTUP_TIME
last_startup_time=DATETIME '2020-6-19 15:28:55'
#DM7_DCT_VERSION
dm7_dct_version=7
#DM8_DCT_VERSION
dm8_dct_version=18

#===============================================
#===============================================

# table space name
ts_name=SYSTEM
 # table space ID
ts_id=0
# table space status
ts_state=0
# table space cache
ts_cache=
# DSC node number
ts_nth=0
# table space create time
ts_create_time=DATETIME '2020-6-17 10:28:5'
# table space modify time
ts_modify_time=DATETIME '2020-6-17 10:28:5'
# table space encrypt flag
ts_encrypt_flag=0
# table space copy num
ts_copy_num=0
# table space region size flag
ts_size_flag=0

#-----------------------------------------------

# file path
fil_path=/dm/data02/DAMENG/SYSTEM.DBF
# mirror path
mirror_path=
# file id
fil_id=0
# whether the file is auto extend
autoextend=1
# file create time
fil_create_time=DATETIME '2020-6-17 10:28:5'
# file modify time
fil_modify_time=DATETIME '2020-6-17 10:28:5'
# the max size of file
fil_max_size=0
# next size of file
fil_next_size=0


#===============================================

# table space name
ts_name=ROLL
 # table space ID
ts_id=1
# table space status
ts_state=0
# table space cache
ts_cache=
# DSC node number
ts_nth=0
# table space create time
ts_create_time=DATETIME '2020-6-17 10:28:5'
# table space modify time
ts_modify_time=DATETIME '2020-6-17 10:28:5'
# table space encrypt flag
ts_encrypt_flag=0
# table space copy num
ts_copy_num=0
# table space region size flag
ts_size_flag=0

#-----------------------------------------------

# file path
fil_path=/dm/data02/DAMENG/ROLL.DBF
# mirror path
mirror_path=
# file id
fil_id=0
# whether the file is auto extend
autoextend=1
# file create time
fil_create_time=DATETIME '2020-6-17 10:28:5'
# file modify time
fil_modify_time=DATETIME '2020-6-17 10:28:5'
# the max size of file
fil_max_size=0
# next size of file
fil_next_size=0


#===============================================

# table space name
ts_name=RLOG
 # table space ID
ts_id=2
# table space status
ts_state=0
# table space cache
ts_cache=
# DSC node number
ts_nth=0
# table space create time
ts_create_time=DATETIME '2020-6-17 10:28:5'
# table space modify time
ts_modify_time=DATETIME '2020-6-17 10:28:5'
# table space encrypt flag
ts_encrypt_flag=0
# table space copy num
ts_copy_num=0
# table space region size flag
ts_size_flag=0

#-----------------------------------------------

# file path
fil_path=/dm/data02/DAMENG/DAMENG01.log
# mirror path
mirror_path=
# file id
fil_id=0
# whether the file is auto extend
autoextend=1
# file create time
fil_create_time=DATETIME '2020-6-17 10:28:5'
# file modify time
fil_modify_time=DATETIME '2020-6-17 10:28:5'
# the max size of file
fil_max_size=0
# next size of file
fil_next_size=0

# file path
fil_path=/dm/data02/DAMENG/DAMENG02.log
# mirror path
mirror_path=
# file id
fil_id=1
# whether the file is auto extend
autoextend=1
# file create time
fil_create_time=DATETIME '2020-6-17 10:28:5'
# file modify time
fil_modify_time=DATETIME '2020-6-17 10:28:5'
# the max size of file
fil_max_size=0
# next size of file
fil_next_size=0


#===============================================

# table space name
ts_name=MAIN
 # table space ID
ts_id=4
# table space status
ts_state=0
# table space cache
ts_cache=
# DSC node number
ts_nth=0
# table space create time
ts_create_time=DATETIME '2020-6-17 10:28:5'
# table space modify time
ts_modify_time=DATETIME '2020-6-17 10:28:5'
# table space encrypt flag
ts_encrypt_flag=0
# table space copy num
ts_copy_num=0
# table space region size flag
ts_size_flag=0

#-----------------------------------------------

# file path
fil_path=/dm/data02/DAMENG/MAIN.DBF
# mirror path
mirror_path=
# file id
fil_id=0
# whether the file is auto extend
autoextend=1
# file create time
fil_create_time=DATETIME '2020-6-17 10:28:5'
# file modify time
fil_modify_time=DATETIME '2020-6-17 10:28:5'
# the max size of file
fil_max_size=0
# next size of file
fil_next_size=0


#===============================================

# table space name
ts_name=TEST
 # table space ID
ts_id=5
# table space status
ts_state=0
# table space cache
ts_cache=NORMAL
# DSC node number
ts_nth=0
# table space create time
ts_create_time=DATETIME '2020-6-19 14:30:39'
# table space modify time
ts_modify_time=DATETIME '2020-6-19 14:34:13'
# table space encrypt flag
ts_encrypt_flag=0
# table space copy num
ts_copy_num=0
# table space region size flag
ts_size_flag=0

#-----------------------------------------------

# file path
fil_path=/dm/data02/DAMENG/test.dbf    
# mirror path
mirror_path=
# file id
fil_id=0
# whether the file is auto extend
autoextend=1
# file create time
fil_create_time=DATETIME '2020-6-19 14:30:39'
# file modify time
fil_modify_time=DATETIME '2020-6-19 14:34:13'
# the max size of file
fil_max_size=0
# next size of file
fil_next_size=0


#===============================================

# HUGE table space name
htsname=HMAIN
# HUGE table space id
htsid=128
#HUGE table space share flag
htsflag=0
# HUGE table space copy num
hts_copy_num=0
# HUGE table space region size flag
hts_size_flag=0
# HUGE table space create time
hts_create_time=DATETIME '2020-6-17 10:28:5'
# HUGE table space modify time
hts_modify_time=DATETIME '2020-6-17 10:28:5'
# HUGE table space path
htspath=/dm/data02/DAMENG/HMAIN

#===============================================

控制文件文本文件中第一部分为数据库相关属性及记录,第二部分为表空间数据文件、日志文件属性。

4、修改控制文件的文本文件

将dm_ctl.txt文件中的file path及htspath等涉及路径的配置,更改为对应新的路径。

更改后内容如下:

[dmdba@localhost bin]$ cat /home/dmdba/dm_ctl.txt|grep -v "mirror_path"|grep -v "^#"|grep path
fil_path=/dm/data/DAMENG/SYSTEM.DBF
fil_path=/dm/data/DAMENG/ROLL.DBF
fil_path=/dm/data/DAMENG/DAMENG01.log
fil_path=/dm/data/DAMENG/DAMENG02.log
fil_path=/dm/data/DAMENG/MAIN.DBF
fil_path=/dm/data/DAMENG/test.dbf
htspath=/dm/data/DAMENG/HMAIN

5、转换修改后的文本文件为新控制文件

使用dmctlcvt工具将修改后的文本文件转换为二进制文件:

[dmdba@localhost bin]$ ./dmctlcvt TYPE=2 SRC=/home/dmdba/dm_ctl.txt DEST=/dm/data/DAMENG/dm.ctl
DMCTLCVT V8
convert txt to ctl success!
或者使用下面语句:
[dmdba@localhost bin]$ ./dmctlcvt t2c /home/dmdba/dm_ctl.txt /dm/data/DAMENG/dm.ctl 

6、更新dm.ini文件中配置的相关路径

查看需要更改的相关配置参数:

[dmdba@localhost ~]$ cd /dm/data/DAMENG/
[dmdba@localhost DAMENG]$ cat dm.ini |grep "/dm/data02"
		CTL_PATH      = /dm/data02/DAMENG/dm.ctl     #ctl file path
		CTL_BAK_PATH  = /dm/data02/DAMENG/ctl_bak    #dm.ctl backup path
		SYSTEM_PATH   = /dm/data02/DAMENG            #system path
		CONFIG_PATH   = /dm/data02/DAMENG            #config path
		TEMP_PATH    = /dm/data02/DAMENG        #temporary file path
		BAK_PATH    = /dm/data02/DAMENG/bak        #backup file path

更改后,内容如下:

[dmdba@localhost DAMENG]$ cat dm.ini |grep "/dm/data02"
		CTL_PATH      = /dm/data/DAMENG/dm.ctl     #ctl file path
		CTL_BAK_PATH  = /dm/data/DAMENG/ctl_bak    #dm.ctl backup path
		SYSTEM_PATH   = /dm/data/DAMENG            #system path
		CONFIG_PATH   = /dm/data/DAMENG            #config path
		TEMP_PATH    = /dm/data/DAMENG        #temporary file path
		BAK_PATH    = /dm/data/DAMENG/bak        #backup file path

7、测试是否能正常启动

使用dmserver前台启动测试:

[dmdba@localhost ~]$ cd /dm/dmdbms/bin
[dmdba@localhost bin]$ ./dmserver /dm/data/DAMENG/dm.ini 
file dm.key not found, use default license!
version info: develop
Use normal os_malloc instead of HugeTLB
Use normal os_malloc instead of HugeTLB
DM Database Server x64 V8 1-1-87-20.06.01-122565-ENT  startup...
Database mode = 0, oguid = 0
License will expire on 2021-06-01
file lsn: 43647
ndct db load finished
ndct fill fast pool finished
iid page's trxid[10078]
NEXT TRX ID = 10079
pseg_collect_items, collect 0 active_trxs, 0 cmt_trxs, 0 pre_cmt_trxs, 0 active_pages, 0 cmt_pages, 0 pre_cmt_pages
pseg_process_collect_items end, 0 active trx, 0 active pages, 0 committed trx, 0 committed pages
total 0 active crash trx, pseg_crash_trx_rollback sys_only(0) begin ...
pseg_crash_trx_rollback end
purg2_crash_cmt_trx end, total 0 page purged
set EP[0]'s pseg state to inactive
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.
total 0 active crash trx, pseg_crash_trx_rollback sys_only(0) begin ...
pseg_crash_trx_rollback end
SYSTEM IS READY.

启动正常

8、修改数据库服务脚本INI_PATH配置

修改DmService服务脚本中INI_PATH的值为新路径下的dm.ini,内容如下:

[dmdba@localhost bin]$ cat DmService |grep -w "INI_PATH="
INI_PATH="/dm/data/DAMENG/dm.ini"

启动、关闭测试:

---start
[dmdba@localhost bin]$ ./DmService start
Starting DmService:                                        [ OK ]
[dmdba@localhost bin]$ ps -ef|grep -v grep|grep dms
dmdba      7371      1  1 18:02 pts/2    00:00:00 /dm/dmdbms/bin/dmserver /dm/data/DAMENG/dm.ini -noconsole

---stop
[dmdba@localhost bin]$ ./DmService stop
Stopping DmService:                                        [ OK ]

四、总结

DM数据库冷拷贝方式迁移与Oracle类似,都需要对控制文件进行修改。通过dmctlcvt工具对控制文件类型进行转换,在使用上要更方便一些。
DM数据库冷拷贝迁移不能跨大版本,小版本之间迁移需要注意CHECK_SVR_VERSION参数的配置,拷贝迁移到低版本时,迁移完成后,启动之前需要将该参数设置为0。

你可能感兴趣的:(达梦)