12C容器数据库的备份恢复及闪回CDB与PDB。

2020-09-12 00:00:00 文件 备份 报错 日志 恢复

12C之五备份恢复、闪回CDBPDB

1 备份整个CDB

rman target /

backup as compressed backupset database plus archivelog delete all input;

2 备份pluggable

backup as compressed backupset pluggable database orclpdb;

3)恢复PDBsystem表空间

sqlplus system/oracle@orclpdb

select file_name from dba_data_files;

! rm /u01/app/oracle/oradata/orcl/orclpdb/system01.dbf


rman target /

shutdown abort

start mount


restore tablespace orclpdb:system;

recover tablespace orclpdb:system;

alter database open;

alter pluggable database orclpdb open;


至此恢复完毕

也可以将整个PDB恢复到方式实现

rman target /

shutdown abort;

startup mount;

restore pluggable database orclpdb;

recover pluggable database orclpdb;

alter database open;

alter pluggable database orclpdb open;


4 恢复PDB的非关键文件(高可用恢复)

创建测试表空间

create tablespace users datafile ‘/u01/app/oracle/oradata/orcl/orclpdb/users01.dbf’ size 10m;

create table t (id number) 

insert into t values(100);

commit;

alter table t move tablespace users;


!rm /u01/app/oracle/oradata/orcl/orclpdb/users01.dbf

(这里清除Buffer cache验证表t无法查询数据)

sqlplus system/oracle@orclpdb

alter tablespace users offline immediate

(这里文件已经删除了,必须使用immediate,否则报错文件不存在)


rman target /

restore tablespace orclpdb:users;

recover tablespace orclpdb:users;


sqlplus system/oracle@orclpdb

alter tablespace users online;


5)备份控制文件夹

alter database backup controlfile to trace;

cd /u01/app/oracle/diag/rdbms/orcl/orcl/trace/

ls -ltr | tail -10


配置RMAN自动备份


(6) 恢复控制文件

 方法1:直接拷贝完好的副本

方法2:使用trace的脚本

方法3:使用RMAN自动备份恢复。


select name from v$controlfile;

!rm /u01/app/oracle/fast_recovery_area/orcl/control02.ctl

此时尝试关闭数据库,无法关库(关库需要写控制文件,完全检查点),报错

shutdown abort;

rman target /

startup nomount;

restore controlfile from autobackup;

alter database mount;

recover database;

alter database open resetlogs;


sqlplus / as sysdba

alter pluggable database orclpdb open;


后再做一次全备份

rman target /

backup as compressed backupset database plus archivelog delete all input;


7)恢复重做日志文件

先向日志组添加成员

alter database add logfile member '/u01/app/oracle/oradata/orcl/redo01_2’ to group 1;

alter database add logfile member '/u01/app/oracle/oradata/orcl/redo02_2' to group 2;

alter database add logfile member '/u01/app/oracle/oradata/orcl/redo03_2’ to group 3;


切换日志,让所有新成员都有数据。


查看当前日志状态

SQL> select group#,sequence#,archived,status from v$log;


    GROUP#  SEQUENCE# ARC STATUS

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

1       10                NO  CURRENT

2       8                 YES INACTIVE

3       9                 YES INACTIVE


我们删除当前Group1 的某个日志成员


 !rm -f /u01/app/oracle/oradata/orcl/redo01_2


 group1—/u01/app/oracle/oradata/orcl/redo01_2

group1—/u01/app/oracle/oradata/orcl/redo01

如何恢复呢,通过clear的方式尝试重新格式化重做日志

alter database clear logfile group 1;

但是该日志的当前在用的,系统报错


下面尝试切换日志

alter system switch logfile;

切换成功后,查询日志状态

SQL> select group#,sequence#,archived,status from v$log;


    GROUP#  SEQUENCE# ARC STATUS

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

1                 10 YES ACTIVE

2                 11 NO  CURRENT

3                   9 YES INACTIVE


再clear,可能依然报错,需要通过完全检查点推进,使得日志组1实例恢复不再需要。

alter database clear logfile group 1;

ERROR at line 1:

ORA-01624: log 1 needed for crash recovery of instance orcl (thread 1)

ORA-00312: online log 1 thread 1: '/u01/app/oracle/oradata/orcl/redo01.log'

ORA-00312: online log 1 thread 1: '/u01/app/oracle/oradata/orcl/redo01_2

alter system checkpoint;


继续clear

alter database clear logfile group 1;

此时成功!

验证:

 !ls -l /u01/app/oracle/oradata/orcl/redo*



其他

如新增日志组

alter database add logfile group 1 '/u01/app/oracle/oradata/orcl/redo01.log'  size 200m;


删除日志成员

alter database drop logfile member '/u01/app/oracle/oradata/orcl/redo01.log'


注意:操作系统文件依然存在,需要手工删除

相关文章