基於cancel的資料庫恢復

skyin_1603發表於2016-11-07

基於cancel的恢復,該種方式恢復資料庫,只能恢復到刪除日誌檔案與資料檔案之前已歸檔日誌時的狀態。

---全庫備份:

[oracle@enmo ~]$ rman  target /

Recovery Manager: Release 11.2.0.4.0 - Production on Mon Nov 7 13:20:57 2016

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

connected to target database: PROD (DBID=338469376)

 

RMAN> backup as compressed backupset full database;

Starting backup at 07-NOV-16

using target database control file instead of recovery catalog

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=29 device type=DISK

channel ORA_DISK_1: starting compressed full datafile backup set

channel ORA_DISK_1: specifying datafile(s) in backup set

input datafile file number=00001 name=/u01/app/oracle/oradata/PROD/system01.dbf

input datafile file number=00002 name=/u01/app/oracle/oradata/PROD/sysaux01.dbf

input datafile file number=00005 name=/u01/app/oracle/oradata/PROD/example01.dbf

input datafile file number=00003 name=/u01/app/oracle/oradata/PROD/undotbs01.dbf

input datafile file number=00006 name=/u01/app/oracle/oradata/PROD/ts_xxf_01.dbf

input datafile file number=00004 name=/u01/app/oracle/oradata/PROD/users01.dbf

channel ORA_DISK_1: starting piece 1 at 07-NOV-16

channel ORA_DISK_1: finished piece 1 at 07-NOV-16

piece handle=/u01/app/backup/db_0crkane1_1_1.rmn tag=TAG20161107T132105 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:02:25

Finished backup at 07-NOV-16

 

Starting Control File and SPFILE Autobackup at 07-NOV-16

piece handle=/u01/app/oracle/fast_recovery_area/PROD/autobackup/2016_11_07/o1_mf_s_927293010_d203ylz3_.bkp comment=NONE

Finished Control File and SPFILE Autobackup at 07-NOV-16

RMAN>

#全庫備份完成。

---建立測試表:

create table t1 as select 1 as id from dual;

suxing@PROD>create table t1 as select 1 as id from dual;

Table created.

suxing@PROD>select * from t1;

        ID

----------

         1

create table t2 as select 2 as id from dual;

suxing@PROD>create table t2 as select 2 as id from dual;

Table created.

suxing@PROD>select * from t2;

        ID

----------

         2

--切換當前redo日誌:

sys@PROD>alter system archive log current;

System altered.

 

create table t3 as select 3 as id from dual;

suxing@PROD>create table t3 as select 3 as id from dual;

Table created.

suxing@PROD>select * from t3;

        ID

----------

         3

--在切換一次日誌:

sys@PROD>alter system archive log current;

System altered.

 

--檢視3個表的資訊:

sys@PROD>select table_name,tablespace_name from dba_tables

  2  where table_name LIKE 'T_';

TABLE_NAME                     TABLESPACE_NAME

------------------------------ ------------------------------

T1                             USERS

T1                             USERS

T2                             USERS

T3                             USERS 


--刪除所有日誌檔案

[oracle@enmo backup]$ cd /u01/app/oracle/oradata/PROD

[oracle@enmo PROD]$ ls

control01.ctl  redo01.log  redo03.log    system01.dbf  ts_xxf_01.dbf  users01.dbf

example01.dbf  redo02.log  sysaux01.dbf  temp01.dbf    undotbs01.dbf

[oracle@enmo PROD]$

[oracle@enmo PROD]$ pwd

/u01/app/oracle/oradata/PROD

[oracle@enmo PROD]$ rm *.log

[oracle@enmo PROD]$ ls

control01.ctl  example01.dbf  sysaux01.dbf  system01.dbf  temp01.dbf  ts_xxf_01.dbf  undotbs01.dbf  users01.dbf

[oracle@enmo PROD]$ rm *.dbf

[oracle@enmo PROD]$ ls

control01.ctl

---資料庫啟動到mount模式

sys@PROD>shutdown abort;

ORACLE instance shut down.

sys@PROD>startup mount;

ORACLE instance started.

 

Total System Global Area  835104768 bytes

Fixed Size                  2257840 bytes

Variable Size             507513936 bytes

Database Buffers          322961408 bytes

