DMRMAN对数据库执行指定映射文件还原
指定映射文件还原,还原后的数据文件默认地生成到还原目标库的路径下,如果用户想生成数据文件到特定的路径,就需要指定映射文件参数来实现。
映射文件(mappedfile)用于指定存放还原目标路径,即备份集里面的数据文件的路径。可以手动修改自动生成的映射文件。当参数BACKUPSET和MAPPED FILE指定的路径不一致时,以MAPPED FILE中指定的路径为主。映射文件可用于库级脱机还原和表空间还原。
使用DUMP命令可以将指定备份集还原目标信息生成到目标映射文件中,该文件可被重新编辑后,用于数据库的还原过程。语法如下:
DUMP BACKUPSET '< 备份集目录>' [DEVICE TYPE DISK|TAPE [PARMS '介质参数']] [DATABASE ''] MAPPED FILE '< 映射文件>';
BACKUPSET:待生成映射文件的备份集目录。
DEVICE TYPE:指存储备份集的介质类型,支持DISK和TAPE,默认为DISK。
PARMS:介质参数,供第三方存储介质(TAPE类型)管理使用。
DATABASE:指定目标还原库的dm.ini文件路径。
MAPPED FILE:生成映射文件路径。若指定DATABASE参数,则生成内容调整为与指定数据库相适应的数据文件目标还原路径;否则,仅将备份集中备份时记录的路径输出。
下面以脱机备份还原为例说明使用映射文件还原的具体步骤。
1) 启动RMAN,脱机备份数据库。
RMAN> backup database '/dm_home/dmdba/dmdbms/data/jydm/dm.ini' backupset '/dm_home/dmdba/dmdbms/data/jydm/bak/db_bak_for_map_01'; backup database '/dm_home/dmdba/dmdbms/data/jydm/dm.ini' backupset '/dm_home/dmdba/dmdbms/data/jydm/bak/db_bak_for_map_01'; file dm.key not found, use default license! checking if the database under system path [/dm_home/dmdba/dmdbms/data/jydm] is running...[4]. checking if the database under system path [/dm_home/dmdba/dmdbms/data/jydm] is running...[3]. checking if the database under system path [/dm_home/dmdba/dmdbms/data/jydm] is running...[2]. checking if the database under system path [/dm_home/dmdba/dmdbms/data/jydm] is running...[1]. checking if the database under system path [/dm_home/dmdba/dmdbms/data/jydm] is running...[0]. checking if the database under system path [/dm_home/dmdba/dmdbms/data/jydm] is running, write dmrman info. EP[0] max_lsn: 20379861 BACKUP DATABASE [jydm], execute...... CMD CHECK LSN...... BACKUP DATABASE [jydm], collect dbf...... CMD CHECK ...... DBF BACKUP SUBS...... total 1 packages processed... total 7 packages processed... total 13 packages processed... total 14 packages processed... total 15 packages processed... total 16 packages processed... total 22 packages processed... total 23 packages processed... DBF BACKUP MAIN...... BACKUPSET [/dm_home/dmdba/dmdbms/data/jydm/bak/db_bak_for_map_01] END, CODE [0]...... META GENERATING...... total 27 packages processed... total 27 packages processed! CMD END.CODE:[0] backup successfully! time used: 16318.143(ms) [dmdba@shard1 bak]$ scp -r db_bak_for_map_01/ dmdba@10.138.130.187:/dm_home/dmdbms/backup/ dmdba@10.138.130.187's password: db_bak_for_map_01.bak 100% 210MB 104.9MB/s 00:02 db_bak_for_map_01.meta 100% 85KB 84.5KB/s 00:00 [dmdba@shard1 bak]$
2) 生成映射文件map_file_01.txt至/dm_home/dmdbms/backup目录。此处指定生成映射文件中的数据文件路径与数据库/dm_home/dmdbms/data/dameng_for_recover/中的数据文件一致。若不指定,与备份集中的源数据库的数据文件路径一致。
RMAN> dump backupset '/dm_home/dmdbms/backup/db_bak_for_map_01' database '/dm_home/dmdbms/data/dameng_for_recover/dm.ini' mapped file '/dm_home/dmdbms/backup/map_file_01.txt'; dump backupset '/dm_home/dmdbms/backup/db_bak_for_map_01' database '/dm_home/dmdbms/data/dameng_for_recover/dm.ini' mapped file '/dm_home/dmdbms/backup/map_file_01.txt'; dump mapped file successfully. time used: 11.093(ms)
生成的映射文件内容如下:
[dmdba@dmks backup]$ cat map_file_01.txt /**************************************************************/ /*** Delete the unnecessary modified groups **/ /*** Modify the data_path or mirror_path only in one group **/ /**************************************************************/ /**=============================================================**/ /*[jydm_SYSTEM_FIL_0]*/ fil_id = 0 ts_id = 0 ts_name = SYSTEM data_path = /dm_home/dmdbms/data/dameng_for_recover/SYSTEM.DBF mirror_path = /**=============================================================**/ /*[jydm_ROLL_FIL_0]*/ fil_id = 0 ts_id = 1 ts_name = ROLL data_path = /dm_home/dmdbms/data/dameng_for_recover/ROLL.DBF mirror_path = /**=============================================================**/ /*[jydm_MAIN_FIL_0]*/ fil_id = 0 ts_id = 4 ts_name = MAIN data_path = /dm_home/dmdbms/data/dameng_for_recover/MAIN.DBF mirror_path = /**=============================================================**/ /*[jydm_BOOKSHOP_FIL_0]*/ fil_id = 0 ts_id = 5 ts_name = BOOKSHOP data_path = /dm_home/dmdbms/data/dameng_for_recover/BOOKSHOP.DBF mirror_path = /**=============================================================**/ /*[jydm_DMHR_FIL_0]*/ fil_id = 0 ts_id = 6 ts_name = DMHR data_path = /dm_home/dmdbms/data/dameng_for_recover/DMHR.DBF mirror_path = /**=============================================================**/ /*[jydm_USERS_FIL_0]*/ fil_id = 0 ts_id = 7 ts_name = USERS data_path = /dm_home/dmdbms/data/dameng_for_recover/users01.dbf mirror_path = /**=============================================================**/ /*[jydm_SYSAUX_FIL_0]*/ fil_id = 0 ts_id = 9 ts_name = SYSAUX data_path = /dm_home/dmdbms/data/dameng_for_recover/SYSAWR.DBF mirror_path = /**=============================================================**/ /*[jydm_FG_PERSON_FIL_0]*/ fil_id = 0 ts_id = 10 ts_name = FG_PERSON data_path = /dm_home/dmdbms/data/dameng_for_recover/FG_PERSON.DBF mirror_path = /***************************** END ****************************/
如果需要恢复数据文件或镜像文件到指定路径,可手动编辑映射文件中表空间对应的data_path属性。例如,要还原USERS表空间中的数据文件users01.dbf到/home/dmdba/路径下,修改组jydm_USERS_FIL_0的内容如下:
/*[jydm_USERS_FIL_0]*/ fil_id = 0 ts_id = 7 ts_name = USERS data_path = /home/dmdba/users01.dbf mirror_path =
3) 指定映射文件还原。还原前可选择对备份文件进行校验。
RMAN> restore database '/dm_home/dmdbms/data/dameng_for_recover/dm.ini' from backupset '/dm_home/dmdbms/backup/db_bak_for_map_01' mapped file '/dm_home/dmdbms/backup/map_file_01.txt'; restore database '/dm_home/dmdbms/data/dameng_for_recover/dm.ini' from backupset '/dm_home/dmdbms/backup/db_bak_for_map_01' mapped file '/dm_home/dmdbms/backup/map_file_01.txt'; checking if the database under system path [/dm_home/dmdbms/data/dameng_for_recover] is running...[4]. checking if the database under system path [/dm_home/dmdbms/data/dameng_for_recover] is running...[3]. checking if the database under system path [/dm_home/dmdbms/data/dameng_for_recover] is running...[2]. checking if the database under system path [/dm_home/dmdbms/data/dameng_for_recover] is running...[1]. checking if the database under system path [/dm_home/dmdbms/data/dameng_for_recover] is running...[0]. checking if the database under system path [/dm_home/dmdbms/data/dameng_for_recover] is running, write dmrman info. RESTORE DATABASE CHECK...... RESTORE DATABASE , dbf collect...... RESTORE DATABASE , dbf refresh ...... RESTORE BACKUPSET [/dm_home/dmdbms/backup/db_bak_for_map_01] START...... total 23 packages processed... RESTORE DATABASE , UPDATE ctl file...... RESTORE DATABASE , REBUILD key file...... RESTORE DATABASE , CHECK db info...... RESTORE DATABASE , UPDATE db info...... total 25 packages processed! CMD END.CODE:[0] restore successfully. time used: 49988.649(ms)
4)恢复数据库
RMAN> recover database '/dm_home/dmdbms/data/dameng_for_recover/dm.ini' from backupset '/dm_home/dmdbms/backup/db_bak_for_map_01'; recover database '/dm_home/dmdbms/data/dameng_for_recover/dm.ini' from backupset '/dm_home/dmdbms/backup/db_bak_for_map_01'; checking if the database under system path [/dm_home/dmdbms/data/dameng_for_recover] is running...[4]. checking if the database under system path [/dm_home/dmdbms/data/dameng_for_recover] is running...[3]. checking if the database under system path [/dm_home/dmdbms/data/dameng_for_recover] is running...[2]. checking if the database under system path [/dm_home/dmdbms/data/dameng_for_recover] is running...[1]. checking if the database under system path [/dm_home/dmdbms/data/dameng_for_recover] is running...[0]. checking if the database under system path [/dm_home/dmdbms/data/dameng_for_recover] is running, write dmrman info. EP[0] max_lsn: 20379861 RESTORE RLOG CHECK...... CMD END.CODE:[603],DESC:[no log generates while the backupset [/dm_home/dmdbms/backup/db_bak_for_map_01] created] no log generates while the backupset [/dm_home/dmdbms/backup/db_bak_for_map_01] created recover successfully! time used: 7026.527(ms)
5)检验数据文件还原的位置
[root@dmks init.d]# service DmServicedmrc start Starting DmServicedmrc: [ OK ] SQL> select * from v$datafile; LINEID GROUP_ID ID PATH CLIENT_PATH CREATE_TIME STATUS$ RW_STATUS LAST_CKPT_TIME MODIFY_TIME MODIFY_TRX TOTAL_SIZE FREE_SIZE FREE_PAGE_NO PAGES_READ PAGES_WRITE PAGE_SIZE READ_REQUEST WRITE_REQUEST AUTO_EXTEND MAX_SIZE NEXT_SIZE MIRROR_PATH ---------- ----------- ----------- ----------------------------------------------------- ----------------------- --------------------------- ----------- ----------- --------------------------- --------------------------- -------------------- -------------------- -------------------- -------------------- -------------------- -------------------- ----------- ------------ ------------- ----------- ----------- ----------- ----------- 1 0 0 /dm_home/dmdbms/data/dameng_for_recover/SYSTEM.DBF SYSTEM.DBF 2020-06-18 17:02:59 1 2 2020-06-18 17:13:08 2020-06-18 17:02:59 0 2944 2117 1840 368 3 8192 368 3 1 16777215 0 NULL 2 1 0 /dm_home/dmdbms/data/dameng_for_recover/ROLL.DBF ROLL.DBF 2020-06-18 17:02:59 1 2 2020-06-18 17:13:08 2020-06-18 17:02:59 0 25472 24138 24400 32 1289 8192 32 1289 1 16777215 0 NULL 3 3 0 /dm_home/dmdbms/data/dameng_for_recover/TEMP.DBF TEMP.DBF 2020-06-18 17:08:08 1 2 2020-06-18 17:13:08 2020-06-18 17:08:08 0 1280 1272 32 0 0 8192 0 0 1 16777215 0 NULL 4 4 0 /dm_home/dmdbms/data/dameng_for_recover/MAIN.DBF MAIN.DBF 2020-06-18 17:02:59 1 2 2020-06-18 17:13:08 2020-06-18 17:02:59 0 24064 17781 22944 1607 0 8192 1607 0 1 16777215 0 NULL 5 5 0 /dm_home/dmdbms/data/dameng_for_recover/BOOKSHOP.DBF BOOKSHOP.DBF 2020-06-18 17:02:59 1 2 2020-06-18 17:13:08 2020-06-18 17:02:59 0 19200 19079 864 43 0 8192 43 0 1 16777215 0 NULL 6 6 0 /dm_home/dmdbms/data/dameng_for_recover/DMHR.DBF DMHR.DBF 2020-06-18 17:02:59 1 2 2020-06-18 17:13:08 2020-06-18 17:02:59 0 16384 16325 304 35 0 8192 35 0 1 16777215 0 NULL 7 7 0 /home/dmdba/users01.dbf /home/dmdba/users01.dbf 2020-06-18 17:02:59 1 2 2020-06-18 17:13:08 2020-06-18 17:02:59 0 6400 6258 3392 57 0 8192 57 0 1 16777215 0 NULL 8 9 0 /dm_home/dmdbms/data/dameng_for_recover/SYSAWR.DBF SYSAWR.DBF 2020-06-18 17:02:59 1 2 2020-06-18 17:13:08 2020-06-18 17:02:59 0 21760 2834 20592 529 0 8192 529 0 1 10240 0 NULL 9 10 0 /dm_home/dmdbms/data/dameng_for_recover/FG_PERSON.DBF FG_PERSON.DBF 2020-06-18 17:02:59 1 2 2020-06-18 17:13:08 2020-06-18 17:02:59 0 16384 16375 32 1 0 8192 1 0 1 16777215 0 NULL 9 rows got used time: 8.354(ms). Execute id is 10.