oracle 12c中CDB和PDB的備份還原實驗

水逸冰發表於2019-07-19

本文件分為兩部分:
1.單個pdb備份還原
2.只cdb備份還原


1.rman只備份pdb
SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 MPDB01                         READ WRITE NO
         5 MPDB02                         READ WRITE NO
CDB和PDB中建立如下測試表:
SQL> create table t_for_back (a int);

Table created.

SQL> insert into t_for_back select 1 from dual;

1 row created.

SQL> commit;

Commit complete.


備份單個pdb
RMAN> BACKUP pluggable database mpdb02 FORMAT '/backup/oraback/bk_%s_%p_%t';

Starting backup at 19-JUL-19
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00016 name=/u02/app/oracle/oradata/MCDB/8E032EED10D56F47E05302CEA8C0D24C/datafile/o1_mf_undotbs1_gm2p199r_.dbf
input datafile file number=00014 name=/u02/app/oracle/oradata/MCDB/8E032EED10D56F47E05302CEA8C0D24C/datafile/o1_mf_system_gm2p199h_.dbf
input datafile file number=00015 name=/u02/app/oracle/oradata/MCDB/8E032EED10D56F47E05302CEA8C0D24C/datafile/o1_mf_sysaux_gm2p199q_.dbf
input datafile file number=00017 name=/u02/app/oracle/oradata/MCDB/8E032EED10D56F47E05302CEA8C0D24C/datafile/o1_mf_users_gm2p199s_.dbf
channel ORA_DISK_1: starting piece 1 at 19-JUL-19
channel ORA_DISK_1: finished piece 1 at 19-JUL-19
piece handle=/backup/oraback/bk_100_1_1014040596 tag=TAG20190719T135636 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:15
Finished backup at 19-JUL-19

Starting Control File and SPFILE Autobackup at 19-JUL-19
piece handle=/u02/app/oracle/products/12.2.0.1/db_1/dbs/c-3951895183-20190719-01 comment=NONE
Finished Control File and SPFILE Autobackup at 19-JUL-19

檢查備份情況:
RMAN>  list backup of pluggable database mpdb02;


List of Backup Sets
===================


BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
94      Full    1.17G      DISK        00:00:08     19-JUL-19      
        BP Key: 94   Status: AVAILABLE  Compressed: NO  Tag: TAG20190719T135636
        Piece Name: /backup/oraback/bk_100_1_1014040596
  List of Datafiles in backup set 94
  Container ID: 5, PDB Name: MPDB02
  File LV Type Ckp SCN    Ckp Time  Abs Fuz SCN Sparse Name
  ---- -- ---- ---------- --------- ----------- ------ ----
  14      Full 2902650    19-JUL-19              NO    /u02/app/oracle/oradata/MCDB/8E032EED10D56F47E05302CEA8C0D24C/datafile/o1_mf_system_gm2p199h_.dbf
  15      Full 2902650    19-JUL-19              NO    /u02/app/oracle/oradata/MCDB/8E032EED10D56F47E05302CEA8C0D24C/datafile/o1_mf_sysaux_gm2p199q_.dbf
  16      Full 2902650    19-JUL-19              NO    /u02/app/oracle/oradata/MCDB/8E032EED10D56F47E05302CEA8C0D24C/datafile/o1_mf_undotbs1_gm2p199r_.dbf
  17      Full 2902650    19-JUL-19              NO    /u02/app/oracle/oradata/MCDB/8E032EED10D56F47E05302CEA8C0D24C/datafile/o1_mf_users_gm2p199s_.dbf
 
模擬資料檔案丟失  
[oracle@oradb-2062 datafile]$ mv o1_mf_system_gm2p199h_.dbf o1_mf_system_gm2p199h_.dbf.bak


cdb和mpdb01中:
SQL> create table t19071901 (a int);

Table created.

SQL> insert into t19071901 select 1 from dual;

1 row created.

SQL> commit;

Commit complete.

mpdb02中
SQL> create table t19071901 (a int) tablespace users;

Table created.

SQL> insert into t19071901 select 1 from dual;

1 row created.

SQL> commit;

Commit complete.

SQL> alter system checkpoint;

System altered.

SQL> sho con_name
ERROR:
ORA-03135: connection lost contact
Process ID: 94384
Session ID: 33 Serial number: 19671


SP2-1545: This feature requires Database availability.

現在RMAN恢復:
RMAN> restore pluggable database mpdb02;

