sample 1:
1.清空归档日志
RMAN> crosscheck archivelog all;
RMAN> delete achivelog all;
2.清空数据文件。
select name from v$datafile;
rm v$datafile
3.恢复数据
##check file date:
##把db数据恢复到:2017-02-05 00:00:00
ls -lt /ngenprdblog/ ls -lt /ngprdb/data ##change data file location to '/ngprdb/data' rman nocatalog target / catalog start with '/ngprdb/data'; switch database to copy;
(解释如下)
现在换个角度来考虑,这些控制文件记录的都是不存在的文件,只是数据库认为是这些文件,而我的ASM上才是真实的数据文件,那么,我可以把ASM上的文件都认为是数据文件的copy备份,完全可以使用RMAN的catalog start with手工将这些copy“备份”加进来,数据库会认为这些文件就只是数据文件的copy备份,然后直接switch database to copy就可以成功切换。) ### change logfile location to '/ngprdb/data' select 'alter database rename file '||''''||member||''''||' to '||chr(39)||replace(member,'/ngenprdb/','/ngprdb/')||''';' from v$logfile; ###recover database method 1recover database;sql 'alter database open'; ##recover database method 2run{ set until time "to_date('2017-02-05 00:00:00','YYYY-MM-DD HH24:MI:SS')";restore database;recover database;sql 'alter database open resetlogs';}sampe 2 .restore prod db to uat db initedruat.orachange db_name
#db_name = edruatdb_name = edrproddbngt6[/home/oracle][edruat] >sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Tue May 9 17:06:05 2017
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup mount
ORACLE instance started.Total System Global Area 5678927872 bytes
Fixed Size 2215680 bytesVariable Size 1006633216 bytesDatabase Buffers 4664066048 bytesRedo Buffers 6012928 bytesDatabase mounted.SQL> alter database backup controlfile to trace;Database altered.
SQL> select * from v$diag_info;
initedruat.orachange db_namedb_name = edruat#db_name = edrprod sed -n "1,2p"sed -n "70,210p" /edruatdb/diag/rdbms/edrprod/edruat/trace/edruat_ora_8217.trc > /tmp/contrl.sqlset ic%s/prod/uat/g%s/PROD/UAT/g ###ORA-01503: CREATE CONTROLFILE failedORA-01161: database name EDRPROD in file header does not match given name ofEDRUATORA-01110: data file 1: '/edruatdb/data/system_f01.dbf'#####vi /tmp/contrl.sql
chang "resue" to "SET" and "NORESETLOGS" to "RESETLOGS"CREATE CONTROLFILE SET DATABASE "DEV" RESETLOGS ARCHIVELOG
######
ERROR at line 1:ORA-01503: CREATE CONTROLFILE failedORA-00200: control file could not be createdORA-00202: control file: '/edruatdb/data/cntl01.ctl'ORA-27038: created file already existsAdditional information: 1######mv /edruatdb/data/cntl01.ctl /edruatdb/data/cntl01.ctl.bak
mv /edruatdb/data/cntl02.ctl /edruatdb/data/cntl02.ctl.bak
SQL> @/tmp/contrl.sql
ORACLE instance started.Total System Global Area 5678927872 bytes
Fixed Size 2215680 bytesVariable Size 1006633216 bytesDatabase Buffers 4664066048 bytesRedo Buffers 6012928 bytesControl file created.
SQL> recover database using backup controlfile until cancel;
ORA-00279: change 9742867340450 generated at 05/08/2017 14:00:07 needed forthread 1ORA-00289: suggestion : /edruatdblog/edrprod_863435250_1_37704.arcORA-00280: change 9742867340450 for thread 1 is in sequence #37704 Specify log: {<RET>=suggested | filename | AUTO | CANCEL}AUTOORA-00279: change 9742867342449 generated at 05/08/2017 14:43:31 needed forthread 1ORA-00289: suggestion : /edruatdblog/edrprod_863435250_1_37705.arcORA-00280: change 9742867342449 for thread 1 is in sequence #37705ORA-00278: log file '/edruatdblog/edrprod_863435250_1_37704.arc' no longerneeded for this recovery
SQL> alter database open resetlogs;
Database altered.
cd /edruatdb/change/env
SQL> @chg_env_edruat.sql
rm /edruatdb/data/temp_f*
alter tablespace TEMP add tempfile '/edruatdb/data/temp_f01.dbf' size 4000m autoextend on;
alter tablespace TEMP add tempfile '/edruatdb/data/temp_f02.dbf' size 4000m autoextend on;alter tablespace TEMP add tempfile '/edruatdb/data/temp_f03.dbf' size 4000m autoextend on;alter database default temporary tablespace temp;
Solution
How to restore a complete database from an RMAN backup
This note assumes an RMAN catalog is not available. The use of a catalog is optional in this scenario as the backup information is available in the controlfile.
Step 1: Identify controlfile backup to restore
Note: If you do not need to restore a controlfile proceed to step 3.
Step 2: Restore the controlfile
2a) If you DO NOT have a spfile.
If you do have an spfile or init.ora move to Step 2b2b)
Step 3: Restore and recover the database
Your next task is to restore the database and perform recovery. Mount the database now that the controlfile has been restored: