Oracle 12c: RMAN restore/recover pluggable database

时间:2021-12-03 21:42:11

查看数据库状态

运行在归档模式,可拔插数据库name=pdborcl

SQL> archive log list;
Database log mode           Archive Mode
Automatic archival           Enabled
Archive destination           USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     24
Next log sequence to archive   26
Current log sequence           26
SQL> alter pluggable database all open;

Pluggable database altered.

SQL> show pdbs;

    CON_ID CON_NAME              OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
     2 PDB$SEED              READ ONLY  NO
     3 PDBORCL              READ WRITE NO


SQL> alter session set container=pdborcl;

Session altered.

SQL> select * from scott.dept;

    DEPTNO DNAME      LOC
---------- -------------- -------------
    10 ACCOUNTING      NEW YORK
    20 RESEARCH      DALLAS
    30 SALES      CHICAGO
    40 OPERATIONS      BOSTON

rman连接cdb,备份整个数据库

run{

allocate channel C1 device type disk format  '/home/oracle/backup/full_db_%U';

backup database include current controlfile plus archivelog  ;

release  channel C1 ;

}

crosscheck backupset;

delete noprompt  obsolete;

或者

backup database include current controlfile format  '/home/oracle/backup/full_db_%U'  plus archivelog  format  '/home/oracle/backup/full_db_%U';

结果如下:

RMAN> backup database include current controlfile format  '/home/oracle/backup/full_db_%U'  plus archivelog  format  '/home/oracle/backup/full_db_%U';


Starting backup at 05-JAN-16
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=45 RECID=20 STAMP=900344286
input archived log thread=1 sequence=46 RECID=21 STAMP=900344420
channel ORA_DISK_1: starting piece 1 at 05-JAN-16
channel ORA_DISK_1: finished piece 1 at 05-JAN-16
piece handle=/home/oracle/backup/full_db_27qqkaj4_1_1 tag=TAG20160105T154020 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 05-JAN-16

Starting backup at 05-JAN-16
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=/data/app/oracle/oradata/orcl/system01.dbf input datafile file number=00003 name=/data/app/oracle/oradata/orcl/sysaux01.dbf input datafile file number=00004 name=/data/app/oracle/oradata/orcl/undotbs01.dbf input datafile file number=00006 name=/data/app/oracle/oradata/orcl/users01.dbf
channel ORA_DISK_1: starting piece 1 at 05-JAN-16
channel ORA_DISK_1: finished piece 1 at 05-JAN-16
piece handle=/home/oracle/backup/full_db_28qqkaj5_1_1 tag=TAG20160105T154021 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:07
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00009 name=/data/app/oracle/oradata/orcl/pdborcl/sysaux01.dbf input datafile file number=00008 name=/data/app/oracle/oradata/orcl/pdborcl/system01.dbf input datafile file number=00010 name=/data/app/oracle/oradata/orcl/pdborcl/pdborcl_users01.dbf
channel ORA_DISK_1: starting piece 1 at 05-JAN-16
channel ORA_DISK_1: finished piece 1 at 05-JAN-16
piece handle=/home/oracle/backup/full_db_29qqkajc_1_1 tag=TAG20160105T154021 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00007 name=/data/app/oracle/oradata/orcl/pdbseed/sysaux01.dbf input datafile file number=00005 name=/data/app/oracle/oradata/orcl/pdbseed/system01.dbf
channel ORA_DISK_1: starting piece 1 at 05-JAN-16
channel ORA_DISK_1: finished piece 1 at 05-JAN-16
piece handle=/home/oracle/backup/full_db_2aqqkajg_1_1 tag=TAG20160105T154021 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:07
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
channel ORA_DISK_1: starting piece 1 at 05-JAN-16
channel ORA_DISK_1: finished piece 1 at 05-JAN-16
piece handle=/home/oracle/backup/full_db_2bqqkajn_1_1 tag=TAG20160105T154021 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 05-JAN-16

Starting backup at 05-JAN-16
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=47 RECID=22 STAMP=900344441
channel ORA_DISK_1: starting piece 1 at 05-JAN-16
channel ORA_DISK_1: finished piece 1 at 05-JAN-16
piece handle=/home/oracle/backup/full_db_2cqqkajp_1_1 tag=TAG20160105T154041 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 05-JAN-16

Starting Control File and SPFILE Autobackup at 05-JAN-16
piece handle=/data/app/oracle/recovery_area/ORCL/autobackup/2016_01_05/o1_mf_s_900344442_c8pwvtqb_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 05-JAN-16

RMAN>

7个piece,一个属于CDB,一个PDB$SEED,一个PDBORCL, 2个archivelog,1个current contrilfile ,还有1个默认的Control File and SPFILE Autobackup

