recover database using backup controlfile/until cancel
-------------------------recover database using backup controlfile--------------------------------------
并不是使用rman备份的控制文件的scn恢复,而是以当前redo的记录的scn进行恢复
recover database using backup controlfile实际上是告诉数据库,我要联机日志的最大scn为终点,对数据文件在block级别进行恢复
1.找到控制文件的路径
show parameters control
我这里的控制文件路径如下:
/u01/app/oracle/oradata/ora12c/control01.ctl,
/u01/app/oracle/oradata/ora12c/control02.ctl
2.关闭数据库对控制文件做冷备份
shutdown immediate
cd /u01/app/oracle/oradata/ora12c
mkdir bak
cp control01.ctl bak/
cp control02.ctl bak/
3.启动数据库并进行检查点切换
SQL>startup
SQL>alter system checkpoint;
SQL>alter system checkpoint;
SQL>alter system checkpoint;
同时可以尝试归档日志切换
alter system switch logfile;
alter system switch logfile;
alter system switch logfile;
4.再次关闭数据库,将之前冷备份的控制文件还原
这里我先备份下当前的控制文件
SQL> shutdown immediate
[oracle@localhost ora12c]$ mv control01.ctl old_control01.ctl
[oracle@localhost ora12c]$ mv control02.ctl old_control02.ctl
使用之前冷备份的控制文件进行还原
cp bak/control01.ctl .
cp bak/control02.ctl .
5.启动数据库
SQL> connect / as sysdba
Connected to an idle instance.
SQL> startup
ORACLE instance started.
Total System Global Area 771751936 bytes
Fixed Size 8797536 bytes
Variable Size 566231712 bytes
Database Buffers 192937984 bytes
Redo Buffers 3784704 bytes
Database mounted.
ORA-01122: database file 1 failed verification check
ORA-01110: data file 1: '/u01/app/oracle/oradata/ora12c/system01.dbf'
ORA-01207: file is more recent than control file - old control file
6.查看现在控制文件、数据文件scn
控制文件scn
SQL> Select file#,CHECKPOINT_CHANGE# From v$datafile;
FILE# CHECKPOINT_CHANGE#
---------- ------------------
1 2573511
3 2573511
4 2573511
5 1441000
6 1441000
7 2573511
8 1441000
9 2573439
10 2573439
11 2573439
12 2573439
11 rows selected.
数据文件头部scn
SQL> Select file#,CHECKPOINT_CHANGE# From v$datafile_header;
FILE# CHECKPOINT_CHANGE#
---------- ------------------
1 2574491
3 2574491
4 2574491
5 1441000
6 1441000
7 2574491
8 1441000
9 2574330
10 2574330
11 2574330
12 2574330
11 rows selected.
可以发现每个数据文件上控制文件的scn 明显小于数据文件头部scn
7.做recover database恢复
SQL> recover database;
ORA-00283: recovery session canceled due to errors
ORA-01122: database file 1 failed verification check
ORA-01110: data file 1: '/u01/app/oracle/oradata/ora12c/system01.dbf'
ORA-01207: file is more recent than control file - old control file
8.加参数using backup controlfile再恢复
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /u01/app/oracle/archive_log
Oldest online log sequence 40
Next log sequence to archive 42
Current log sequence 42
SQL>
SQL>
SQL> recover database using backup controlfile;
ORA-00279: change 2573511 generated at 12/27/2019 02:01:59 needed for thread 1
ORA-00289: suggestion : /u01/app/oracle/archive_log/1_42_1027432868.dbf
ORA-00280: change 2573511 for thread 1 is in sequence #42
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
这里提示需要42这个归档日志文件,因为我们这里还没有归档,直接指定online redo
SQL> Select group#,sequence# From v$log;
GROUP# SEQUENCE#
---------- ----------
1 40
3 42
2 41
SQL> Select group#,Member From v$logfile;
GROUP# MEMBER
---------- ------------------------------------------
3 /u01/app/oracle/oradata/ora12c/redo03.log
2 /u01/app/oracle/oradata/ora12c/redo02.log
1 /u01/app/oracle/oradata/ora12c/redo01.log
SQL> recover database using backup controlfile;
ORA-00279: change 2573511 generated at 12/27/2019 02:01:59 needed for thread 1
ORA-00289: suggestion : /u01/app/oracle/archive_log/1_42_1027432868.dbf
ORA-00280: change 2573511 for thread 1 is in sequence #42
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
/u01/app/oracle/oradata/ora12c/redo03.log
Log applied.
Media recovery complete.
9.打开数据库
SQL> alter database open RESETLOGS;
Database altered.
SQL> alter pluggable database ORA12CPDB1 open;
Pluggable database altered.
10.再次检查scn
SQL> Select file#,CHECKPOINT_CHANGE# From v$datafile;
FILE# CHECKPOINT_CHANGE#
---------- ------------------
1 2574495
3 2574495
4 2574495
5 1441000
6 1441000
7 2574495
8 1441000
9 2575189
10 2575189
11 2575189
12 2575189
11 rows selected.
SQL> Select file#,CHECKPOINT_CHANGE# From v$datafile_header;
FILE# CHECKPOINT_CHANGE#
---------- ------------------
1 2574495
3 2574495
4 2574495
5 1441000
6 1441000
7 2574495
8 1441000
9 2575189
10 2575189
11 2575189
12 2575189
11 rows selected.
----------------------------recover database using backup controlfile until cancel-------------------------------------------------------
recover database using backup controlfile until cancel,既可以完全恢复,也可以指定归档日志、联机日志不完全恢复
SQL> recover database using backup controlfile until cancel;
ORA-00279: change 2576645 generated at 12/27/2019 09:27:19 needed for thread 1
ORA-00289: suggestion : /u01/app/oracle/archive_log/1_7_1028106767.dbf
ORA-00280: change 2576645 for thread 1 is in sequence #7
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
/u01/app/oracle/archive_log/1_7_1028106767.dbf
ORA-00279: change 2577308 generated at 12/27/2019 09:37:11 needed for thread 1
ORA-00289: suggestion : /u01/app/oracle/archive_log/1_8_1028106767.dbf
ORA-00280: change 2577308 for thread 1 is in sequence #8
ORA-00278: log file '/u01/app/oracle/archive_log/1_7_1028106767.dbf' no longer
needed for this recovery
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
/u01/app/oracle/archive_log/1_8_1028106767.dbf
ORA-00279: change 2577313 generated at 12/27/2019 09:37:19 needed for thread 1
ORA-00289: suggestion : /u01/app/oracle/archive_log/1_9_1028106767.dbf
ORA-00280: change 2577313 for thread 1 is in sequence #9
ORA-00278: log file '/u01/app/oracle/archive_log/1_8_1028106767.dbf' no longer
needed for this recovery
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
/u01/app/oracle/archive_log/1_9_1028106767.dbf
ORA-00279: change 2577316 generated at 12/27/2019 09:37:21 needed for thread 1
ORA-00289: suggestion : /u01/app/oracle/archive_log/1_10_1028106767.dbf
ORA-00280: change 2577316 for thread 1 is in sequence #10
ORA-00278: log file '/u01/app/oracle/archive_log/1_9_1028106767.dbf' no longer
needed for this recovery
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
/u01/app/oracle/oradata/ora12c/redo01.log
ORA-00279: change 2577319 generated at 12/27/2019 09:37:24 needed for thread 1
ORA-00289: suggestion : /u01/app/oracle/archive_log/1_11_1028106767.dbf
ORA-00280: change 2577319 for thread 1 is in sequence #11
ORA-00278: log file '/u01/app/oracle/oradata/ora12c/redo01.log' no longer
needed for this recovery
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
/u01/app/oracle/oradata/ora12c/redo02.log
Log applied.
Media recovery complete.
SQL> alter database open resetlogs;
Database altered.
若是停掉数据库期间做个归档的切换,那么恢复控制文件后,该控制文件是不会记录归档切换后的信息的,这样的恢复的话,按照提示输入每个redo日志文件
如下控制文件只记录到7的归档,而做了日志切换后,归档日志已经到了10,但是我们又不知道10对应的是那个redo,那么只能每个都进行输入进行恢复
SQL> Select group#,Member From v$logfile;
GROUP# MEMBER
---------- -----------------------------------------------------
3 /u01/app/oracle/oradata/ora12c/redo03.log
2 /u01/app/oracle/oradata/ora12c/redo02.log
1 /u01/app/oracle/oradata/ora12c/redo01.log
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /u01/app/oracle/archive_log
Oldest online log sequence 5
Next log sequence to archive 7
Current log sequence 7