2017-08-03 00:324620原创Oracle 12c编辑删除
本文链接:https://www.cndba.cn/leo1990/article/2045
概念
A CDB consists of zero or more PDBs. Recovery Manager (RMAN) can backup the entire CDB and single or multiple PDBs to a consistent point-in-time. In addition, individual tablespaces or data files can be backed up from specific PDBs.
一个CDB由零个或多个PDBs组成。恢复管理器(RMAN)可以将整个CDB和单个或多个PDBs备份到一个一致的时间点。此外,可以从特定的PDBs备份个人的表空间或数据文件。
New syntax, PLUGGABLE DATABASE, is introduced to support individual pluggable database backup and recovery.
新的语法,可插入的数据库,被引入来支持个人可插入数据库的备份和恢复。
CDB users need backup and recovery facilities for the new pluggable database model.
CDB用户需要为新的可插入数据库模型提供备份和恢复功能。
实验
1)备份CDB
RMAN的连接使用OS身份验证。这意味着您将使用“AS SYSDBA”特权连接到CDB中的根容器。
[oracle@dg1 ~]$ rman target /
Recovery Manager: Release 12.2.0.1.0 - Production on Wed Aug 2 17:17:33 2017
Copyright (c) 1982, 2017, Oracle and/or its affiliates. All rights reserved.
connected to target database: CNDBA (DBID=211273844)
或者 sys 用户连接
[oracle@dg1 ~]$ rman target sys$pdbcndba
Recovery Manager: Release 12.2.0.1.0 - Production on Wed Aug 2 22:14:17 2017
Copyright (c) 1982, 2017, Oracle and/or its affiliates. All rights reserved.
target database Password:
connected to target database: CNDBA (DBID=211273844)
上述备份命令的输出部分如下所示。注意,备份中包含了与CBD(cdb1)和所有PDBs(pdb1、pdb2、pdb $ seed)相关的数据文件。
RMAN> backup database;
Starting backup at 02-AUG-17
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=59 device type=DISK
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=/u01/app/oracle/oradata/cndba/system01.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/cndba/sysaux01.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/cndba/undotbs01.dbf
input datafile file number=00007 name=/u01/app/oracle/oradata/cndba/users01.dbf
channel ORA_DISK_1: starting piece 1 at 02-AUG-17
channel ORA_DISK_1: finished piece 1 at 02-AUG-17
piece handle=/u01/app/oracle/product/12.1.0/db_1/dbs/04satk1p_1_1 tag=TAG20170802T171745 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:02:35
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00010 name=/u01/app/oracle/oradata/cndba/pdbcndba/sysaux01.dbf
input datafile file number=00009 name=/u01/app/oracle/oradata/cndba/pdbcndba/system01.dbf
input datafile file number=00011 name=/u01/app/oracle/oradata/cndba/pdbcndba/undotbs01.dbf
input datafile file number=00012 name=/u01/app/oracle/oradata/cndba/pdbcndba/users01.dbf
channel ORA_DISK_1: starting piece 1 at 02-AUG-17
channel ORA_DISK_1: finished piece 1 at 02-AUG-17
piece handle=/u01/app/oracle/product/12.1.0/db_1/dbs/05satk6l_1_1 tag=TAG20170802T171745 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:15
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00017 name=/u01/app/oracle/oradata/cndba/pdbcndba2/sysaux01.dbf
input datafile file number=00016 name=/u01/app/oracle/oradata/cndba/pdbcndba2/system01.dbf
input datafile file number=00018 name=/u01/app/oracle/oradata/cndba/pdbcndba2/undotbs01.dbf
channel ORA_DISK_1: starting piece 1 at 02-AUG-17
channel ORA_DISK_1: finished piece 1 at 02-AUG-17
piece handle=/u01/app/oracle/product/12.1.0/db_1/dbs/06satk90_1_1 tag=TAG20170802T171745 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:05
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00006 name=/u01/app/oracle/oradata/cndba/pdbseed/sysaux01.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/cndba/pdbseed/system01.dbf
input datafile file number=00008 name=/u01/app/oracle/oradata/cndba/pdbseed/undotbs01.dbf
channel ORA_DISK_1: starting piece 1 at 02-AUG-17
channel ORA_DISK_1: finished piece 1 at 02-AUG-17
piece handle=/u01/app/oracle/product/12.1.0/db_1/dbs/07satkb1_1_1 tag=TAG20170802T171745 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:55
Finished backup at 02-AUG-17
2)备份 Root Container
Root Container的备份是CDB的备份,不包括任何PDBs。
Starting Control File and SPFILE Autobackup at 02-AUG-17
piece handle=/u01/app/oracle/product/12.1.0/db_1/dbs/c-211273844-20170802-00 comment=NONE
Finished Control File and SPFILE Autobackup at 02-AUG-17
[oracle@dg1 ~]$ rman target /
Recovery Manager: Release 12.2.0.1.0 - Production on Wed Aug 2 17:30:12 2017
Copyright (c) 1982, 2017, Oracle and/or its affiliates. All rights reserved.
connected to target database: CNDBA (DBID=211273844)
RMAN> backup database root;
下面的命令输出中只备份CDB,PDBs (pdb1, pdb2, pdb$seed) 都没有备份
Starting backup at 02-AUG-17
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=61 device type=DISK
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=/u01/app/oracle/oradata/cndba/system01.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/cndba/sysaux01.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/cndba/undotbs01.dbf
input datafile file number=00007 name=/u01/app/oracle/oradata/cndba/users01.dbf
channel ORA_DISK_1: starting piece 1 at 02-AUG-17
channel ORA_DISK_1: finished piece 1 at 02-AUG-17
piece handle=/u01/app/oracle/product/12.1.0/db_1/dbs/09satkpq_1_1 tag=TAG20170802T173034 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:35
Finished backup at 02-AUG-17
Starting Control File and SPFILE Autobackup at 02-AUG-17
piece handle=/u01/app/oracle/product/12.1.0/db_1/dbs/c-211273844-20170802-01 comment=NONE
Finished Control File and SPFILE Autobackup at 02-AUG-17
3)备份PDB
--有两种备份PDB数据库的方法。当连接到RMAN作为根容器时,您可以使用以下命令备份一个或多个PDBs。
[oracle@dg1 ~]$ rman target /
Recovery Manager: Release 12.2.0.1.0 - Production on Wed Aug 2 17:42:48 2017
Copyright (c) 1982, 2017, Oracle and/or its affiliates. All rights reserved.
connected to target database: CNDBA (DBID=211273844)
RMAN> backup pluggable database PDBCNDBA,PDBCNDBA2;
可以看到多个PDB 的数据文件
Starting backup at 02-AUG-17
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=70 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00010 name=/u01/app/oracle/oradata/cndba/pdbcndba/sysaux01.dbf
input datafile file number=00009 name=/u01/app/oracle/oradata/cndba/pdbcndba/system01.dbf
input datafile file number=00011 name=/u01/app/oracle/oradata/cndba/pdbcndba/undotbs01.dbf
input datafile file number=00012 name=/u01/app/oracle/oradata/cndba/pdbcndba/users01.dbf
channel ORA_DISK_1: starting piece 1 at 02-AUG-17
channel ORA_DISK_1: finished piece 1 at 02-AUG-17
piece handle=/u01/app/oracle/product/12.1.0/db_1/dbs/0bsatlhb_1_1 tag=TAG20170802T174307 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:06
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00017 name=/u01/app/oracle/oradata/cndba/pdbcndba2/sysaux01.dbf
input datafile file number=00016 name=/u01/app/oracle/oradata/cndba/pdbcndba2/system01.dbf
input datafile file number=00018 name=/u01/app/oracle/oradata/cndba/pdbcndba2/undotbs01.dbf
channel ORA_DISK_1: starting piece 1 at 02-AUG-17
channel ORA_DISK_1: finished piece 1 at 02-AUG-17
piece handle=/u01/app/oracle/product/12.1.0/db_1/dbs/0csatljd_1_1 tag=TAG20170802T174307 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:45
Finished backup at 02-AUG-17
Starting Control File and SPFILE Autobackup at 02-AUG-17
piece handle=/u01/app/oracle/product/12.1.0/db_1/dbs/c-211273844-20170802-02 comment=NONE
Finished Control File and SPFILE Autobackup at 02-AUG-17
连接到特定的PDB使用以下命令
sys 用户连接pdb
[oracle@dg1 ~]$ rman target sys@pdbcndba
Recovery Manager: Release 12.2.0.1.0 - Production on Wed Aug 2 22:21:23 2017
Copyright (c) 1982, 2017, Oracle and/or its affiliates. All rights reserved.
target database Password:
connected to target database: CNDBA:PDBCNDBA (DBID=2565515280)
或者拥有sysdba 权限的用户test连接pdb
[oracle@dg1 ~]$ rman target test@pdbcndba
Recovery Manager: Release 12.2.0.1.0 - Production on Wed Aug 2 22:22:19 2017
Copyright (c) 1982, 2017, Oracle and/or its affiliates. All rights reserved.
target database Password:
connected to target database: CNDBA:PDBCNDBA (DBID=2565515280)
RMAN> backup database;
只备份当前连接的PDB的数据文件
Starting backup at 02-AUG-17
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=61 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00010 name=/u01/app/oracle/oradata/cndba/pdbcndba/sysaux01.dbf
input datafile file number=00009 name=/u01/app/oracle/oradata/cndba/pdbcndba/system01.dbf
input datafile file number=00011 name=/u01/app/oracle/oradata/cndba/pdbcndba/undotbs01.dbf
input datafile file number=00012 name=/u01/app/oracle/oradata/cndba/pdbcndba/users01.dbf
channel ORA_DISK_1: starting piece 1 at 02-AUG-17
channel ORA_DISK_1: finished piece 1 at 02-AUG-17
piece handle=/u01/app/oracle/product/12.1.0/db_1/dbs/0fsau5rd_1_1 tag=TAG20170802T222133 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:35
Finished backup at 02-AUG-17
4) 备份PDB表空间和数据文件
同一个CDB中的多个PDBs可以拥有一个具有相同名称的表空间,例如系统、SYSAUX和用户。消除这种歧义的一种方法是连接到适当的PDB。当RMAN连接到PDB时,与以前的版本相比,表空间备份命令是不变的。
[oracle@dg1 ~]$ rman target sys@pdbcndba
Recovery Manager: Release 12.2.0.1.0 - Production on Wed Aug 2 22:36:59 2017
Copyright (c) 1982, 2017, Oracle and/or its affiliates. All rights reserved.
target database Password:
connected to target database: CNDBA:PDBCNDBA (DBID=2565515280)
RMAN> BACKUP TABLESPACE system, sysaux, users;
Starting backup at 02-AUG-17
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=61 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00010 name=/u01/app/oracle/oradata/cndba/pdbcndba/sysaux01.dbf
input datafile file number=00009 name=/u01/app/oracle/oradata/cndba/pdbcndba/system01.dbf
input datafile file number=00012 name=/u01/app/oracle/oradata/cndba/pdbcndba/users01.dbf
channel ORA_DISK_1: starting piece 1 at 02-AUG-17
channel ORA_DISK_1: finished piece 1 at 02-AUG-17
piece handle=/u01/app/oracle/product/12.1.0/db_1/dbs/0hsau6op_1_1 tag=TAG20170802T223713 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:45
Finished backup at 02-AUG-17
RMAN> exit
或者,您可以通过在连接到根容器时将PDB名称与表空间名称进行限定,从而消除歧义。
Recovery Manager complete.
[oracle@dg1 ~]$ rman target sys@cndba
Recovery Manager: Release 12.2.0.1.0 - Production on Wed Aug 2 22:38:07 2017
Copyright (c) 1982, 2017, Oracle and/or its affiliates. All rights reserved.
target database Password:
connected to target database: CNDBA (DBID=211273844)
RMAN> BACKUP TABLESPACE pdbcndba:system, pdbcndba:sysaux, pdbcndba:users, pdbcndba2:system;
Starting backup at 02-AUG-17
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=23 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00010 name=/u01/app/oracle/oradata/cndba/pdbcndba/sysaux01.dbf
input datafile file number=00009 name=/u01/app/oracle/oradata/cndba/pdbcndba/system01.dbf
input datafile file number=00012 name=/u01/app/oracle/oradata/cndba/pdbcndba/users01.dbf
channel ORA_DISK_1: starting piece 1 at 02-AUG-17
channel ORA_DISK_1: finished piece 1 at 02-AUG-17
piece handle=/u01/app/oracle/product/12.1.0/db_1/dbs/0isau6s4_1_1 tag=TAG20170802T223900 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:35
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=/u01/app/oracle/oradata/cndba/pdbcndba2/system01.dbf
channel ORA_DISK_1: starting piece 1 at 02-AUG-17
channel ORA_DISK_1: finished piece 1 at 02-AUG-17
piece handle=/u01/app/oracle/product/12.1.0/db_1/dbs/0jsau6t8_1_1 tag=TAG20170802T223900 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:25
Finished backup at 02-AUG-17
Starting Control File and SPFILE Autobackup at 02-AUG-17
piece handle=/u01/app/oracle/product/12.1.0/db_1/dbs/c-211273844-20170802-03 comment=NONE
Finished Control File and SPFILE Autobackup at 02-AUG-17
数据文件具有唯一的文件编号和完全限定的名称,因此它们可以从根容器或单个PDB备份。
$ rman target=/
或者
[oracle@dg1 ~]$ rman target sys@pdbcndba
Recovery Manager: Release 12.2.0.1.0 - Production on Wed Aug 2 22:48:29 2017
Copyright (c) 1982, 2017, Oracle and/or its affiliates. All rights reserved.
target database Password:
connected to target database: CNDBA:PDBCNDBA (DBID=2565515280)
RMAN> backup datafile 9,10;
Starting backup at 02-AUG-17
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=69 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00010 name=/u01/app/oracle/oradata/cndba/pdbcndba/sysaux01.dbf
input datafile file number=00009 name=/u01/app/oracle/oradata/cndba/pdbcndba/system01.dbf
channel ORA_DISK_1: starting piece 1 at 02-AUG-17
channel ORA_DISK_1: finished piece 1 at 02-AUG-17
piece handle=/u01/app/oracle/product/12.1.0/db_1/dbs/0lsau7ee_1_1 tag=TAG20170802T224846 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:35
Finished backup at 02-AUG-17
如果您正在连接到PDB,那么只有属于PDB的文件才能备份。例如,当连接为PDBCNDBA时,如果尝试从根容器中备份系统数据文件,就会出现错误。
[oracle@dg1 ~]$ rman target sys@pdbcndba
Recovery Manager: Release 12.2.0.1.0 - Production on Wed Aug 2 22:41:09 2017
Copyright (c) 1982, 2017, Oracle and/or its affiliates. All rights reserved.
target database Password:
connected to target database: CNDBA:PDBCNDBA (DBID=2565515280)
RMAN> BACKUP DATAFILE 1;
Starting backup at 02-AUG-17
using channel ORA_DISK_1
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of backup command at 08/02/2017 22:43:25
RMAN-20201: datafile not found in the recovery catalog
RMAN-06010: error while looking up datafile: 1