Redo Buffers                2371584 bytes

Database mounted.

sys@PROD>

 

[oracle@enmo ~]$ rman target /

Recovery Manager: Release 11.2.0.4.0 - Production on Mon Nov 7 13:58:08 2016

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

connected to target database: PROD (DBID=338469376, not open)

RMAN>

---裝載資料檔案恢復:

RMAN> restore database;

 

Starting restore at 07-NOV-16

using target database control file instead of recovery catalog

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=20 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 /u01/app/oracle/oradata/PROD/system01.dbf

channel ORA_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/PROD/sysaux01.dbf

channel ORA_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/PROD/undotbs01.dbf

channel ORA_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/PROD/users01.dbf

channel ORA_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/PROD/example01.dbf

channel ORA_DISK_1: restoring datafile 00006 to /u01/app/oracle/oradata/PROD/ts_xxf_01.dbf

channel ORA_DISK_1: reading from backup piece /u01/app/backup/db_0crkane1_1_1.rmn

channel ORA_DISK_1: piece handle=/u01/app/backup/db_0crkane1_1_1.rmn tag=TAG20161107T132105

channel ORA_DISK_1: restored backup piece 1

channel ORA_DISK_1: restore complete, elapsed time: 00:03:15

Finished restore at 07-NOV-16

RMAN>

#裝載完成。


---恢復資料檔案:

---直接做恢復操作:

RMAN> recover database;

Starting recover at 07-NOV-16

using channel ORA_DISK_1

starting media recovery

 

archived log for thread 1 with sequence 1 is already on disk as file /u01/app/oracle/fast_recovery_area/PROD/archivelog/2016_11_07/o1_mf_1_1_d204rlf1_.arc

archived log for thread 1 with sequence 2 is already on disk as file /u01/app/oracle/fast_recovery_area/PROD/archivelog/2016_11_07/o1_mf_1_2_d204v4nd_.arc

archived log file name=/u01/app/oracle/fast_recovery_area/PROD/archivelog/2016_11_07/o1_mf_1_1_d204rlf1_.arc thread=1 sequence=1

archived log file name=/u01/app/oracle/fast_recovery_area/PROD/archivelog/2016_11_07/o1_mf_1_2_d204v4nd_.arc thread=1 sequence=2

RMAN-00571: ===========================================================

RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============

RMAN-00571: ===========================================================

RMAN-03002: failure of recover command at 11/07/2016 14:06:52

ORA-00283: recovery session canceled due to errors

RMAN-11003: failure during parse/execution of SQL statement: alter database recover logfile '/u01/app/oracle/fast_recovery_area/PROD/archivelog/2016_11_07/o1_mf_1_2_d204v4nd_.arc'

ORA-00283: recovery session canceled due to errors

ORA-00313: open failed for members of log group 3 of thread 1

ORA-00312: online log 3 thread 1: '/u01/app/oracle/oradata/PROD/redo03.log'

ORA-27037: unable to obtain file status

Linux-x86_64 Error: 2: No such file or directory

Additional information: 3

#報錯,原因是丟失了日誌檔案。

 

sys@PROD>recover database until cancel;

ORA-00279: change 1754922 generated at 11/07/2016 13:38:44 needed for thread 1

ORA-00289: suggestion :

/u01/app/oracle/fast_recovery_area/PROD/archivelog/2016_11_07/o1_mf_1_3_%u_.arc

ORA-00280: change 1754922 for thread 1 is in sequence #3

 

Specify log: {=suggested | filename | AUTO | CANCEL}

 

Specify log: {=suggested | filename | AUTO | CANCEL}

Cancel

Media recovery cancelled.

#恢復到刪除之時的狀態。
 

---嘗試以resetlogs方式開啟資料庫:

sys@PROD>alter database open resetlogs;

Database altered.

#已經恢復到刪除前完成,併成功開啟資料庫:

 

---嘗試檢視之前建立的資料表:

sys@PROD>select table_name,tablespace_name from dba_tables

  2  where table_name LIKE 'T_';

TABLE_NAME                     TABLESPACE_NAME

------------------------------ ------------------------------

T1                             USERS

T1                             USERS

T2                             USERS

T3                             USERS
#可以已經恢復到刪除日誌前已歸檔部分的狀態。

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

相關文章