数据库做不完全恢复(可用于备份集异地恢复)

环境:

OS:Centos 7

DB:12.2.0.1

数据库做不完全恢复
1.首先做个全备
run
{
allocate channel ch1 device type disk;
backup as compressed backupset full filesperset 5 database format '/u01/rman_backup/db_fullbackup_%d_%s_%p_%T';
sql 'alter system archive log current';
backup as compressed backupset archivelog all delete input format '/u01/rman_backup/arch_%d_%s_%p_%T';
backup current controlfile format '/u01/rman_backup/ctl_%d_%s_%p_%T';
backup spfile format '/u01/rman_backup/spfile_%d_%s_%p_%T';
release channel ch1;
crosscheck backup;
crosscheck archivelog all;
delete noprompt expired backup;
delete noprompt obsolete;
}

2.模拟删除全部的归档日志
rm /u01/app/oracle/oradata/ora12c/redo01.log
rm /u01/app/oracle/oradata/ora12c/redo02.log
rm /u01/app/oracle/oradata/ora12c/redo03.log

3.数据库重启动
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.

Total System Global Area  771751936 bytes
Fixed Size                  8797536 bytes
Variable Size             629146272 bytes
Database Buffers          130023424 bytes
Redo Buffers                3784704 bytes
Database mounted.
ORA-03113: end-of-file on communication channel
Process ID: 24209
Session ID: 1 Serial number: 41927

发现无法启动,后台日志如下:
Errors in file /u01/app/oracle/diag/rdbms/ora12c/ora12c/trace/ora12c_lgwr_24169.trc:
ORA-00313: open failed for members of log group 1 of thread 1
ORA-00312: online log 1 thread 1: '/u01/app/oracle/oradata/ora12c/redo01.log'
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 7
2019-12-18T16:54:07.141494-05:00
Errors in file /u01/app/oracle/diag/rdbms/ora12c/ora12c/trace/ora12c_lgwr_24169.trc:
ORA-00313: open failed for members of log group 1 of thread 1
ORA-00312: online log 1 thread 1: '/u01/app/oracle/oradata/ora12c/redo01.log'
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 7
2019-12-18T16:54:07.142117-05:00
Errors in file /u01/app/oracle/diag/rdbms/ora12c/ora12c/trace/ora12c_ora_24209.trc:
ORA-00313: open failed for members of log group 1 of thread
ORA-00312: online log 1 thread 1: '/u01/app/oracle/oradata/ora12c/redo01.log'

4.查看数据库最后的归档日志
启动到mount状态,看下当前的归档日志情况
SQL>startup mount
SQL>set linesize 1000;
SQL>column sequence# format 999999;
SQL>column Name format a64;
SQL> select sequence#,name,resetlogs_id from v$archived_log;

SEQUENCE# NAME                                                             RESETLOGS_ID
--------- ---------------------------------------------------------------- ------------
        2                                                                    1027345947
        3                                                                    1027345947
        1                                                                    1027353855
        2                                                                    1027353855
        0                                                                    1027353855
        1 /u01/app/oracle/oradata/ora12c/redo01.log                          1027353855
        2 /u01/app/oracle/oradata/ora12c/redo02.log                          1027353855
        0 /u01/app/oracle/oradata/ora12c/redo03.log                          1027353855
        1                                                                                                     1027355918
        2 /u01/app/oracle/archive_log/1_2_1027355918.dbf                     1027355918

10 rows selected.

可以看到最后的归档日志是2,我们查看下该归档日志是否存在
[oracle@localhost archive_log]$ ls -1 /u01/app/oracle/archive_log/1_2_1027355918.dbf
/u01/app/oracle/archive_log/1_2_1027355918.dbf


或是在rman模式下查看
RMAN> list archivelog all;

List of Archived Log Copies for database with db_unique_name ORA12C
=====================================================================

Key     Thrd Seq     S Low Time           
------- ---- ------- - -------------------
10      1    2       A 2019-12-18 16:43:19
        Name: /u01/app/oracle/archive_log/1_2_1027355918.dbf


5.进行不完全恢复

启动数据库到mount状态
RMAN> shutdown immediate
RMAN> startup nomount

恢复控制文件

RMAN> restore controlfile from '/u01/rman_backup/db_fullbackup_ORA12C_20_1_20191218'; ##这个备份集可以使用list backup查看包含控制文件的是那个备份集
RMAN> alter database mount;

检查是否可以恢复
run{
set until sequence 3 thread 1; ##这里不包含3归档,只到2
restore database preview;
}

进行恢复
run{
set until sequence 3 thread 1; ##这里不包含3归档,只到2
restore database;
recover database;
}

最后打开数据库
RMAN> alter database open resetlogs;

Statement processed

若是在异机恢复的话,因业务的要求有可能进行多次不完全恢复,可以采用只读的方式打开数据,通过dblink连接,让业务比较数据

alter database open read only;
只读方式启动pdb
SQL> alter pluggable database ORA12CPDB1 open read only;

posted @ 2019-12-18 17:22  slnngk  阅读(380)  评论(0编辑  收藏  举报