返回顶部

欢迎来到菜鸟大明儿哥的博客

我们一起交流学习,不断提升自我

ORACLE 12C RMAN备份与恢复

oracle12C下一个CDB库(test),两个PDB库(test1,test2)

一、备份

rman target sys/oracle@test

1.显示数据库结构

RMAN>report schema;

 

Report of database schema for database with db_unique_name TEST

List of Permanent Datafiles
===========================
File          Size(MB)     Tablespace           RB segs                               Datafile Name
---- -------- ---------------------------------------------------------------------------------------------------------- ------- ------------------------
 1            930     SYSTEM      YES      +DATA/TEST/DATAFILE/system.261.1013957131
 2      3140    SYSAUX       NO       +DATA/TEST/DATAFILE/sysaux.262.1013957135
 3      965      UNDOTBS1      YES      +DATA/TEST/DATAFILE/undotbs1.263.1013957135
 4      200      UNDOTBS2      YES      +DATA/TEST/DATAFILE/undotbs2.264.1013957143
 5        5        USERS         NO       +DATA/TEST/DATAFILE/users.265.1013957145
 6      32000       USERS         NO       +DATA/TEST/DATAFILE/users02.dbf

List of Temporary Files
=======================
File      Size(MB)  Tablespace    Maxsize(MB)   Tempfile Name
---- -------- ------------------------------------------------------------------------------------------------------------------ ----------- --------------------
 1       78      TEMP      32767     +DATA/TEST/TEMPFILE/temp.257.1013957137

2.备份全库
RMAN> backup database;

3.备份CDB库
RMAN> backup database root;

4.备份PDB库(可多个)
RMAN> backup pluggable database test1,test2; (如果要备份根容器需要加"")

5.备份表空间
rman target sys/oracle@test1
RMAN> backup tablespace TEST;

 

二、恢复

1.恢复全库
rman target sys/oracle@test
run
{
allocate channel c1 type disk;
startup mount;
restore database;
recover database;
alter database open;
release channel c1;
}

2.恢复CDB库
connect target sys/oracle@test
run
{
allocate channel c1 type disk;
startup mount;
restore database root;
recover database root;
alter database open;
release channel c1;
}

3.恢复PDB库(可多个同时恢复)
connect target sys/oracle@test
run
{
allocate channel c1 type disk;
alter pluggable database test1,test2 close;
restore pluggable database test1,test2;
recover pluggable database test1,test2;
alter pluggable database test1,test2 open;
release channel c1;
}


4.单独恢复CDB库数据文件
connect target sys/oracle@test
run{
allocate channel c1 type disk;
sql 'alter database datafile 11 offline';
restore datafile 11;
recover datafile 11;
sql 'alter database datafile 11 online';
release channel c1;
}

5.单独恢复PDB库数据文件
connect target sys/oracle@test2
run{
allocate channel c1 type disk;
sql 'alter database datafile 15 offline';
restore datafile 15;
recover datafile 15;
sql 'alter database datafile 15 online';
release channel c1;
}

 

6. 恢复控制文件:

            关闭数据库:

            sqlplus / as sysdba

            shutdown immediate

            rman登录:

            rman target /

            startup nomount

            restore controlefile from autobackup;

            alter database mount;

            recover database;

            alter database open resetlogs;

            alter pluggable database all open;

 

  7. 恢复system或undo表空间

            关闭数据库:

            sqlplus / as sysdba

            shutdown immediate

            rman登录:

            rman target /

            startup mount

            restore tablespace system;

            recover tablespace system;

            alter database open;

            alter pluggable database all open;

 

   8. 恢复SYSAUX或其他根表空间

            不需要关闭数据库

            rman登录:

            alter tablespace sysaux offline immediate;

            restore tablespace sysaux;

            recover tablespace sysaux;

            alter tablespace sysaux online;

 

   9. 恢复PDB数据文件

            (1)丢失未开启pdb的system表空间(CDB和其他PDB在还原和恢复期间仍可打开)

                  rman登录:

                  restore tablespace test1:system;

                  recover tablespace test1:system;

                  alter pluggable database test1 open;

            注:若pdb已开启,此时丢失system表空间,则要关闭整个CDB。

            (2)丢失PDB非system数据文件

                  sqlplus / as sysdba

                  conn sys/oracle@test1;

                  alter tablespace test offline;

                  登录rman:

                  restore tablespace test1:test;

                  recover tablespace test1:test;

                  sqlplus / as sysdba

                  conn sys/oracle@test1;

                  alter tablespace test offline;

posted @ 2020-04-13 16:26  菜鸟大明儿哥  阅读(1659)  评论(0编辑  收藏  举报