说明:相应版本oracle 11g,因为没使用克隆所以新库的db_name与dbid与原库是一样的,它只是对RMAN备份进行异机恢复
- 备份原库
在这里我用 0 级和 1 级备份了下 DB。
$ ls
arch_0pm6qt8q_1_1_20110309 dave_lev0_0jm6qt77_1_1_20110309 dave_lev1_0um6qtcq_
1_1_20110309
arch_0qm6qt8q_1_1_20110309 dave_lev0_0km6qt77_1_1_20110309 dave_lev1_0vm6qtcq_
1_1_20110309
arch_13m6qtda_1_1_20110309 dave_lev0_0lm6qt77_1_1_20110309 dave_lev1_11m6qtd7_
1_1_20110309
arch_14m6qtda_1_1_20110309 dave_lev0_0nm6qt7c_1_1_20110309 dave_spfile_16m6qtd
e_1_1_20110309
ctl_file_15m6qtdc_1_1_20110309 dave_lev1_0tm6qtcq_1_1_20110309
将备份 copy 到辅助库的相同位置(因为使用的是原库的控制文件,它记录着RMAN备份的元信息)
- 新库准备工作
1)创建口令文件
$ orapwd file=?/dbs/orapwdave password=oracle
2)创建相关的目录
$ mkdir oradata
3)创建初始化参数
$ export ORACLE_SID=dave
$ rman target /
RMAN> restore spfile to pfile '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/initdave.ora' from '/u01/backup/dave_spfile_16m6qtde_1_1_20110309'; ---控制文件备份要手动指定
Starting restore at 11-MAR-11
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=19 device type=DISK
channel ORA_DISK_1: restoring spfile from AUTOBACKUP
/u01/backup/dave_spfile_16m6qtde_1_1_20110309
channel ORA_DISK_1: SPFILE restore from AUTOBACKUP complete
Finished restore at 11-MAR-11
也可以更改下controlfile的位置(数据文件及日志文件位置不是存在pfile中而是控制文件中,所以这里改不了):
*.control_files='/u01/oradata/control01.ctl','/u01/oradata/control02.ctl','/u01/oradata/cont
rol03.ctl'
*.db_name='dave'
4)用 spfile将新库启动到nomout状态
SQL> create spfile from pfile
SQL> startup nomount
5)恢复控制文件
RMAN> restore controlfile from '/u01/backup/ctl_file_15m6qtdc_1_1_20110309';
Starting restore at 11-MAR-11
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=20 device type=DISK
channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/u01/oradata/control01.ctl
output file name=/u01/oradata/control02.ctl
output file name=/u01/oradata/control03.ctl
Finished restore at 11-MAR-11
restore 的时候需要控制文件,控制文件恢复的位置,是我们在 pfile 中的control_files 参数控制的
6)restore 数据库
RMAN> alter database mount;
这里演示恢复到不同目录下(如果是相同目录直接restore即可)
SQL> select file_id,file_name from dba_data_files;
FILE_ID FILE_NAME
---------- -------------------------------------------
4 /u01/app/oracle/oradata/dave/users01.dbf
3 /u01/app/oracle/oradata/dave/undotbs01.dbf
2 /u01/app/oracle/oradata/dave/sysaux01.dbf
1 /u01/app/oracle/oradata/dave/system01.dbf
SQL> select file_id,file_name from dba_temp_files;
FILE_ID FILE_NAME
---------- ------------------------------------------
1 /u01/app/oracle/oradata/dave/temp01.dbf
RMAN> run
{
set newname for datafile 1 to "/u01/oradata/system01.dbf";
set newname for datafile 2 to "/u01/oradata/sysaux01.dbf";
set newname for datafile 3 to "/u01/oradata/undotbs01.dbf";
set newname for datafile 4 to "/u01/oradata/users01.dbf";
set newname for tempfile 1 to "/u01/oradata/temp01.dbf";
restore database;
switch datafile all;
switch tempfile all;
}
executing command: SET NEWNAME
released channel: ORA_DISK_1
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
Starting restore at 11-MAR-11
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=20 device type=DISK
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00003 to /u01/oradata/undotbs01.dbf
channel ORA_DISK_1: reading from backup piece /u01/backup/dave_lev0_0lm6qt77_1_1_20110309
channel ORA_DISK_1: piece handle=/u01/backup/dave_lev0_0lm6qt77_1_1_20110309 tag=DAVE_LEV0
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:03
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00004 to /u01/oradata/users01.dbf
channel ORA_DISK_1: reading from backup piece /u01/backup/dave_lev0_0nm6qt7c_1_1_20110309
channel ORA_DISK_1: piece handle=/u01/backup/dave_lev0_0nm6qt7c_1_1_20110309 tag=DAVE_LEV0
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00002 to /u01/oradata/sysaux01.dbf
channel ORA_DISK_1: reading from backup piece /u01/backup/dave_lev0_0km6qt77_1_1_20110309
channel ORA_DISK_1: piece handle=/u01/backup/dave_lev0_0km6qt77_1_1_20110309 tag=DAVE_LEV0
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:15
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to /u01/oradata/system01.dbf
channel ORA_DISK_1: reading from backup piece /u01/backup/dave_lev0_0jm6qt77_1_1_20110309
channel ORA_DISK_1: piece handle=/u01/backup/dave_lev0_0jm6qt77_1_1_20110309 tag=DAVE_LEV0
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:25
Finished restore at 11-MAR-11
datafile 1 switched to datafile copy
input datafile copy RECID=5 STAMP=745522150 file name=/u01/oradata/system01.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=6 STAMP=745522150 file name=/u01/oradata/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=7 STAMP=745522150 file name=/u01/oradata/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=8 STAMP=745522150 file name=/u01/oradata/users01.dbf
7)recover DB
RMAN> recover database;
Starting recover at 11-MAR-11
using channel ORA_DISK_1
channel ORA_DISK_1: starting incremental datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
destination for restore of datafile 00001: /u01/oradata/system01.dbf
channel ORA_DISK_1: reading from backup piece /u01/backup/dave_lev1_0tm6qtcq_1_1_20110309
channel ORA_DISK_1: piece handle=/u01/backup/dave_lev1_0tm6qtcq_1_1_20110309 tag=DAVE_LEV1
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
channel ORA_DISK_1: starting incremental datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
destination for restore of datafile 00002: /u01/oradata/sysaux01.dbf
channel ORA_DISK_1: reading from backup piece /u01/backup/dave_lev1_0um6qtcq_1_1_20110309
channel ORA_DISK_1: piece handle=/u01/backup/dave_lev1_0um6qtcq_1_1_20110309 tag=DAVE_LEV1
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:02
channel ORA_DISK_1: starting incremental datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
destination for restore of datafile 00003: /u01/oradata/undotbs01.dbf
channel ORA_DISK_1: reading from backup piece /u01/backup/dave_lev1_0vm6qtcq_1_1_20110309
channel ORA_DISK_1: piece handle=/u01/backup/dave_lev1_0vm6qtcq_1_1_20110309 tag=DAVE_LEV1
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
channel ORA_DISK_1: starting incremental datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
destination for restore of datafile 00004: /u01/oradata/users01.dbf
channel ORA_DISK_1: reading from backup piece /u01/backup/dave_lev1_11m6qtd7_1_1_20110309
channel ORA_DISK_1: piece handle=/u01/backup/dave_lev1_11m6qtd7_1_1_20110309 tag=DAVE_LEV1
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
starting media recovery
channel ORA_DISK_1: starting archived log restore to default destination
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=7
channel ORA_DISK_1: reading from backup piece /u01/backup/arch_13m6qtda_1_1_20110309
channel ORA_DISK_1: piece handle=/u01/backup/arch_13m6qtda_1_1_20110309 tag=ARC_BAK
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
archived log file name=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_7_745352047.dbf
thread=1 sequence=7
channel ORA_DISK_1: starting archived log restore to default destination
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=8
channel ORA_DISK_1: reading from backup piece /u01/backup/arch_14m6qtda_1_1_20110309
channel ORA_DISK_1: piece handle=/u01/backup/arch_14m6qtda_1_1_20110309 tag=ARC_BAK
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
archived log file name=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_8_745352047.dbf
thread=1 sequence=8
unable to find archived log
archived log thread=1 sequence=9
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 03/11/2011 17:32:00
RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 9 and
starting SCN of 823627
之后会报一个错误:
RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 9 and
starting SCN of 823627
这里是提醒恢复到一个未知的scn号。在alter database mount之后,通过set until scn或者set until
time 命令设置恢复到的 scn 号或时间
8)用open resetlogs打开数据库
SQL> alter database open resetlogs;
这个新库的db_name及dbid为原库值
- 处理online redo log的位置更改(如果需要) ----这个过程是可以在mount下完成的!!
SQL> select group#,bytes/1024/1024||'M',status from v$log;
GROUP# BYTES/1024/1024||'M' STATUS
---------- ----------------------------------------- ----------------
1 50M INACTIVE
2 50M CURRENT
3 50M UNUSED
SQL> select group#,member from v$logfile;
GROUP# MEMBER
---------------------------------------------------------------------
3 /u01/app/oracle/oradata/dave/redo03.log
2 /u01/app/oracle/oradata/dave/redo02.log
1 /u01/app/oracle/oradata/dave/redo01.log
oracle 至少有 2 组 redo log。 所以我们可以将已经完成归档的 redo drop 掉, 重新创建。
SQL> alter database drop logfile group 3;
SQL> alter database add logfile group 3 ('/u01/oradata/redo03.log') size 50m;
SQL> alter system switch logfile;
SQL> select group#,bytes/1024/1024||'M',status from v$log;
GROUP# BYTES/1024/1024||'M' STATUS
---------- ----------------------------------------- ----------------
1 50M INACTIVE
2 50M ACTIVE
3 50M CURRENT
SQL> alter database drop logfile group 1;
SQL> alter database add logfile group 1 ('/u01/oradata/redo01.log') size 50m;
SQL> alter system switch logfile;
SQL> alter database drop logfile group 2;
SQL> alter database add logfile group 2 ('/u01/oradata/redo02.log') size 50m;
SQL> select group#,member from v$logfile;
GROUP# MEMBER
---------------------------------------------------------------------
3 /u01/oradata/redo03.log
2 /u01/oradata/redo02.log
1 /u01/oradata/redo01.log