--执行灾难恢复
灾难意味着丢失了整个目标数据库、恢复目录数据库、所有当前控制文件、所有联机重做日志文件和参数文件。
灾难恢复包括还原和恢复目标数据库。
备份集的最低要求:
恢复的基本过程:
灾难意味着丢失了整个目标数据库、恢复目录数据库、所有当前控制文件、所有联机重做日志文件和参数文件。
灾难恢复包括还原和恢复目标数据库。
备份集的最低要求:
- 数据文件的备份。
- 相应的归档重做日志文件。
- 至少一个控制文件自动备份。
恢复的基本过程:
- 还原服务器参数文件的自动备份。
- 启动目标数据库实例。
- 从自动备份还原控制文件。
- 装载数据库。
- 还原数据文件。
- 恢复数据文件。
- 使用RESETLOGS选项打开数据库。
--实验
[oracle@ocm1 ~]$ rm -rf /u01/app/oracle/admin/PROD2/
[oracle@ocm1 ~]$ rm -rf /u01/app/oracle/oradata/PROD2/
[oracle@ocm1 ~]$ rm -rf /u01/app/oracle/fast_recovery_area/PROD2/
[oracle@ocm1 ~]$ rm -rf /u01/app/oracle/product/11.2.0/dbhome_1/dbs/spfilePROD2.ora
[oracle@ocm1 ~]$ rm -rf /u01/app/oracle/product/11.2.0/dbhome_1/dbs/orapwPROD2
[oracle@ocm1 ~]$ rm -rf /u01/app/oracle/product/11.2.0/dbhome_1/dbs/initPROD2.ora
--找到类似以下结构的备份集恢复spfile
[oracle@ocm1 ~]$ ls /u01/app/oracle/fast_recovery_area/PROD2/autobackup/2016_12_11/o1_mf_s_930346140_d4to4y0h_.bkp
/u01/app/oracle/fast_recovery_area/PROD2/autobackup/2016_12_11/o1_mf_s_930346140_d4to4y0h_.bkp
RMAN> startup nomount
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/initPROD2.ora'
starting Oracle instance without parameter file for retrieval of spfile
Oracle instance started
Total System Global Area 159019008 bytes
Fixed Size 1343612 bytes
Variable Size 75501444 bytes
Database Buffers 79691776 bytes
Redo Buffers 2482176 bytes
--恢复参数文件
RMAN> restore spfile from '/u01/app/oracle/fast_recovery_area/PROD2/autobackup/2016_12_11/o1_mf_s_930346140_d4to4y0h_.bkp';
Starting restore at 11-DEC-16
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=18 device type=DISK
channel ORA_DISK_1: restoring spfile from AUTOBACKUP /u01/app/oracle/fast_recovery_area/PROD2/autobackup/2016_12_11/o1_mf_s_930346140_d4to4y0h_.bkp
channel ORA_DISK_1: SPFILE restore from AUTOBACKUP complete
Finished restore at 11-DEC-16
RMAN> shutdown abort
Oracle instance shut down
RMAN> exit
Recovery Manager complete.
--查看二进制参数文件,创建其中不存在的目录
[oracle@ocm1 ~]$ strings /u01/app/oracle/product/11.2.0/dbhome_1/dbs/spfilePROD2.ora |grep /u01
PROD2.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
*.audit_file_dest='/u01/app/oracle/admin/PROD2/adump'
*.control_files='/u01/app/oracle/oradata/PROD2/control01
.ctl','/u01/app/oracle/fast_recovery_area/PROD2/control02.ctl'
*.db_recovery_file_dest='/u01/app/oracle/fast_recovery_area'
*.diagnostic_dest='/u01/app/oracle'
[oracle@ocm1 ~]$ mkdir /u01/app/oracle/oradata/PROD2
[oracle@ocm1 ~]$ mkdir /u01/app/oracle/admin/PROD2/adump
[oracle@ocm1 ~]$ strings /u01/app/oracle/product/11.2.0/dbhome_1/dbs/spfilePROD2.ora > /u01/app/oracle/product/11.2.0/dbhome_1/dbs/initPROD2.ora
--再次启动到nomount开始恢复控制文件
RMAN> startup nomount
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/initPROD2.ora'
starting Oracle instance without parameter file for retrieval of spfile
Oracle instance started
Total System Global Area 159019008 bytes
Fixed Size 1343612 bytes
Variable Size 75501444 bytes
Database Buffers 79691776 bytes
Redo Buffers 2482176 bytes
--与参数文件在同一个备份集
RMAN> restore controlfile from '/u01/app/oracle/fast_recovery_area/PROD2/autobackup/2016_12_11/o1_mf_s_930346140_d4to4y0h_.bkp';
Starting restore at 11-DEC-16
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=19 device type=DISK
channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:04
output file name=/u01/app/oracle/oradata/PROD2/control01.ctl
output file name=/u01/app/oracle/fast_recovery_area/PROD2/control02.ctl
Finished restore at 11-DEC-16
--还原数据库
RMAN> alter database mount;
database mounted
released channel: ORA_DISK_1
RMAN> restore database;
Starting restore at 11-DEC-16
Starting implicit crosscheck backup at 11-DEC-16
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=19 device type=DISK
Crosschecked 29 objects
Finished implicit crosscheck backup at 11-DEC-16
Starting implicit crosscheck copy at 11-DEC-16
using channel ORA_DISK_1
Finished implicit crosscheck copy at 11-DEC-16
searching for all files in the recovery area
cataloging files...
cataloging done
List of Cataloged Files
=======================
File Name: /u01/app/oracle/fast_recovery_area/PROD2/autobackup/2016_12_11/o1_mf_s_930346140_d4to4y0h_.bkp
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/app/oracle/oradata/PROD2/system01.dbf
channel ORA_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/PROD2/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/PROD2/undotbs01.dbf
channel ORA_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/PROD2/users01.dbf
channel ORA_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/PROD2/example01.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/PROD2/backupset/2016_12_11/o1_mf_nnndf_TAG20161211T212610_d4tnzm3s_.bkp
channel ORA_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/PROD2/backupset/2016_12_11/o1_mf_nnndf_TAG20161211T212610_d4tnzm3s_.bkp tag=TAG20161211T212610
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:02:42
Finished restore at 11-DEC-16
--恢复数据库
RMAN> recover database;
Starting recover at 11-DEC-16
using channel ORA_DISK_1
starting media recovery
archived log for thread 1 with sequence 34 is already on disk as file /u01/app/oracle/fast_recovery_area/PROD2/archivelog/2016_12_11/o1_mf_1_34_d4to4t8o_.arc
archived log file name=/u01/app/oracle/fast_recovery_area/PROD2/archivelog/2016_12_11/o1_mf_1_34_d4to4t8o_.arc thread=1 sequence=34
unable to find archived log
archived log thread=1 sequence=35
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 12/11/2016 22:10:38
RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 35 and starting SCN of 4299834974
--执行不完全恢复
RMAN> recover database until scn 4299834974;
Starting recover at 11-DEC-16
using channel ORA_DISK_1
starting media recovery
media recovery complete, elapsed time: 00:00:00
Finished recover at 11-DEC-16
RMAN> alter database open resetlogs;
database opened