使用dmrestore工具还原数据库
1. 概述
DM支持利用还原工具对数据库进行还原。根据不同备份类型,包括联机备份、脱机备份、完全备份以及增量备份,还原工具选择不同的还原策略实现恢复用户数据的目的。首先讨论联机备份与脱机备份,脱机备份仅包含数据页文件的内容,而联机备份文件除了包含数据页文件内容以外,可能还包括备份过程中产生的日志文件内容。因此在利用联机备份还原时,除了拷贝数据页至数据库文件以外,可能还需要重做备份的日志文件内容,达到还原数据库的目的。在还原联机库备份且不带日志的备份时,需要用户指定归档目录,由用户保证备份期间的归档日志存在且完好,在还原库时,需要重做该日志。如果日志不存在,则备份文件就无效,报错归档日志错误。
接下来讨论完全备份与增量备份,对于增量备份,还原工具会根据用户提供备份的信息搜集它的基础备份,若基础备份仍然为增量备份,则工具会继续搜集,直至搜集到一个类型为完全备份的基础备份为止。因此在这个过程中,工具会构造一个基础备份链表,备份链表基于备份间的依赖关系组织。比如,备份A是备份B的增量备份,则可以说A依赖于B。若用户首先进行了一次完全备份A,然后在A的基础上做了增量备份B,随后基于增量备份B又做了增量备份C,最后基于增量备份C做了增量备份D。那么此时利用增量备份D还原数据库时,系统搜集到得备份链表如30.1所示,执行还原时,首先利用完全备份恢复A进行还原,然后依次利用增量备份B,C和D还原,最终完成整个还原过程。需要说明的是,若备份类型为B树备份的数据库备份是不存在增量备份的。
脱机库还原支持无备份文件的还原,原理就是利用归档文件,在目标库上执行REDO操作,把库还原到指定的时间点或者LSN。限制条件是,
1)目标库和归档必须是源自同一个库;2)必须保证源库的归档是完整,否则会出现不可预知的错误,即要保证备份之后产生的归档是完整的。要利用归档还原,需要利用备份文件还原一个目标库,修改目标库db_magic和源库中归档文件的db_magic一致。然后就可以执行还原操作了。库db_magic的修改可以使用dmmdf工具。
dmmdf工具的用法如下:
dmmdf KEYWORD=value
在Windows“命令提示符”窗口中输入带参数的dmmdf命令启动该工具,参数说明见
[dmdba@shard1 dmdbms]$ dmmdf help Format: ./dmmdf KEYWORD=value Example: ./dmmdf TYPE=1 FILE=/opt/data/DAMENG/SYSTEM.DBF Keyword Explanation -------------------------------------------------------------------------------- TYPE type 1: for dbf 2: for rlog 3: for original bak 4: for bakset meta 5: for bakset bkp 6: for bakset 7: batch modify db_magic for arch file 8: for database degrades 9:batch modify crc_check for DB specified by dm.ini. 10:batch modify crc_check for archive log in archive directory. FILE file path DCR_INI dmdcr.ini path DB_MAGIC_SRC db_magic_src,for TYPE=7 and 10 DB_MAGIC_DST db_magic_dst,for TYPE=7 CRC_CHECK crc_check,for TYPE=9 and 10 HELP show this help info -------------------------------------------------- Example: ./dmmdf TYPE=1 FILE=/opt/data/DAMENG/SYSTEM.dbf ./dmmdf TYPE=2 FILE=/opt/data/DAMENG/DAMENG01.log ./dmmdf TYPE=3 FILE=/opt/data/DAMENG/bak/dmdb.bak ./dmmdf TYPE=4 FILE=/opt/data/DAMENG/bak/bset/nbak.meta ./dmmdf TYPE=5 FILE=/opt/data/DAMENG/bak/bset/nbak.bak ./dmmdf TYPE=6 FILE=/opt/data/DAMENG/bak/bset ./dmmdf TYPE=7 FILE=/opt/data/DAMENG/arch DB_MAGIC_SRC=4734373 DB_MAGIC_DST=4734366 ./dmmdf TYPE=8 FILE=/opt/data/DAMENG/dm.ctl ./dmmdf TYPE=9 FILE=/opt/data/DAMENG/dm.ini,CRC_CHECK=1 ./dmmdf TYPE=10 FILE=/opt/data/DAMENG/arch,CRC_CHECK=0,DB_MAGIC_SRC=4734373
使用说明:
dmmdf工具可以修改TYPE中指定的文件中的信息,例如db_magic。
DMRESTORE还原工具的用法如下:
DMRESTORE KEYWORD=value 或KEYWORD=(value1,value2,...,valueN)
确认DM数据库服务器已停止后,在Windows“命令提示符”窗口中输入带参数的DMRESTORE命令启动该工具。
[dmdba@shard1 dmdbms]$ dmrestore help Format: DMRESTORE KEYWORD=value or KEYWORD=(value1,value2,...,valueN) Eg: DMRESTORE INI_PATH=/opt/dm7data/dameng/dm.ini FILE=/opt/dm7data/backup/test.bak Imperative Argument: FILE Keyword explain(default value) -------------------------------------------------------------------------------- INI_PATH the path of the dmserver's dm.ini file FILE backup file MAPPED_FIL the path of mapped file, when res_type assign 4. TIME the timestamp of be going to recover ARCHIVE_DIR the directory at backup, Format (dir1,dir2,dir3,...) BACKUP_DIR the stored path of backup file, be used to search backup file, Format (dir1,dir2,dir3,...) DATAFIL_PATH the file path at the recovery, Format (id1,path1,id2,path2,id3,path3,...) MIRROR_PATH the mirror file path at the recovery, Format (id1,path1,id2,path2,id3,path3,...) PARALLEL_DIR the full path of parallel mapping file RES_TYPE restore type(0,1,2,3,4), 0: bakfil restore, 1: bakfil show, 2: archfil restore, 3: step increment restore, 4:output mapped file default(0) END_LSN restore to end_lsn LOG restore output log file DUMMY quiet mode, {(Y)es,(N)o} default:No PASSWORD restore with password ENCRYPT_NAME restore decrypt with encrypt name HELP output help info
INI_PATH:配置文件路径,最大长度为256字节,可选参数
FILE:用于还原的备份文件完整路径,必选参数
MAPPED_FIL:当指定res_type为4时,输出备份文件的映射信息到该文件;如果指定res_type为0或3时,则还原时,会采用MAPPED_FIL文件中的data_path和mirror_path路径为准(如果用户希望使用相对路径策略还原,请删除相关的组,同时修改要修改的data_path和mirror_path)。此外,如果指定MAPPED_FIL参数,则本工具中datafil_path和mirror_path参数会失效;反之,则生效,可选参数
TIME:指定还原的时间点和指定还原的LSN,需要配合ARCHIVE_DIR使用,若指定了ARCHIVE_DIR,既没有指定TIME和END_LSN则会重做所有的归档;如果指定了某一个则会还原到指定的TIME或者LSN;如果都指定了,则会还原到早的一个时间点(或者LSN);如果指定END_LSN为1,则表示还原到备份的时候,不会redo归档,可选参数
END_LSN:指定还原的时间点和指定还原的LSN,需要配合ARCHIVE_DIR使用,若指定了ARCHIVE_DIR,既没有指定TIME和END_LSN则会重做所有的归档;如果指定了某一个则会还原到指定的TIME或者LSN;如果都指定了,则会还原到早的一个时间点(或者LSN);如果指定END_LSN为1,则表示还原到备份的时候,不会redo归档,可选参数。
BACKUP_DIR:备份文件存放路径,用于搜索备份文件(默认会搜索备份文件所在的目录,以及库的默认备份目录),可选参数
ARCHIVE_DIR:归档日志存放的目录,可以指定1~8个。在还原联机库备份且不带日志(WITHOUT LOG)的备份文件时,ARCHIVE_DIR为必选参数,可选参数。
DATAFIL_PATH:指定还原后的新文件路径([编号,路径],……,[编号,路径])。编号与路径成对出现,最多可以指定16个。编号为大于0的整数。MAPPED_FIL优先,可选参数。
PARALLEL_DIR:并行映射文件存放路径,用于搜索映射文件,可选参数
SHOW_BAK_INFO:可选值(0,1,2)0:表示利用备份还原;1:仅显示备份信息,不进行还原;2:表示使用归档日志进行还原;默认值为0。该参数已被RES_TYPE取代,为兼容之前版本,暂时保留。如果同时指定RES_TYPE和SHOW_BAK_INFO,则RES_TYPE有效,SHOW_BAK_INFO无效,可选参数。
RES_TYPE:可选值(0,1,2,3,4)0:表示利用备份还原;1:仅显示备份信息,不进行还原;2:表示使用归档日志进行还原;3:仅还原单个完全备份或者增量备份;4:仅仅输出备份文件映射信息到文件。默认值为0,可选参数。
MIRROR_PATH:指定备份库中的镜像文件路径在还原时的映射路径。([编号,路径],……,[编号,路径])。编号与路径成对出现,最多可以指定16个。编号为大于0的整数,映射路径绝对路径。MAPPED_FIL优先,可选参数。
LOG:指定一个文件,还原时日志会写入该文件,可选参数。
DUMMY:静默模式,可以指定{(Y)es,(N)o}。默认No。交互信息处理: 打印(P)。Y:打印所有交互信息。N:不打印交互信息。可选参数。
PASSWORD:还原时,指定备份时的加密密码
ENCRYPT_NAME:还原时用来解密的算法名。缺省算法为AES256_CFB
HELP:打印帮助信息
若设置SHOW_BAK_INFO参数为1,则不需要利用备份进行还原操作,可以不指定INI_PATH;指定了BACKUP_DIR参数时,则会收集备份目录下的所有的备份,并分组输出;如果指定了FILE,且该备份文件是增量备份,则会收集增量备份相关的所有备份输出。
数据库还原时,如果需要重做的日志量较大,将INI参数BUFFER适当设大,可以提高还原的性能。
2. 使用备份文件还原
例如,利用备份文件/dm_home/dmdba/dmdbms/data/jydm/bak/DB_jydm_20200711192046000434.bak还原数据库
[dmdba@shard1 backup]$ dmrestore ini_path=/dm_home/dmdba/dmdbms/data/jydm/dm.ini file=/dm_home/dmdba/dmdbms/data/jydm/bak/DB_jydm_20200711192046000434.bak restore V7.1.6.46-Build(2018.02.08-89107)ENT file dm.key not found, use default license! backup sig: BA backup tool version: 12595 backup db name: jydm backup db magic: -82313077 backup pemnt magic: 1250320462 backup name: jydm backup type: full backup level: offline backup range: database backup description: compressed level: 0 encrypt_type: 0 encrypt_id: 2052 rac node: 0 page check: 0 rlog encrypt: 0 external cipher id: 0 external hash id: 0 length in char: 0 use new hash: 1 backup time: 2020-07-11 19:20:46 page size: 8 KB extent size: 16 case sensitive: 1 log page size: 512 B charset: 0 data version: 0x7000A sys version: V7.1.6.46-Build(2018.02.08-89107)ENT enable policy: 0 mpp_timestamp: 0 crc_check: TRUE parallel type: 0 parallel info len: 0 backup db fil num: 8 archive flag: 1 after backup LSN: 27830642 $bak_seq |$file_path |$size(K) |$used(K) 1|/dm_home/dmdba/dmdbms/data/jydm/bak/DB_jydm_20200711192046000434.bak| 294912.00| 284866.00 $file_seq |$type|$ts_name |$state |$size(K) |$seq_in_bak |$off_in_bak(B) |$len_in_bak(B) |$file_path |$mirror_path 1|DBF |SYSTEM |ONLINE | 23552| 1| 43008| 6766592|/dm_home/dmdba/dmdbms/data/jydm/SYSTEM.DBF | 2|DBF |ROLL |ONLINE | 229376| 1| 6809600| 401408|/dm_home/dmdba/dmdbms/data/jydm/ROLL.DBF | 3|DBF |MAIN |ONLINE | 210944| 1| 7211008| 171753472|/dm_home/dmdba/dmdbms/data/jydm/MAIN.DBF | 4|DBF |BOOKSHOP |ONLINE | 153600| 1| 178964480| 933888|/dm_home/dmdba/dmdbms/data/jydm/BOOKSHOP.DBF | 5|DBF |DMHR |ONLINE | 131072| 1| 179898368| 425984|/dm_home/dmdba/dmdbms/data/jydm/DMHR.DBF | 6|DBF |USERS |ONLINE | 51200| 1| 180324352| 1105920|/dm_home/dmdba/dmdbms/data/jydm/users01.dbf | 7|DBF |SYSAUX |ONLINE | 179200| 1| 181430272| 110256128|/dm_home/dmdba/dmdbms/data/jydm/SYSAWR.DBF | 8|DBF |FG_PERSON |ONLINE | 131072| 1| 291686400| 16384|/dm_home/dmdba/dmdbms/data/jydm/FG_PERSON.DBF | Continue?[Y/N]:Y restore bak_file: /dm_home/dmdba/dmdbms/data/jydm/bak/DB_jydm_20200711192046000434.bak ... start restore database... start restore file: /dm_home/dmdba/dmdbms/data/jydm/SYSTEM.DBF(SYSTEM), pages: 826 end restore file: /dm_home/dmdba/dmdbms/data/jydm/SYSTEM.DBF(SYSTEM) start restore file: /dm_home/dmdba/dmdbms/data/jydm/ROLL.DBF(ROLL), pages: 49 end restore file: /dm_home/dmdba/dmdbms/data/jydm/ROLL.DBF(ROLL) start restore file: /dm_home/dmdba/dmdbms/data/jydm/MAIN.DBF(MAIN), pages: 20966 end restore file: /dm_home/dmdba/dmdbms/data/jydm/MAIN.DBF(MAIN) start restore file: /dm_home/dmdba/dmdbms/data/jydm/BOOKSHOP.DBF(BOOKSHOP), pages: 114 end restore file: /dm_home/dmdba/dmdbms/data/jydm/BOOKSHOP.DBF(BOOKSHOP) start restore file: /dm_home/dmdba/dmdbms/data/jydm/DMHR.DBF(DMHR), pages: 52 end restore file: /dm_home/dmdba/dmdbms/data/jydm/DMHR.DBF(DMHR) start restore file: /dm_home/dmdba/dmdbms/data/jydm/users01.dbf(USERS), pages: 135 end restore file: /dm_home/dmdba/dmdbms/data/jydm/users01.dbf(USERS) start restore file: /dm_home/dmdba/dmdbms/data/jydm/SYSAWR.DBF(SYSAUX), pages: 13459 end restore file: /dm_home/dmdba/dmdbms/data/jydm/SYSAWR.DBF(SYSAUX) start restore file: /dm_home/dmdba/dmdbms/data/jydm/FG_PERSON.DBF(FG_PERSON), pages: 2 end restore file: /dm_home/dmdba/dmdbms/data/jydm/FG_PERSON.DBF(FG_PERSON) end restore database data files. Apply archive log LSN from 27830643 to 27830642, time used:0.000s. restore finished, code = 0! restore successfully! restore time used: 7144.214(ms)
例如,利用归档文件/dm_home/dmdbms/backup/arch还原数据库,这里将使用备份文件还原新的目标库
1.先将原备份库的备份文件和归档文件复制到新还原库的主机上
[dmdba@shard1 backup]$ scp -r /dm_home/dmdba/dmdbms/data/jydm/bak/DB_jydm_20200711192046000434.bak dmdba@10.138.130.187:/dm_home/dmdbms/backup/ dmdba@10.138.130.187's password: DB_jydm_20200711192046000434.bak 100% 288MB 96.0MB/s 00:03 [dmdba@shard1 backup]$ scp -r /dm_home/dmdba/dmdbms/data/arch dmdba@10.138.130.187:/dm_home/dmdbms/backup/ dmdba@10.138.130.187's password: ARCHIVE_LOCAL1_20200603195207512_0.log 100% 84MB 21.0MB/s 00:04 ARCHIVE_LOCAL1_20200606020009584_0.log 100% 6588KB 6.4MB/s 00:00 ARCHIVE_LOCAL1_20200606061513930_0.log 100% 24KB 24.0KB/s 00:00 ARCHIVE_LOCAL1_20200606062617837_0.log 100% 7168 7.0KB/s 00:00 ARCHIVE_LOCAL1_20200606062943852_0.log 100% 300MB 100.0MB/s 00:03 ARCHIVE_LOCAL1_20200606142842948_0.log 100% 300MB 100.0MB/s 00:03 ARCHIVE_LOCAL1_20200606142846352_0.log 100% 300MB 100.0MB/s 00:03 ARCHIVE_LOCAL1_20200606142902741_0.log 100% 300MB 33.3MB/s 00:09 ARCHIVE_LOCAL1_20200606142909259_0.log 100% 300MB 150.0MB/s 00:02 ARCHIVE_LOCAL1_20200606220653158_0.log 100% 300MB 50.0MB/s 00:06 ARCHIVE_LOCAL1_20200613210000757_0.log 100% 300MB 14.3MB/s 00:21 ARCHIVE_LOCAL1_20200617093523748_0.log 100% 32MB 7.9MB/s 00:04 ARCHIVE_LOCAL1_20200617161801000_0.log 100% 3926KB 3.8MB/s 00:00 ARCHIVE_LOCAL1_20200617170101954_0.log 100% 1464KB 1.4MB/s 00:00 ARCHIVE_LOCAL1_20200617173005734_0.log 100% 8583KB 8.4MB/s 00:01 ARCHIVE_LOCAL1_20200617190859140_0.log 100% 20MB 20.1MB/s 00:01 ARCHIVE_LOCAL1_20200622160035411_0.log 100% 220KB 220.0KB/s 00:00 ARCHIVE_LOCAL1_20200623172303743_0.log 100% 300MB 11.1MB/s 00:27 ARCHIVE_LOCAL1_20200624180051432_0.log 100% 300MB 10.7MB/s 00:28 ARCHIVE_LOCAL1_20200626193023317_0.log 100% 300MB 10.7MB/s 00:28 ARCHIVE_LOCAL1_20200630024319628_0.log 100% 47MB 9.5MB/s 00:05 ARCHIVE_LOCAL1_20200630173436447_0.log 100% 39MB 9.6MB/s 00:04 ARCHIVE_LOCAL1_20200706091427214_0.log 100% 300MB 9.7MB/s 00:31 ARCHIVE_LOCAL1_20200710110030273_0.log 100% 113MB 8.7MB/s 00:13 ARCHIVE_LOCAL1_20200606062454805_0.log 100% 7680 7.5KB/s 00:00 ARCHIVE_LOCAL1_20200606062942967_0.log 100% 7680 7.5KB/s 00:00 ARCHIVE_LOCAL1_20200606064235117_0.log 100% 16KB 15.5KB/s 00:00 ARCHIVE_LOCAL1_20200606142853068_0.log 100% 300MB 10.0MB/s 00:30 ARCHIVE_LOCAL1_20200606142906087_0.log 100% 300MB 23.1MB/s 00:13 ARCHIVE_LOCAL1_20200606142912805_0.log 100% 5120 5.0KB/s 00:00 ARCHIVE_LOCAL1_20200617193955110_0.log 100% 83MB 10.4MB/s 00:08 ARCHIVE_LOCAL1_20200622160200765_0.log 100% 234KB 234.0KB/s 00:00 ARCHIVE_LOCAL1_20200711193829081_0.log 100% 300MB 13.6MB/s 00:22 [dmdba@shard1 backup]$ [dmdba@dmks backup]$ ls -lrt drwxr-xr-x. 2 dmdba dinstall 4096 7月 11 19:47 arch -rw-r--r--. 1 dmdba dinstall 33554432 7月 11 19:50 DB_dmks_FULL_2020_07_11_19_50_30.bak
2.使用原备份库还原新库
[dmdba@dmks backup]$ dmrestore ini_path=/dm_home/dmdbms/data/dameng_for_recover/dm.ini file=/dm_home/dmdbms/backup/DB_jydm_20200711192046000434.bak restore V7.1.6.46-Build(2018.02.08-89107)ENT file dm.key not found, use default license! backup sig: BA backup tool version: 12595 backup db name: jydm backup db magic: -82313077 backup pemnt magic: 1250320462 backup name: jydm backup type: full backup level: offline backup range: database backup description: compressed level: 0 encrypt_type: 0 encrypt_id: 2052 rac node: 0 page check: 0 rlog encrypt: 0 external cipher id: 0 external hash id: 0 length in char: 0 use new hash: 1 backup time: 2020-07-11 19:20:46 page size: 8 KB extent size: 16 case sensitive: 1 log page size: 512 B charset: 0 data version: 0x7000A sys version: V7.1.6.46-Build(2018.02.08-89107)ENT enable policy: 0 mpp_timestamp: 0 crc_check: TRUE parallel type: 0 parallel info len: 0 backup db fil num: 8 archive flag: 1 after backup LSN: 27830642 $bak_seq |$file_path |$size(K) |$used(K) 1|/dm_home/dmdbms/backup/DB_jydm_20200711192046000434.bak| 294912.00| 284866.00 $file_seq |$type|$ts_name |$state |$size(K) |$seq_in_bak |$off_in_bak(B) |$len_in_bak(B) |$file_path |$mirror_path 1|DBF |SYSTEM |ONLINE | 23552| 1| 43008| 6766592|/dm_home/dmdba/dmdbms/data/jydm/SYSTEM.DBF | 2|DBF |ROLL |ONLINE | 229376| 1| 6809600| 401408|/dm_home/dmdba/dmdbms/data/jydm/ROLL.DBF | 3|DBF |MAIN |ONLINE | 210944| 1| 7211008| 171753472|/dm_home/dmdba/dmdbms/data/jydm/MAIN.DBF | 4|DBF |BOOKSHOP |ONLINE | 153600| 1| 178964480| 933888|/dm_home/dmdba/dmdbms/data/jydm/BOOKSHOP.DBF | 5|DBF |DMHR |ONLINE | 131072| 1| 179898368| 425984|/dm_home/dmdba/dmdbms/data/jydm/DMHR.DBF | 6|DBF |USERS |ONLINE | 51200| 1| 180324352| 1105920|/dm_home/dmdba/dmdbms/data/jydm/users01.dbf | 7|DBF |SYSAUX |ONLINE | 179200| 1| 181430272| 110256128|/dm_home/dmdba/dmdbms/data/jydm/SYSAWR.DBF | 8|DBF |FG_PERSON |ONLINE | 131072| 1| 291686400| 16384|/dm_home/dmdba/dmdbms/data/jydm/FG_PERSON.DBF | Continue?[Y/N]:Y Warning: Backup file may has been modified ! Continue?[Y/N]:Y restore bak_file: /dm_home/dmdbms/backup/DB_jydm_20200711192046000434.bak ... start restore database... start restore file: /dm_home/dmdbms/data/dameng_for_recover/SYSTEM.DBF(SYSTEM), pages: 826 end restore file: /dm_home/dmdbms/data/dameng_for_recover/SYSTEM.DBF(SYSTEM) start restore file: /dm_home/dmdbms/data/dameng_for_recover/ROLL.DBF(ROLL), pages: 49 end restore file: /dm_home/dmdbms/data/dameng_for_recover/ROLL.DBF(ROLL) start restore file: /dm_home/dmdbms/data/dameng_for_recover/MAIN.DBF(MAIN), pages: 20966 end restore file: /dm_home/dmdbms/data/dameng_for_recover/MAIN.DBF(MAIN) start restore file: /dm_home/dmdbms/data/dameng_for_recover/BOOKSHOP.DBF(BOOKSHOP), pages: 114 end restore file: /dm_home/dmdbms/data/dameng_for_recover/BOOKSHOP.DBF(BOOKSHOP) start restore file: /dm_home/dmdbms/data/dameng_for_recover/DMHR.DBF(DMHR), pages: 52 end restore file: /dm_home/dmdbms/data/dameng_for_recover/DMHR.DBF(DMHR) start restore file: /dm_home/dmdbms/data/dameng_for_recover/users01.dbf(USERS), pages: 135 end restore file: /dm_home/dmdbms/data/dameng_for_recover/users01.dbf(USERS) start restore file: /dm_home/dmdbms/data/dameng_for_recover/SYSAWR.DBF(SYSAUX), pages: 13459 end restore file: /dm_home/dmdbms/data/dameng_for_recover/SYSAWR.DBF(SYSAUX) start restore file: /dm_home/dmdbms/data/dameng_for_recover/FG_PERSON.DBF(FG_PERSON), pages: 2 end restore file: /dm_home/dmdbms/data/dameng_for_recover/FG_PERSON.DBF(FG_PERSON) end restore database data files. Apply archive log LSN from 27830643 to 27830642, time used:0.000s. restore finished, code = 0! restore successfully! restore time used: 44867.245(ms)
使用备份文件还原数据库归档日志LSN为27830643
3.使用dmmdbf工具查看原备份库中的db_magic为1371967312
[dmdba@shard1 backup]$ dmmdf type=1 file=/dm_home/dmdba/dmdbms/data/jydm/SYSTEM.DBF dmmdf V7.1.6.46-Build(2018.02.08-89107)ENT ********************************************************** 1 db_magic=1371967312 2 next_trxid=3377415 3 pemnt_magic=1250320462 ********************************************************** Please input which parameter you want to change(1-3), q to quit: q
4.使用dmmdf工具查看目标库的system.dbf的db_magic并进行修改1371967312
[dmdba@dmks dameng_for_recover]$ dmmdf type=1 file=/dm_home/dmdbms/data/dameng_for_recover/SYSTEM.DBF dmmdf V7.1.6.46-Build(2018.02.08-89107)ENT ********************************************************** 1 db_magic=-82313077 2 next_trxid=3377415 3 pemnt_magic=1250320462 ********************************************************** Please input which parameter you want to change(1-3), q to quit: 1 Please input new value: 1371967312 ********************************************************** 1 db_magic=1371967312 2 next_trxid=3377415 3 pemnt_magic=1250320462 ********************************************************** Do you want to save the change to file (y/n): y Save to file success!
5.使用dmmdf工具查看目标库的dameng_for_recover01.log和dameng_for_recover02.log的db_magic并进行修改-82313077
[dmdba@dmks dameng_for_recover]$ dmmdf type=2 file=/dm_home/dmdbms/data/dameng_for_recover/dameng_for_recover01.log dmmdf V7.1.6.46-Build(2018.02.08-89107)ENT ********************************************************** 1 sig = DMRLOG 2 ver = 7004 3 chksum = 0 4 dbversion = 0x7000a 5 sta = 0 6 n_magic = 35 7 db_magic = -82313077 8 clsn_fil = 0 10 next_seq = 304 11 arch_seq = 0 12 len = 268435456 13 free = 4096 14 clsn = 27830642 15 clsn_off = 4096 16 arch_lsn = 0 17 pemnt_magic = 1250320462 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: 1371967312 ********************************************************** 1 sig = DMRLOG 2 ver = 7004 3 chksum = 0 4 dbversion = 0x7000a 5 sta = 0 6 n_magic = 35 7 db_magic = 1371967312 8 clsn_fil = 0 10 next_seq = 304 11 arch_seq = 0 12 len = 268435456 13 free = 4096 14 clsn = 27830642 15 clsn_off = 4096 16 arch_lsn = 0 17 pemnt_magic = 1250320462 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! [dmdba@dmks dameng_for_recover]$ dmmdf type=2 file=/dm_home/dmdbms/data/dameng_for_recover/dameng_for_recover02.log dmmdf V7.1.6.46-Build(2018.02.08-89107)ENT ********************************************************** 1 sig = DMRLOG 2 ver = 7004 3 chksum = 0 4 dbversion = 0x7000a 5 sta = 0 6 n_magic = 35 7 db_magic = -82313077 8 clsn_fil = 0 10 next_seq = 0 11 arch_seq = 0 12 len = 268435456 13 free = 4096 14 clsn = 0 15 clsn_off = 0 16 arch_lsn = 0 17 pemnt_magic = 1250320462 18 fil_id = 1 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: 1371967312 ********************************************************** 1 sig = DMRLOG 2 ver = 7004 3 chksum = 0 4 dbversion = 0x7000a 5 sta = 0 6 n_magic = 35 7 db_magic = 1371967312 8 clsn_fil = 0 10 next_seq = 0 11 arch_seq = 0 12 len = 268435456 13 free = 4096 14 clsn = 0 15 clsn_off = 0 16 arch_lsn = 0 17 pemnt_magic = 1250320462 18 fil_id = 1 19 crc_check = 1 ********************************************************** Do you want to quit and save the change to file (y/n): y Save to file success!
6.使用归档文件还原数据库
[dmdba@dmks backup]$ dmrestore ini_path=/dm_home/dmdbms/data/dameng_for_recover/dm.ini archive_dir=(/dm_home/dmdbms/backup/arch) show_bak_info=2 -bash: syntax error near unexpected token `(' [dmdba@dmks backup]$ dmrestore ini_path=/dm_home/dmdbms/data/dameng_for_recover/dm.ini archive_dir=\(/dm_home/dmdbms/backup/arch\) show_bak_info=2 restore V7.1.6.46-Build(2018.02.08-89107)ENT file dm.key not found, use default license! Continue?[Y/N]:Y try to apply archive log from LSN: 27830642 to LSN: 9223372036854775807. Apply archive log LSN from 27830643 to 27832982, time used:2.811s. restore successfully! restore time used: 3840.401(ms) [dmdba@dmks backup]$
使用归档文件还原数据库归档日志LSN从27830643(因为使用数据库备份文件还原数据库时LSN27830643)为应用到了27832982。
7.启动恢复目标库
[root@dmks init.d]# service DmServicedmrc start Starting DmServicedmrc: [ OK ] [dmdba@dmks dameng_for_recover]$ cat dm.ini | grep PORT_NUM PORT_NUM = 5336 #Port number on which the database server will listen DCP_PORT_NUM = 5237 #Port number on which DCP will listen [dmdba@dmks dameng_for_recover]$ disql sysdba/xxzx7817600@localhost:5336 Server[localhost:5336]:mode is normal, state is open login used time: 19.135(ms) disql V7.1.6.46-Build(2018.02.08-89107)ENT Connected to: DM 7.1.6.46 SQL> select * from t1; LINEID C1 C2 ---------- ----------- ----------- 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 used time: 1.767(ms). Execute id is 4. SQL> select * from t1; LINEID C1 C2 ---------- ----------- ----------- 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 used time: 16.368(ms). Execute id is 4733.
原库
SQL> select * from t1; LINEID C1 C2 ---------- ----------- ----------- 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 used time: 16.368(ms). Execute id is 4733.