rman连接cdb,备份指定pdb

连接

[oracle@xqzt ~]$ rman target /

备份

backup pluggable database pdborcl include current controlfile format '/home/oracle/backup/full_db_%U' plus archivelog

结果

RMAN> list backup ;


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


BS Key  Size       Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
81      209.50K    DISK        00:00:00     05-JAN-16      
        BP Key: 81   Status: AVAILABLE  Compressed: NO  Tag: TAG20160105T155733
        Piece Name: /data/app/oracle/recovery_area/ORCL/backupset/2016_01_05/o1_mf_annnn_TAG20160105T155733_c8pxvfww_.bkp

  List of Archived Logs in backup set 81
  Thrd Seq     Low SCN    Low Time  Next SCN   Next Time
  ---- ------- ---------- --------- ---------- ---------
  1    45      2804981    05-JAN-16 2805000    05-JAN-16
  1    46      2805000    05-JAN-16 2805165    05-JAN-16
  1    47      2805165    05-JAN-16 2805184    05-JAN-16
  1    48      2805184    05-JAN-16 2805762    05-JAN-16

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
82      Full    675.54M    DISK        00:00:00     05-JAN-16      
        BP Key: 82   Status: AVAILABLE  Compressed: NO  Tag: TAG20160105T155735
        Piece Name: /home/oracle/backup/full_db_2iqqkbjf_1_1
  List of Datafiles in backup set 82
  Container ID: 3, PDB Name: PDBORCL
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  8       Full 2805770    05-JAN-16 /data/app/oracle/oradata/orcl/pdborcl/system01.dbf
  9       Full 2805770    05-JAN-16 /data/app/oracle/oradata/orcl/pdborcl/sysaux01.dbf
  10      Full 2805770    05-JAN-16 /data/app/oracle/oradata/orcl/pdborcl/pdborcl_users01.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
83      Full    17.17M     DISK        00:00:01     05-JAN-16      
        BP Key: 83   Status: AVAILABLE  Compressed: NO  Tag: TAG20160105T155735
        Piece Name: /home/oracle/backup/full_db_2jqqkbjm_1_1
  Control File Included: Ckp SCN: 2805772      Ckp time: 05-JAN-16

BS Key  Size       Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
84      3.00K      DISK        00:00:00     05-JAN-16      
        BP Key: 84   Status: AVAILABLE  Compressed: NO  Tag: TAG20160105T155744
        Piece Name: /data/app/oracle/recovery_area/ORCL/backupset/2016_01_05/o1_mf_annnn_TAG20160105T155744_c8pxvrg2_.bkp

  List of Archived Logs in backup set 84
  Thrd Seq     Low SCN    Low Time  Next SCN   Next Time
  ---- ------- ---------- --------- ---------- ---------
  1    49      2805762    05-JAN-16 2805777    05-JAN-16

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
85      Full    17.20M     DISK        00:00:00     05-JAN-16      
        BP Key: 85   Status: AVAILABLE  Compressed: NO  Tag: TAG20160105T155745
        Piece Name: /data/app/oracle/recovery_area/ORCL/autobackup/2016_01_05/o1_mf_s_900345465_c8pxvsq8_.bkp
  SPFILE Included: Modification time: 05-JAN-16
  SPFILE db_unique_name: ORCL
  Control File Included: Ckp SCN: 2805786      Ckp time: 05-JAN-16

rman连接pdb,备份pdb数据库

配置pdborcl的tns

PDBORCL =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = xqzt)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME =pdborcl)
    )
  )

rman 连接pdborcl

rman target sys/wangshengzhuang@pdborcl

开始备份

RMAN> backup database include current controlfile format  '/home/oracle/backup/full_db_%U'  plus archivelog  format  '/home/oracle/backup/full_db_%U';


Starting backup at 05-JAN-16
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=60 device type=DISK
specification does not match any archived log in the repository
backup cancelled because there are no files to backup
Finished backup at 05-JAN-16

Starting backup at 05-JAN-16
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=00009 name=/data/app/oracle/oradata/orcl/pdborcl/sysaux01.dbf
input datafile file number=00008 name=/data/app/oracle/oradata/orcl/pdborcl/system01.dbf
input datafile file number=00010 name=/data/app/oracle/oradata/orcl/pdborcl/pdborcl_users01.dbf
channel ORA_DISK_1: starting piece 1 at 05-JAN-16
channel ORA_DISK_1: finished piece 1 at 05-JAN-16
piece handle=/home/oracle/backup/full_db_2eqqkb6b_1_1 tag=TAG20160105T155035 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:07
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
channel ORA_DISK_1: starting piece 1 at 05-JAN-16
channel ORA_DISK_1: finished piece 1 at 05-JAN-16
piece handle=/home/oracle/backup/full_db_2fqqkb6i_1_1 tag=TAG20160105T155035 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 05-JAN-16