Starting restore at 19-JUL-19
using channel ORA_DISK_1

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 00014 to /u02/app/oracle/oradata/MCDB/8E032EED10D56F47E05302CEA8C0D24C/datafile/o1_mf_system_gm2p199h_.dbf
channel ORA_DISK_1: restoring datafile 00015 to /u02/app/oracle/oradata/MCDB/8E032EED10D56F47E05302CEA8C0D24C/datafile/o1_mf_sysaux_gm2p199q_.dbf
channel ORA_DISK_1: restoring datafile 00016 to /u02/app/oracle/oradata/MCDB/8E032EED10D56F47E05302CEA8C0D24C/datafile/o1_mf_undotbs1_gm2p199r_.dbf
channel ORA_DISK_1: restoring datafile 00017 to /u02/app/oracle/oradata/MCDB/8E032EED10D56F47E05302CEA8C0D24C/datafile/o1_mf_users_gm2p199s_.dbf
channel ORA_DISK_1: reading from backup piece /backup/oraback/bk_100_1_1014040596
channel ORA_DISK_1: piece handle=/backup/oraback/bk_100_1_1014040596 tag=TAG20190719T135636
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:16
Finished restore at 19-JUL-19

RMAN> recover pluggable database mpdb02;

Starting recover at 19-JUL-19
using channel ORA_DISK_1

starting media recovery
media recovery complete, elapsed time: 00:00:02

Finished recover at 19-JUL-19

資料檢查

SQL> alter session set container=mpdb02;

Session altered.

SQL> select * from t_for_back
  2  ;

         A
----------
         1

SQL> select * from t19071901;

         A
----------
         1

###########################################################################

下面用rman只備份cdb
RMAN> backup database root FORMAT '/backup/oraback/bk_%s_%p_%t';

Starting backup at 19-JUL-19
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=/u02/app/oracle/oradata/MCDB/datafile/o1_mf_system_gkmjqb8y_.dbf
input datafile file number=00003 name=/u02/app/oracle/oradata/MCDB/datafile/o1_mf_sysaux_gkmjt28w_.dbf
input datafile file number=00004 name=/u02/app/oracle/oradata/MCDB/datafile/o1_mf_undotbs1_gkmjvjz7_.dbf
input datafile file number=00007 name=/u02/app/oracle/oradata/MCDB/datafile/o1_mf_users_gkmjvl3k_.dbf
channel ORA_DISK_1: starting piece 1 at 19-JUL-19
channel ORA_DISK_1: finished piece 1 at 19-JUL-19
piece handle=/backup/oraback/bk_102_1_1014042002 tag=TAG20190719T142002 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:16
Finished backup at 19-JUL-19

Starting Control File and SPFILE Autobackup at 19-JUL-19
piece handle=/u02/app/oracle/products/12.2.0.1/db_1/dbs/c-3951895183-20190719-02 comment=NONE
Finished Control File and SPFILE Autobackup at 19-JUL-19


SQL> shutdown abort
ORACLE instance shut down.
SQL>
SQL>
SQL>
SQL> startup
ORACLE instance started.

Total System Global Area 1191182336 bytes
Fixed Size                  8792104 bytes
Variable Size             436209624 bytes
Database Buffers          738197504 bytes
Redo Buffers                7983104 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 1 - see DBWR trace file
ORA-01110: data file 1:
'/u02/app/oracle/oradata/MCDB/datafile/o1_mf_system_gkmjqb8y_.dbf'


SQL> select status from v$instance;

STATUS
------------------------------------
MOUNTED

RMAN> restore database root;

Starting restore at 19-JUL-19
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=42 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 /u02/app/oracle/oradata/MCDB/datafile/o1_mf_system_gkmjqb8y_.dbf
channel ORA_DISK_1: restoring datafile 00003 to /u02/app/oracle/oradata/MCDB/datafile/o1_mf_sysaux_gkmjt28w_.dbf
channel ORA_DISK_1: restoring datafile 00004 to /u02/app/oracle/oradata/MCDB/datafile/o1_mf_undotbs1_gkmjvjz7_.dbf
channel ORA_DISK_1: restoring datafile 00007 to /u02/app/oracle/oradata/MCDB/datafile/o1_mf_users_gkmjvl3k_.dbf
channel ORA_DISK_1: reading from backup piece /backup/oraback/bk_102_1_1014042002
channel ORA_DISK_1: piece handle=/backup/oraback/bk_102_1_1014042002 tag=TAG20190719T142002
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:15
Finished restore at 19-JUL-19

RMAN> recover database root;

Starting recover at 19-JUL-19
using channel ORA_DISK_1

starting media recovery
media recovery complete, elapsed time: 00:00:01

Finished recover at 19-JUL-19

RMAN> alter database open;

Statement processed

BACKUP DATABASE;
會備份所有的CDB和PDB

BACKUP DATABASE root;
只備份CDB

BACKUP DATABASE pdb01,pdb02;
備份指定的PDB



來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/31480688/viewspace-2651129/,如需轉載,請註明出處,否則將追究法律責任。

相關文章