使用dmrestore工具利用归档日志还原
利用备份文件,DM可以将数据库、表空间和表还原到备份时的状态。但用户可能更希望将数据还原到最新的状态。这点不用担心,事实上系统足够智能,在利用备份完成还原后,会去归档目录搜索归档日志,并分析归档日志是否与还原的数据库匹配,若存在匹配的归档日志,则系统会重做这部分日志,将数据库还原到最新的状态;若没有可用的归档日志,则只能还原到备份时的状态。
利用指定归档目录下归档日志还原数据库jydm
1.对数据库jydm执行完全备份
SQL> backup database full to full_bak_for_arch_restor bakfile '/dm_home/dmdba/dmdbms/backup/full_bak_for_arch_restor.bak'; executed successfully used time: 00:00:25.113. Execute id is 977781. SQL> select * from t1; LINEID C1 C2 ---------- ----------- ----------- 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 used time: 0.744(ms). Execute id is 977816. SQL> insert into t1 values(6,6); affect rows 1 used time: 49.901(ms). Execute id is 977842. SQL> commit; executed successfully used time: 21.340(ms). Execute id is 977845. SQL> select * from t1; LINEID C1 C2 ---------- ----------- ----------- 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 6 6 6 6 rows got used time: 25.205(ms). Execute id is 977846.
2.异常终止数据库实例
[root@shard1 oracle]# ps -ef | grep dmserver dmdba 3129 1 4 19:51 ? 00:00:02 /dm_home/dmdba/dmdbms/bin/dmserver /dm_home/dmdba/dmdbms/data/jydm/dm.ini -noconsole root 3371 32007 0 19:52 pts/9 00:00:00 grep --color=auto dmserver [root@shard1 oracle]# kill -9 3129 [root@shard1 oracle]# ps -ef | grep dmserver root 3532 32007 0 19:53 pts/9 00:00:00 grep --color=auto dmserver
3.执行还原
[dmdba@shard1 backup]$ dmrestore ini_path=/dm_home/dmdba/dmdbms/data/jydm/dm.ini file=/dm_home/dmdba/dmdbms/backup/full_bak_for_arch_restor.bak archive_dir=/dm_home/dmdba/dmdbms/data/arch 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: 1371967312 backup pemnt magic: 1250320462 backup name: FULL_BAK_FOR_ARCH_RESTOR backup type: full backup level: online 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-21 19:52:09 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: 1595332328 crc_check: TRUE parallel type: 0 parallel info len: 0 backup db fil num: 9 archive flag: 1 backup with log: Yes before backup LSN: 30040400 after backup LSN: 30040406 $bak_seq |$file_path |$size(K) |$used(K) 1|/dm_home/dmdba/dmdbms/backup/full_bak_for_arch_restor.bak| 393216.00| 362036.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| 10887168|/dm_home/dmdba/dmdbms/data/jydm/ROLL.DBF | 3|DBF |MAIN |ONLINE | 276480| 1| 17696768| 240287744|/dm_home/dmdba/dmdbms/data/jydm/MAIN.DBF | 4|DBF |BOOKSHOP |ONLINE | 153600| 1| 257984512| 933888|/dm_home/dmdba/dmdbms/data/jydm/BOOKSHOP.DBF | 5|DBF |DMHR |ONLINE | 131072| 1| 258918400| 425984|/dm_home/dmdba/dmdbms/data/jydm/DMHR.DBF | 6|DBF |USERS |ONLINE | 51200| 1| 259344384| 1105920|/dm_home/dmdba/dmdbms/data/jydm/users01.dbf | 7|DBF |SYSAUX |ONLINE | 179200| 1| 260450304| 110256128|/dm_home/dmdba/dmdbms/data/jydm/SYSAWR.DBF | 8|DBF |FG_PERSON |ONLINE | 131072| 1| 370706432| 16384|/dm_home/dmdba/dmdbms/data/jydm/FG_PERSON.DBF | 9|LOG |ARCHLOG |ONLINE | 0| 1| 370722816| 2048| | Continue?[Y/N]:Y can't find useable archive file when search assigned archive directory restore bak_file: /dm_home/dmdba/dmdbms/backup/full_bak_for_arch_restor.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: 1329 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: 29332 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) redo tmp arch file: /dm_home/dmdba/dmdbms/backup/RES_TMP_ARCH_20200721195311007_0.log, rpages: 16 end restore database data files. Apply archive log LSN from 30040407 to 30040406, time used:0.000s. restore finished, code = 0! restore successfully! restore time used: 8601.260(ms)
4.验证数据
SQL> select * from t1; LINEID C1 C2 ---------- ----------- ----------- 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 6 6 6 6 rows got used time: 0.454(ms). Execute id is 97.