1.已备份的介质 [root@Oracle02 bak_dir]# tree . ├── 2016_12_28 --控制文件 spfile文件 │ └── o1_mf_s_931822213_d67pn609_.bkp ├── 2016_12_29 --rman备份之后产生的归档日志 │ ├── o1_mf_1_2841_d68fh9bc_.arc │ ├── o1_mf_1_2842_d68o9nf9_.arc │ └── o1_mf_1_2843_d68o9o0j_.arc ├── clinics_archbak_ORCL_20161228_474 --被rman备份的归档日志 ├── clinics_archbak_ORCL_20161228_475 ├── clinics_archbak_ORCL_20161228_479 ├── clinics_fullbak_ORCL_20161228_476_1 --被rman备份的库 ├── clinics_fullbak_ORCL_20161228_477_1 └── clinics_fullbak_ORCL_20161228_478_1 [root@Oracle02 bak_dir]# 注: 1.当前环境只安装了oracle软件,并未安装任何数据库 2.当前目录需同源机备份目录相同 否则rman通过控制文件无法找到备份集2.恢复 2.1 从自动备份中回复spfile [root@Oracle02 clinics]# su - oracle [oracle@Oracle02 ~]$ rman target / nocatalog Recovery Manager: Release 11.2.0.1.0 - Production on Thu Dec 29 11:48:30 2016 Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved. connected to target database (not started) RMAN> startup nomount force; startup failed: ORA-01078: failure in processing system parameters LRM-00109: could not open parameter file '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/initorcl.ora' starting Oracle instance without parameter file for retrieval of spfile Oracle instance started Total System Global Area 158662656 bytes Fixed Size 2211448 bytes Variable Size 88080776 bytes Database Buffers 62914560 bytes Redo Buffers 5455872 bytes RMAN> restore spfile from '/home/oracle/bak_dir/2016_12_28/o1_mf_s_931822213_d67pn609_.bkp'; Starting restore at 29-DEC-16 using channel ORA_DISK_1 channel ORA_DISK_1: restoring spfile from AUTOBACKUP /home/oracle/bak_dir/2016_12_28/o1_mf_s_931822213_d67pn609_.bkp channel ORA_DISK_1: SPFILE restore from AUTOBACKUP complete Finished restore at 29-DEC-16 RMAN> #查看当前恢复出来的spfile [oracle@Oracle02 dbs]$ pwd /u01/app/oracle/product/11.2.0/dbhome_1/dbs [oracle@Oracle02 dbs]$ ls -l 总用量 12 -rw-r--r--. 1 oracle oinstall 2851 5月 15 2009 init.ora -rw-r-----. 1 oracle oinstall 2560 12月 29 11:57 spfileorcl.ora [oracle@Oracle02 dbs]$ more spfileorcl.ora orcl.__java_pool_size=268435456 orcl.__large_pool_size=268435456 orcl.__oracle_base='/opt/oracle'#ORACLE_BASE set from environment orcl.__pga_aggregate_target=12348030976 orcl.__sga_target=18253611008 orcl.__shared_io_pool_size=0 orcl.__shared_pool_size=4563402752 orcl.__streams_pool_size=536870912 *.audit_file_dest='/opt/oracle/admin/orcl/adump' *.audit_trail='db' *.compatible='11.2.0.0.0' *.control_files='/opt/oracle/oradata/orcl/control01.ctl','/opC *.db_block_size=8192 *.db_domain='' *.db_name='orcl' *.db_recovery_file_dest='/opt/oracle/flash_recovery_area' *.db_recovery_file_dest_size=10737418240 *.diagnostic_dest='/opt/oracle' *.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)' *.memory_target=30484201472 *.open_cursors=300 *.processes=150 *.remote_login_passwordfile='EXCLUSIVE' *.undo_tablespace='UNDOTBS1' [oracle@Oracle02 dbs]$ 根据实际情况修改spfile中参数的目录。 [oracle@Oracle02 dbs]$ more spfileorcl.ora orcl.__java_pool_size=26843545 orcl.__large_pool_size=26843545 orcl.__oracle_base='/u01/app/oracle' #ORACLE_BASE set from environment orcl.__pga_aggregate_target=1234803097 orcl.__sga_target=1825361100 orcl.__shared_io_pool_size=0 orcl.__shared_pool_size=456340275 orcl.__streams_pool_size=53687091 *.audit_file_dest='/u01/app/oracle/admin/adump' *.audit_trail='db' *.compatible='11.2.0.0.0' *.control_files='/u01/oradata/orcl/control01.ctl' *.db_block_size=8192 *.db_domain='' *.db_name='orcl' *.db_recovery_file_dest='/u01/fast_recovery_area' *.db_recovery_file_dest_size=107374182 *.diagnostic_dest='/u01/app/oracle' *.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)' *.open_cursors=300 *.processes=150 *.remote_login_passwordfile='EXCLUSIVE' *.undo_tablespace='UNDOTBS1' [oracle@Oracle02 dbs]$ 2.2 从自动备份中恢复controfile #利用恢复的spfile将数据库启动到nomount状态 SQL> startup nomount pfile="/u01/app/oracle/product/11.2.0/dbhome_1/dbs/spfileorcl.ora" ORACLE instance started. Total System Global Area 217157632 bytes Fixed Size 2211928 bytes Variable Size 159387560 bytes Database Buffers 50331648 bytes Redo Buffers 5226496 bytes SQL> #从备份中恢复controfile [oracle@Oracle02 ~]$ rman target / Recovery Manager: Release 11.2.0.1.0 - Production on Thu Dec 29 16:34:04 2016 Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved. connected to target database: ORCL (not mounted) RMAN> RESTORE CONTROLFILE FROM '/home/oracle/bak_dir/2016_12_28/o1_mf_s_931822213_d67pn609_.bkp'; Starting restore at 29-DEC-16 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/orcl/control01.ctl Finished restore at 29-DEC-16 RMAN> 2.3 恢复数据 将数据库切换到mount状态 SQL> alter database mount; Database altered. SQL> 确定源文件目录 SQL> select name from v$controlfile 2 union 3 select name from v$datafile 4 union 5 select member from v$logfile 6 union 7 select name from v$tempfile; NAME -------------------------------------------------------------------------------- /opt/oracle/112/network/admin/clinics_data01.dbf /opt/oracle/oradata/orcl/example01.dbf /opt/oracle/oradata/orcl/redo01.log /opt/oracle/oradata/orcl/redo02.log /opt/oracle/oradata/orcl/redo03.log /opt/oracle/oradata/orcl/sysaux01.dbf /opt/oracle/oradata/orcl/system01.dbf /opt/oracle/oradata/orcl/undotbs01.dbf /opt/oracle/oradata/orcl/users01.dbf /u01/oradata/orcl/control01.ctl /opt/oracle/oradata/orcl/temp01.dbf /opt/oracle/112/network/admin/clinics_temp01.dbf SQL> #更改redo日志目录 SQL> ALTER DATABASE RENAME FILE '/opt/oracle/oradata/orcl/redo01.log' TO '/u01/oradata/orcl/redo01.log'; SQL> ALTER DATABASE RENAME FILE '/opt/oracle/oradata/orcl/redo02.log' TO '/u01/oradata/orcl/redo02.log'; SQL> ALTER DATABASE RENAME FILE '/opt/oracle/oradata/orcl/redo03.log' TO '/u01/oradata/orcl/redo03.log'; SQL> #更改tmp文件目录 tmp文件目录更改需要在数据库open状态下进行,恢复后在处理 #恢复数据文件 RMAN> run { 2> set newname for datafile '/opt/oracle/112/network/admin/clinics_data01.dbf' to '/u01/oradata/orcl/clinics01.dbf'; 3> set newname for datafile '/opt/oracle/oradata/orcl/example01.dbf' to '/u01/oradata/orcl/example01.dbf'; 4> set newname for datafile '/opt/oracle/oradata/orcl/sysaux01.dbf' to '/u01/oradata/orcl/sysaux01.dbf'; 5> set newname for datafile '/opt/oracle/oradata/orcl/system01.dbf' to '/u01/oradata/orcl/system01.dbf'; 6> set newname for datafile '/opt/oracle/oradata/orcl/undotbs01.dbf' to '/u01/oradata/orcl/undotbs01.dbf'; 7> set newname for datafile '/opt/oracle/oradata/orcl/users01.dbf' to '/u01/oradata/orcl/users01.dbf'; 8> restore database; 9> switch datafile all; 10> } executing command: SET NEWNAME executing command: SET NEWNAME executing command: SET NEWNAME executing command: SET NEWNAME executing command: SET NEWNAME executing command: SET NEWNAME Starting restore at 29-DEC-16 Starting implicit crosscheck backup at 29-DEC-16 using target database control file instead of recovery catalog allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=20 device type=DISK Crosschecked 17 objects Finished implicit crosscheck backup at 29-DEC-16 Starting implicit crosscheck copy at 29-DEC-16 using channel ORA_DISK_1 Finished implicit crosscheck copy at 29-DEC-16 searching for all files in the recovery area cataloging files... no files cataloged using channel ORA_DISK_1 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/orcl/system01.dbf channel ORA_DISK_1: restoring datafile 00004 to /u01/oradata/orcl/users01.dbf channel ORA_DISK_1: restoring datafile 00006 to /u01/oradata/orcl/clinics01.dbf channel ORA_DISK_1: reading from backup piece /home/oracle/bak_dir/clinics_fullbak_ORCL_20161228_476_1 channel ORA_DISK_1: piece handle=/home/oracle/bak_dir/clinics_fullbak_ORCL_20161228_476_1 tag=TAG20161228T233003 channel ORA_DISK_1: restored backup piece 1 channel ORA_DISK_1: restore complete, elapsed time: 00:00:35 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/orcl/sysaux01.dbf channel ORA_DISK_1: restoring datafile 00003 to /u01/oradata/orcl/undotbs01.dbf channel ORA_DISK_1: restoring datafile 00005 to /u01/oradata/orcl/example01.dbf channel ORA_DISK_1: reading from backup piece /home/oracle/bak_dir/clinics_fullbak_ORCL_20161228_477_1 channel ORA_DISK_1: piece handle=/home/oracle/bak_dir/clinics_fullbak_ORCL_20161228_477_1 tag=TAG20161228T233003 channel ORA_DISK_1: restored backup piece 1 channel ORA_DISK_1: restore complete, elapsed time: 00:00:25 Finished restore at 29-DEC-16 datafile 1 switched to datafile copy input datafile copy RECID=8 STAMP=931879279 file name=/u01/oradata/orcl/system01.dbf datafile 2 switched to datafile copy input datafile copy RECID=9 STAMP=931879279 file name=/u01/oradata/orcl/sysaux01.dbf datafile 3 switched to datafile copy input datafile copy RECID=10 STAMP=931879279 file name=/u01/oradata/orcl/undotbs01.dbf datafile 4 switched to datafile copy input datafile copy RECID=11 STAMP=931879280 file name=/u01/oradata/orcl/users01.dbf datafile 5 switched to datafile copy input datafile copy RECID=12 STAMP=931879280 file name=/u01/oradata/orcl/example01.dbf datafile 6 switched to datafile copy input datafile copy RECID=13 STAMP=931879280 file name=/u01/oradata/orcl/clinics01.dbf RMAN> #查看回复结果 SQL> conn /as sysdba Connected. SQL> select name from v$datafile; NAME -------------------------------------------------------------------------------- /u01/oradata/orcl/system01.dbf /u01/oradata/orcl/sysaux01.dbf /u01/oradata/orcl/undotbs01.dbf /u01/oradata/orcl/users01.dbf /u01/oradata/orcl/example01.dbf /u01/oradata/orcl/clinics01.dbf SQL> 2.4 执行不完全恢复 #将备份之后产生的归档日志登记到控制文件中 [oracle@Oracle02 dbs]$ rman target / Recovery Manager: Release 11.2.0.1.0 - Production on Thu Dec 29 15:29:47 2016 Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved. connected to target database: ORCL (DBID=1435659836, not open) RMAN> catalog archivelog '/home/oracle/bak_dir/2016_12_29/o1_mf_1_2841_d68fh9bc_.arc'; using target database control file instead of recovery catalog cataloged archived log archived log file name=/home/oracle/bak_dir/2016_12_29/o1_mf_1_2841_d68fh9bc_.arc RECID=803 STAMP=931879849 RMAN> catalog archivelog '/home/oracle/bak_dir/2016_12_29/o1_mf_1_2842_d68o9nf9_.arc'; cataloged archived log archived log file name=/home/oracle/bak_dir/2016_12_29/o1_mf_1_2842_d68o9nf9_.arc RECID=804 STAMP=931879869 RMAN> catalog archivelog '/home/oracle/bak_dir/2016_12_29/o1_mf_1_2843_d68o9o0j_.arc'; cataloged archived log archived log file name=/home/oracle/bak_dir/2016_12_29/o1_mf_1_2843_d68o9o0j_.arc RECID=805 STAMP=931879897 RMAN> #查看登记后的归档日志 SQL> select thread#,sequence#,name,next_change# from v$archived_log; THREAD# SEQUENCE# NAME NEXT_CHANGE# ---------- ---------- ------------------------------------------------------------ ------------ 1 2840 39240733 1 2841 /home/oracle/bak_dir/2016_12_29/o1_mf_1_2841_d68fh9bc_.arc 39270727 1 2842 /home/oracle/bak_dir/2016_12_29/o1_mf_1_2842_d68o9nf9_.arc 39282742 1 2843 /home/oracle/bak_dir/2016_12_29/o1_mf_1_2843_d68o9o0j_.arc 39284949 SQL> #根据归档日志视图v$archived_log.SEQUENCE#,在RMAN命令行下执行恢复 RMAN> run{ 2> set until sequence 2844 thread 1; 3> recover database; 4> } executing command: SET until clause Starting recover at 29-DEC-16 using channel ORA_DISK_1 starting media recovery archived log for thread 1 with sequence 2841 is already on disk as file /home/oracle/bak_dir/2016_12_29/o1_mf_1_2841_d68fh9bc_.arc archived log for thread 1 with sequence 2842 is already on disk as file /home/oracle/bak_dir/2016_12_29/o1_mf_1_2842_d68o9nf9_.arc archived log for thread 1 with sequence 2843 is already on disk as file /home/oracle/bak_dir/2016_12_29/o1_mf_1_2843_d68o9o0j_.arc channel ORA_DISK_1: starting archived log restore to default destination channel ORA_DISK_1: restoring archived log archived log thread=1 sequence=2840 channel ORA_DISK_1: reading from backup piece /home/oracle/bak_dir/clinics_archbak_ORCL_20161228_479 channel ORA_DISK_1: piece handle=/home/oracle/bak_dir/clinics_archbak_ORCL_20161228_479 tag=TAG20161228T233012 channel ORA_DISK_1: restored backup piece 1 channel ORA_DISK_1: restore complete, elapsed time: 00:00:01 archived log file name=/u01/fast_recovery_area/ORCL/archivelog/2016_12_29/o1_mf_1_2840_d69m35bo_.arc thread=1 sequence=2840 channel default: deleting archived log(s) archived log file name=/u01/fast_recovery_area/ORCL/archivelog/2016_12_29/o1_mf_1_2840_d69m35bo_.arc RECID=806 STAMP=931884133 archived log file name=/home/oracle/bak_dir/2016_12_29/o1_mf_1_2841_d68fh9bc_.arc thread=1 sequence=2841 archived log file name=/home/oracle/bak_dir/2016_12_29/o1_mf_1_2842_d68o9nf9_.arc thread=1 sequence=2842 archived log file name=/home/oracle/bak_dir/2016_12_29/o1_mf_1_2843_d68o9o0j_.arc thread=1 sequence=2843 media recovery complete, elapsed time: 00:00:10 Finished recover at 29-DEC-16 RMAN> 2.5 以resetlogs方式打开数据库 [oracle@Oracle02 ~]$ rman target / Recovery Manager: Release 11.2.0.1.0 - Production on Thu Dec 29 17:04:31 2016 Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved. connected to target database: ORCL (DBID=1435659836, not open) RMAN> sql'alter database open resetlogs'; using target database control file instead of recovery catalog sql statement: alter database open resetlogs RMAN> 3.恢复库的后续处理 3.1查看各个文件目录 SQL> select name from v$controlfile 2 union 3 select name from v$datafile 4 union 5 select member from v$logfile 6 union 7 select name from v$tempfile; NAME ------------------------------------------------------------ /opt/oracle/112/network/admin/clinics_temp01.dbf /opt/oracle/oradata/orcl/temp01.dbf /u01/oradata/orcl/clinics01.dbf /u01/oradata/orcl/control01.ctl /u01/oradata/orcl/example01.dbf /u01/oradata/orcl/redo01.log /u01/oradata/orcl/redo02.log /u01/oradata/orcl/redo03.log /u01/oradata/orcl/sysaux01.dbf /u01/oradata/orcl/system01.dbf /u01/oradata/orcl/undotbs01.dbf NAME ------------------------------------------------------------ /u01/oradata/orcl/users01.dbf SQL> select ts#,bytes/1024/1024,name from v$tempfile; TS# BYTES/1024/1024 NAME ---------- --------------- ------------------------------------------------------------ 3 0 /opt/oracle/oradata/orcl/temp01.dbf 7 0 /opt/oracle/112/network/admin/clinics_temp01.dbf SQL> select ts#,name from v$tablespace where ts# in (3,7); TS# NAME ---------- ------------------------------------------------------------ 3 TEMP 7 CLINICS_TEMP SQL> 添加新临时文件 SQL> alter tablespace temp add tempfile '/u01/oradata/orcl/temp01.dbf' size 50M; SQL> alter tablespace CLINICS_TEMP add tempfile '/u01/oradata/orcl/clinics_temp01.dbf' size 50M; 删除历史临时文件 SQL> alter database tempfile '/opt/oracle/oradata/orcl/temp01.dbf' drop; SQL> alter database tempfile '/opt/oracle/112/network/admin/clinics_temp01.dbf' drop; 3.2创建spfile SQL> create spfile from memory; File created. SQL> OK鸟!