首页 > 数据库 > Oracle > 基于cancel的数据库恢复
基于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博客 ” ,链接:https://blog.itpub.net/31392094/viewspace-2127962/ ,如需转载,请注明出处,否则将追究法律责任。