RMAN不完全恢復方法(恢復到資料庫某一時間點)
RMAN不完全恢復方法
試驗目的:利用RMAN完成對資料庫的不完全恢復(將資料庫恢復到某個時間點) 試驗步驟: 1.RMAN備份資料庫:backup database; 2. 記錄當前時間:3.刪除一個表:SQL> select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual;TO_CHAR(SYSDATE,'YY-------------------2018-05-09 15:37:15
drop table emp purge;
4.如果在刪除前沒有做時間的記錄,可以通過日誌挖掘來找出刪除的時間或scn:
SQL> exec dbms_logmnr.add_logfile('/home/oracle/app/oracle/oradata/orcl/redo01.log'); (這裡的日誌如果是歸檔日誌,也可用同樣的方法新增進去)
PL/SQL procedure successfully completed.
SQL> EXECUTE DBMS_LOGMNR.START_LOGMNR(OPTIONS=>DBMS_LOGMNR.DICT_FROM_ONLINE_CATALOG);
PL/SQL procedure successfully completed.
SQL> select scn,to_char(timestamp,'yyyy-mm-dd hh24:mi:ss') time,sql_redo from v$logmnr_contents where table_name='EMP';
SCN TIME SQL_REDO
--------------------------------------------------------------------------------
1201958 2018-05-09 15:37:26 drop table emp purge;
SQL> exec dbms_logmnr.end_logmnr;
5.通過RMAN來恢復到指定時間點
RMAN> shutdown immediate
RMAN> startup mount
RMAN> run {
2> set until time "to_date('2018-05-09 15:37:25','yyyy-mm-dd hh24:mi:ss')";
3> restore database;
4> recover database;
5> alter database open resetlogs;
6> }
executing command: SET until clause
Starting restore at 09-MAY-18
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=7 device type=DISK
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 /home/oracle/app/oracle/oradata/orcl/system01.dbf
channel ORA_DISK_1: restoring datafile 00002 to /home/oracle/app/oracle/oradata/orcl/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00003 to /home/oracle/app/oracle/oradata/orcl/undotbs01.dbf
channel ORA_DISK_1: restoring datafile 00004 to /home/oracle/app/oracle/oradata/orcl/users01.dbf
channel ORA_DISK_1: restoring datafile 00005 to /home/oracle/app/oracle/oradata/orcl/example01.dbf
channel ORA_DISK_1: reading from backup piece /home/oracle/app/oracle/fast_recovery_area/ORCL/backupset/2018_05_09/o1_mf_nnndf_TAG20180509T153541_fh596frb_.bkp
channel ORA_DISK_1: piece handle=/home/oracle/app/oracle/fast_recovery_area/ORCL/backupset/2018_05_09/o1_mf_nnndf_TAG20180509T153541_fh596frb_.bkp tag=TAG20180509T153541
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:25
Finished restore at 09-MAY-18
Starting recover at 09-MAY-18
using channel ORA_DISK_1
starting media recovery
media recovery complete, elapsed time: 00:00:01
Finished recover at 09-MAY-18
至此,已完成恢復到指定時間點,在去查emp表的時,可以發現已經恢復。database opened