Starting backup at 05-JAN-16
using channel ORA_DISK_1
specification does not match any archived log in the repository
backup cancelled because there are no files to backup
Finished backup at 05-JAN-16

Starting Control File and SPFILE Autobackup at 05-JAN-16
piece handle=/data/app/oracle/recovery_area/ORCL/autobackup/2016_01_05/o1_mf_s_900345045_c8pxgo7c_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 05-JAN-16

结果如下:

RMAN> list backup;


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


BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
78      Full    675.54M    DISK        00:00:01     05-JAN-16      
        BP Key: 78   Status: AVAILABLE  Compressed: NO  Tag: TAG20160105T155035
        Piece Name: /home/oracle/backup/full_db_2eqqkb6b_1_1
  List of Datafiles in backup set 78
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  8       Full 2805476    05-JAN-16 /data/app/oracle/oradata/orcl/pdborcl/system01.dbf
  9       Full 2805476    05-JAN-16 /data/app/oracle/oradata/orcl/pdborcl/sysaux01.dbf
  10      Full 2805476    05-JAN-16 /data/app/oracle/oradata/orcl/pdborcl/pdborcl_users01.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
79      Full    17.17M     DISK        00:00:01     05-JAN-16      
        BP Key: 79   Status: AVAILABLE  Compressed: NO  Tag: TAG20160105T155035
        Piece Name: /home/oracle/backup/full_db_2fqqkb6i_1_1
  Control File Included: Ckp SCN: 2805478      Ckp time: 05-JAN-16

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
80      Full    17.20M     DISK        00:00:00     05-JAN-16      
        BP Key: 80   Status: AVAILABLE  Compressed: NO  Tag: TAG20160105T155045
        Piece Name: /data/app/oracle/recovery_area/ORCL/autobackup/2016_01_05/o1_mf_s_900345045_c8pxgo7c_.bkp
  SPFILE Included: Modification time: 05-JAN-16
  SPFILE db_unique_name: ORCL
  Control File Included: Ckp SCN: 2805489      Ckp time: 05-JAN-16

RMAN>

模拟pdb库全库恢复

首先删除一个数据文件

SQL> !rm /data/app/oracle/oradata/orcl/pdborcl/pdborcl_users01.dbf

打开pdborcl,报错如下

SQL> alter pluggable database pdborcl open;
alter pluggable database pdborcl open
*
ERROR at line 1:
ORA-01157: cannot identify/lock data file 10 - see DBWR trace file
ORA-01110: data file 10:
'/data/app/oracle/oradata/orcl/pdborcl/pdborcl_users01.dbf'

基于cdb恢复pdb库

连接rman

[oracle@xqzt ~]$ rman target /

restore pdborcl

RMAN> restore pluggable database pdborcl;

Starting restore at 05-JAN-16
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=46 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 00008 to /data/app/oracle/oradata/orcl/pdborcl/system01.dbf
channel ORA_DISK_1: restoring datafile 00009 to /data/app/oracle/oradata/orcl/pdborcl/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00010 to /data/app/oracle/oradata/orcl/pdborcl/pdborcl_users01.dbf
channel ORA_DISK_1: reading from backup piece /home/oracle/backup/full_db_2iqqkbjf_1_1
channel ORA_DISK_1: piece handle=/home/oracle/backup/full_db_2iqqkbjf_1_1 tag=TAG20160105T155735
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:03
Finished restore at 05-JAN-16

RMAN>

recover pdborcl

RMAN> recover pluggable database pdborcl;

Starting recover at 05-JAN-16
using channel ORA_DISK_1

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

Finished recover at 05-JAN-16

尝试打开数据库

RMAN> alter pluggable database pdborcl open;

Statement processed

 

如果rman 连接pdborcl,执行resotre pluggable database pdborcl 会报错如下

[oracle@xqzt ~]$ rman target sys/wangshengzhuang@pdborcl

Recovery Manager: Release 12.1.0.2.0 - Production on Tue Jan 5 16:17:23 2016

Copyright (c) 1982, 2014, Oracle and/or its affiliates.  All rights reserved.

connected to target database: ORCL (DBID=1422060754, not open)

RMAN> restore pluggable database pdborcl;

Starting restore at 05-JAN-16
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=51 device type=DISK
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 01/05/2016 16:17:47
RMAN-07538: Pluggable Database qualifier not allowed when connected to a Pluggable Database