This article mainly describes the Rman recovery scheme and Oracle Machine recovery, the need for friends can refer to the following
Note:
The premise of ① recovery is that it is ready for backup
② Full Recovery database is a database that is experiencing a failure to recover without losing any data that has been submitted
Incomplete recovery of the database is a failure of the database and the recovery of some of the data is lost during recovery
③ need to set environment variables under Linux, that is, the instance name of the ORACLE database that needs to be restored: Export ORACLE_SID=ORCL
④ When you start a database with resetlogs, you should make a full backup of the database
I. Recovery programme
1. Loss of data files for full recovery
Copy the code code as follows:
Rman>startup Mount;
Rman>restore database;
Rman>recover database;
Rman>sql ' ALTER DATABASE open ';
2, lost redo log file, do not complete recovery
Copy the code code as follows:
Sql>startup Mount;
Sql>recover database until cancel;
Sql>alter database open resetlogs;
3. Loss of data files, control files and redo log files for incomplete recovery
Copy the code code as follows:
Rman>startup Nomount;
Rman>restore controfile from Autobackup;
Rman>alter database Mount;
Rman>restore database;
Sql>recover database using Backup controlfile until cancel;
Sql>alter database open resetlogs;
4, loss of initialization files, control file data files and redo log files for incomplete recovery
Copy the code code as follows:
Sql>startup nomount pfile= ' D:\oracle\product\10.2.0\db_1\admin\orcl\pfile\init.ora.27201414210 '; #pfile的路径
Rman>restore SPFile from Autobackup;
Sql>shutdown immediate;
Sql>startup Nomount;
Rman>restore controlfile from Autobackup;
Rman>alter database Mount;
Rman>restore database;
Sql>recover database using Backup controlfile until cancel;
Sql>alter database open resetlogs;
5, point-in-time recovery (common)
Copy the code code as follows:
Rman>startup Mount;
Rman>restore database;
Rman>sql ' alter session set nls_date_format= "YYYYMMDD hh24:mi:ss"; #设置显示时间格式
Rman>recover database until time ' 20140312 17:07:00 '; #把数据库恢复到2014-03-12 17:07:00 at this point in time.
Rman>sql ' ALTER DATABASE open resetlogs ';
6. SCN-based recovery
Copy the code code as follows:
Rman>startup Mount;
Rman>restore database;
Rman>recover database until SCN 963915;
Rman>sql ' ALTER DATABASE open resetlogs ';
① Query The current SCN number:
Copy the code code as follows:
Sql>select Dbms_flashback.get_system_change_number from dual;
② query time According to SCN number:
Copy the code code as follows:
Sql>select To_char (Scn_to_timestamp (963959), ' Yyyymmdd Hh24:mi:si ') from dual;
③ the SCN number based on time:
Copy the code code as follows:
Sql>select TIMESTAMP_TO_SCN (to_date (' 20140309 17:55:10 ', ' yyyymmdd hh24:mi:ss ')) from dual;
④ Check the SCN number for a period of time:
Copy the code code as follows:
Sql>select * FROM (select TIME_DP,SCN from Smon_scn_time ORDER by time_dp Desc) where rownum<20;
7, in-depth understanding of incarnation: it is possible to cross resetlogs data recovery
① each time resetlogs will make incarnation + 1; If you want to revert to the previous incarnation SCN, you need to revert to the previous incarnation;
②incarnation and 12 include the SCN 900000 spot, so when incarnation 12 is until SCN, it is the SCN that reverts to the current incarcation; But according to our needs, we need incarn. ation 11 SCN 900000; So we need to switch incarnation to incarnation 11 to get back the data we need.
Rman>reset database to incarnation 11;
8, recover database of four statement differences
①sql>recover Database using Backup Controlfile
If you lose the current control file, use a cold backup of the control file to restore, to tell Oracle, do not use the SCN in Controlfile as the end point of recovery.
②sql>recover database until Cancel
If you lose current/active redo, manually specify the end point.
③sql>recover database using Backup controlfile until cancel;
If the current controlfile is lost and current/active redo is lost, the archive log is automatically applied and the maximum recovery can be achieved.
④sql>recover database until cancel using Backup controlfile;
If the current controlfile is lost and current/active redo is lost, the SCN in the old redo is the recovery endpoint because no archived logs are applied, and all data is lost.
To understand recover database using Backup Controlfile, first understand recover database; In the ordinary recover database or recover tablespace, recover data File, Oracle will use the archive log and redo log Redo entry to restore the associated datafile block to the "current Controlfile recorded SCN", whichever is the current controlfile record. In some cases, Oracle needs to restore data to a later location than the current Controlfile record SCN (for example, control file is backup Controlfile, or Controlfile is based on trace Create. ), it is necessary to use the using Backup Controlfile. Recovery is not limited by the "SCN currently recorded by Controlfile". This time the limit comes from your statement (until time, until SCN), or the available archive log (until cancel). If the control file is missing, restore backs up the control files after you must use the Using Backup Controlfile option. Until cancel, however, is not fully recovered, that is, the current/active redo is lost, or an archive file is missing from the restore database and terminates.
Conclusion:
If there is an old database backup, the data is not lost if the archive log and the online log are all intact, using recover database or recover database using Backup Controlfile
If a backup data file exists after restore, the archive log or the online log (active, current) is missing, use the Recover database using Backup Controlfile until cancel, The maximum recovery can be achieved.
Second, Rman machine recovery (the source database and the target database instance name to be consistent)
1. Backup the source database
Copy the code code as follows:
Rman>backup database plus archivelog;
Rman>backup current Controlfile;
2. Generate the parameter file of the source database and transfer to the target database after modification.
3. Recovery under Windows platform
Copy the code code as follows:
C:\>oradim-new-sid ORCL #创建一个orcl服务
C:\>set ORACLE_SID=ORCL
C:\>sqlplus "/as sysdba";
Sql>startup nomount pfile= ' C:\INITorcl.ORA ';
Sql> create SPFile from pfile= ' C:\INITorcl.ORA ';
sql> shutdown immediate;
sql>exit;
C:\>set ORACLE_SID=ORCL
C:\>rman target/
Rman>startup Nomount;
Rman>restore controlfile to ' target database control where the file is placed and the name ' from ' where the backup control file is placed ';
Rman>alter database Mount;
Rman>catalog start with ' backup set placement '; #向控制文件中添加备份集
Rman>crosscheck backup;
Rman>report schema;
Write the script below and run
Copy the code code as follows:
Run
{
Set newname for DataFile 1
To ' C:\oracle\product\10.2.0\oradata\orcl\SYSTEM. DBF '; #实例中SYSTEM the location of the. DBF Placement
Set newname for DataFile 2
To ' C:\oracle\product\10.2.0\oradata\orcl\UNDOTBS1. DBF ';
Set NewName for DataFile 3
To ' C:\oracle\product\10.2.0\oradata\orcl\SYSAUX. DBF ';
Set newname for DataFile 4
To ' C:\oracle\product\10.2.0\oradata\orcl\USERS. DBF ';
Set NewName for DataFile 5
To ' C:\oracle\product\10.2.0\oradata\orcl\BANK_DATA02. DBF ';
Restore database;
Switch datafile all;
}
Rman>recover database;
Rman>sql ' ALTER DATABASE open resetlogs ';
Recovery success
Rman recovery Scenarios and Oracle Machine recovery