第4章 資料庫恢復 Database Recovery

zhengbao_jun發表於2009-02-18
第4章 資料庫恢復 Database Recovery
Restore 和 Recovery
sql>connect / as sysdba
sql>startup mount
rman>run
{
allocate channel c1 type disk;
restore database;
recover database;
alter database open;
}
使用者管理恢復
SQL>CONNECT / AS SYSDBA
SQL>STARTUP
command>copy ..\backup\ora101t\users01.dbf
sql>startup mount
sql>recover database;
sql>alter database open;
恢復控制檔案
1. First, you must configure RMAN to perform. a control file autobackup:
rman>connect target
SQL> select dbid from v$database; 1125643918
rman>configure controlfile autobackup on;
rman>show all;
2. Next, perform. a backup with the control file autobackup enabled:
rman>run
{
backup database;
backup (archivelog all);
}
3. Next, you simulate the missing control files by deleting all the control files.
(The database will need to be shut down to perform. this simulated failure.)
command>delete *.ctl
4. Next, start the database in NOMOUNT mode,
command>sqlplus /nolog
sql>connect / as sysdba
sql>startup nomount
5. Next, connect to RMAN and the target database. You will also need to specify the DBID to identify the database you are connecting to, because the control file contains this information and failure causes the control file to be unavailable. The DBID was obtained in step 1 from connecting to the target database before the failure was introduced:
rman>connect target /
rman>set dbid 1125643918; (沒有設定dbid,也搞定,不過是在本地執行dbid,如果恢復資料庫有多個資料庫的備份,可能需要設定dbid,控制檔案裡儲存了dbid資訊)
6. Next, restore the control file from backup:
rman>restore controlfile from autobackup;
7. Next, mount the database and begin to recover the database:
rman>alter database mount;
rman>recover database;
8. Finally, open the database with RESETLOGS option for normal operations:
rman>alter database open resetlogs;
重建控制檔案 Re-creating a Control File
SQL>sqlplus /nolog
sql>connec / as sysdba
sql>alter database backup controlfile to trace;
command>edit ora101t_ora_3428.trc ----&gt儲存為 backup_controlfile_noreset.txt
command>delete *.ctl
command>sqlplus /nolog
sql>connect / as sysdba
@backup_controlfile_noreset.txt
command>dir *.ctl
進行不完全恢復 Performing an Incomplete Recovery
RMAN Incomplete Recovery
SQL>STARTUP MOUNT
command:set NLS_DATE_FORMAT=DD-MON-YYYY HH24:MI:SS
rman>
run
{
set until time '06-SEP-2004 11:25:00';
restore database;
recover database;
}
rman>alter database open resetlogs;
sql>select * from v$log_history;
sql>startup mount
rman>
run
{
set until sequence 3 thread 1;
restore database;
recover database;
}
rman>alter database open resetlogs;
完成使用者管理得不完全恢復
command>set NLS_DATE_FORMAT=DD-MON-YYYY HH24:MI:SS
command>delete USERS01.DBF
command>copy c:\oracle\backup\ora101t\users01.dbf
sql>startup mount
sql>recover database until time '06-SEP-2004 15:15:00';
SQL>ALTER database open resetlogs;

1 . c:\oradata\oracle\ora101t\>copy c:\oracle\backup\ora101t\*.dbf
2 . 檢視 控制檔案建立指令碼
3 . SQL>CONNECT / AS SYSDBA;
SQL>backup_control_reset.txt
4 .sql>recover database until cancel using backup controlfile;
sql>alter database open resetlogs;
使用EM得資料恢復
在RESETLOGS操作之後完成恢復
Performing a Recovery after a RESETLOGS Operation
1. 1. Perform. a backup if you do not have a good whole database backup:
RMAN>CONNECT target
rman>run
{
allocate channel c1 type disk;
backup database;
backup (archivelog all);
}
2. Force all the redo log information to archive logs by executing ALTER SYSTEM SWITCH LOGFILE:
sql>alter system switch logfile;
sql>alter system switch logfile;
sql>alter system switch logfile;
sql>alter system switch logfile;
3. Verify the redo log sequence and thread number in the V$LOG_HISTORY table so that you
can perform. incomplete recovery to a redo log sequence:
SQL> select * from v$log_history;
4. Simulate a failure by shutting down the database and deleting the USERS01.DBF:
command>sqlplus /nolog
sql>connect / as sysdba
sql>shutdown immediate
sql>host
command>del users01.dbf
5. Begin the recovery process by starting the database in MOUNT mode:
sql>startup mount
6. Perform. an incomplete recovery using the SET UNTIL SEQUENCE clause:
rman>connect target
rman>
run
{
set until sequence 5 thread 1; (恢復到sequence 4)
restore database;
recover database;
}
RMAN> alter database open resetlogs;
7. Simulate database activity by creating a table T1 and forcing this activity to the archived redo logs:
sql>connect test/test
sql>create table t1(c1 char(20));
sql>connect / as sysdba
sql>alter system switch logfile;
sql>alter system switch logfile;
sql>alter system switch logfile;
sql>alter system switch logfile;
8. Shut down the database and simulate a database failure by deleting the USERS01.DBF file:
sql>shutdown immediate
C:\oracle\oradata\ora101t\> del USERS01.DBF
9. Start the database in MOUNT mode and then perform. a complete recovery in RMAN:
sql>startup mount
command>rman
rman>connect target
rman>
run
{
restore database;
recover database;
}
10. Validate that you have recovered through the last RESETLOGS by verifying that the current V$LOG_HISTORY table shows the log sequence 6 and thread 1 followed by new redo logs files:
sql>select * from v$log_history;

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/235507/viewspace-555202/,如需轉載,請註明出處,否則將追究法律責任。

相關文章