首页 > 代码库 > Oracle 12c 多租户 CDB 与 PDB 备份

Oracle 12c 多租户 CDB 与 PDB 备份

一、  CDB 备份

1.1  只备份CDB

只备份CDB数据库需要具有SYSDBA或SYSBACKUP权限用户连接到CDB的root环境下,执行backupdatabase root命令即可完成对CDB的备份,方法如下:
[oracle@12c01 ~]$ rman target / 
[oracle@12c01 ~]$ mkdir /home/oracle/rmanback/
RMAN> backup database root format=‘/home/oracle/rmanback/db_%d_%U‘; 
RMAN-03002: failure of backup command at 05/10/2017 23:14:58
RMAN-06817: Pluggable Database CDB$ROOT cannot be backed up in NOARCHIVELOG mode.
说明: 只备份 CDB 需要数据库在归档环境下,自行把数据设置为归档模式。
RMAN> select name,log_mode from v$database;
NAME      LOG_MODE    
--------- ------------
ANDYCDB   ARCHIVELOG  
RMAN> backup database root format=‘/home/oracle/rmanback/db_%d_%U‘; 

Starting backup at 10-MAY-17
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=/home/oracle/app/oracle/oradata/ANDYCDB/datafile/o1_mf_system_djsytx31_.dbf
input datafile file number=00003 name=/home/oracle/app/oracle/oradata/ANDYCDB/datafile/o1_mf_sysaux_djsyx1t8_.dbf
input datafile file number=00004 name=/home/oracle/app/oracle/oradata/ANDYCDB/datafile/o1_mf_undotbs1_djsyyjlk_.dbf
input datafile file number=00007 name=/home/oracle/app/oracle/oradata/ANDYCDB/datafile/o1_mf_users_djsyykpc_.dbf
channel ORA_DISK_1: starting piece 1 at 10-MAY-17
channel ORA_DISK_1: finished piece 1 at 10-MAY-17
piece handle=/home/oracle/rmanback/db_ANDYCDB_07s3u63n_1_1 tag=TAG20170510T233207 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:05
Finished backup at 10-MAY-17

Starting Control File and SPFILE Autobackup at 10-MAY-17
piece handle=/home/oracle/fast_recovery_area/ANDYCDB/autobackup/2017_05_10/o1_mf_s_943659193_dk6dosvv_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 10-MAY-17

1.2.  备份整个CDB及其下面的所有PDB
备份整个CDB数据库及其下面的所有PDB类似于非CDB数据库方法相同,使用具有SYSDBA或SYSBACKUP权限用户连接到CDB的root环境下面,然后执行backupdatabase命令即可完成整个CDB的备份,方法如下: 
RMAN> backup database format=‘/home/oracle/rmanback/db_%d_%U‘;

Starting backup at 10-MAY-17
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=/home/oracle/app/oracle/oradata/ANDYCDB/datafile/o1_mf_system_djsytx31_.dbf
input datafile file number=00003 name=/home/oracle/app/oracle/oradata/ANDYCDB/datafile/o1_mf_sysaux_djsyx1t8_.dbf
input datafile file number=00004 name=/home/oracle/app/oracle/oradata/ANDYCDB/datafile/o1_mf_undotbs1_djsyyjlk_.dbf
input datafile file number=00007 name=/home/oracle/app/oracle/oradata/ANDYCDB/datafile/o1_mf_users_djsyykpc_.dbf
channel ORA_DISK_1: starting piece 1 at 10-MAY-17
channel ORA_DISK_1: finished piece 1 at 10-MAY-17
piece handle=/home/oracle/rmanback/db_ANDYCDB_09s3u69m_1_1 tag=TAG20170510T233517 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:17
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00022 name=/home/oracle/app/oracle/oradata/ANDYCDB/4ECF8621E3DA38EEE0531019640AA598/datafile/o1_mf_sysaux_dk5wmv11_.dbf
input datafile file number=00021 name=/home/oracle/app/oracle/oradata/ANDYCDB/4ECF8621E3DA38EEE0531019640AA598/datafile/o1_mf_system_dk5wmv0s_.dbf
input datafile file number=00024 name=/home/oracle/app/oracle/oradata/ANDYCDB/4ECF8621E3DA38EEE0531019640AA598/datafile/o1_mf_undo_1_dk5wmv13_.dbf
input datafile file number=00023 name=/home/oracle/app/oracle/oradata/ANDYCDB/4ECF8621E3DA38EEE0531019640AA598/datafile/o1_mf_users_dk5wmv12_.dbf
channel ORA_DISK_1: starting piece 1 at 10-MAY-17
channel ORA_DISK_1: finished piece 1 at 10-MAY-17
piece handle=/home/oracle/rmanback/db_ANDYCDB_0as3u6c3_1_1 tag=TAG20170510T233517 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:39
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=/home/oracle/app/oracle/oradata/ANDYCDB/datafile/o1_mf_sysaux_djsz1z2x_.dbf
input datafile file number=00005 name=/home/oracle/app/oracle/oradata/ANDYCDB/datafile/o1_mf_system_djsz1z31_.dbf
input datafile file number=00008 name=/home/oracle/app/oracle/oradata/ANDYCDB/datafile/o1_mf_undotbs1_djsz1z34_.dbf
channel ORA_DISK_1: starting piece 1 at 10-MAY-17
channel ORA_DISK_1: finished piece 1 at 10-MAY-17
piece handle=/home/oracle/rmanback/db_ANDYCDB_0bs3u6da_1_1 tag=TAG20170510T233517 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:46
Finished backup at 10-MAY-17

Starting Control File and SPFILE Autobackup at 10-MAY-17
piece handle=/home/oracle/fast_recovery_area/ANDYCDB/autobackup/2017_05_10/o1_mf_s_943659480_dk6dyrlw_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 10-MAY-17 

 

二、 备份 PDB

1.1.  备份单个和多个PDB
在CDB中允许备份一个或多少PDB数据库(如果要备份多个pdb,只需在备份命令后面跟上多个你想备份的pdb实例的名称,如下backup pluggable database pdb1,pdb2; ),备份一个PDB数据库可以通过以下两个方式备份:
注意:如果没有开启归档模式,单独备份 CDB 或者是 PDB 都会报ORA-19602: cannot backup or copy active file in NOARCHIVELOG mode
方式一:在CDB根(root)使用BACKUP PLUGGABLE DATABASE命令备份一个或多个PDB数据库。 
[oracle@localhost ~]$ rman target / 
RMAN>  backup pluggable database pdb01;

Starting backup at 10-MAY-17
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=00022 name=/home/oracle/app/oracle/oradata/ANDYCDB/4ECF8621E3DA38EEE0531019640AA598/datafile/o1_mf_sysaux_dk5wmv11_.dbf
input datafile file number=00021 name=/home/oracle/app/oracle/oradata/ANDYCDB/4ECF8621E3DA38EEE0531019640AA598/datafile/o1_mf_system_dk5wmv0s_.dbf
input datafile file number=00024 name=/home/oracle/app/oracle/oradata/ANDYCDB/4ECF8621E3DA38EEE0531019640AA598/datafile/o1_mf_undo_1_dk5wmv13_.dbf
input datafile file number=00023 name=/home/oracle/app/oracle/oradata/ANDYCDB/4ECF8621E3DA38EEE0531019640AA598/datafile/o1_mf_users_dk5wmv12_.dbf
channel ORA_DISK_1: starting piece 1 at 10-MAY-17
channel ORA_DISK_1: finished piece 1 at 10-MAY-17
piece handle=/home/oracle/fast_recovery_area/ANDYCDB/4ECF8621E3DA38EEE0531019640AA598/backupset/2017_05_10/o1_mf_nnndf_TAG20170510T234055_dk6f47wq_.bkp tag=TAG20170510T234055 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:36
Finished backup at 10-MAY-17

Starting Control File and SPFILE Autobackup at 10-MAY-17
piece handle=/home/oracle/fast_recovery_area/ANDYCDB/autobackup/2017_05_10/o1_mf_s_943659691_dk6f5cpf_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 10-MAY-17
备份默认在 闪回恢复区里。

方式二:在PDB中使用BACKUP DATABASE备份当前连接的PDB数据库,前提条件是需要配置好TNSNAMES.ORA文件。 
[oracle@12c01 ~]$ rman target sys/oracle@10.100.25.16:1521/pdb01
connected to target database: ANDYCDB:PDB01 (DBID=2550500229) 
RMAN> backup database format=‘/home/oracle/rmanback/db_%d_%U‘;

Starting backup at 10-MAY-17
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=60 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=00022 name=/home/oracle/app/oracle/oradata/ANDYCDB/4ECF8621E3DA38EEE0531019640AA598/datafile/o1_mf_sysaux_dk5wmv11_.dbf
input datafile file number=00021 name=/home/oracle/app/oracle/oradata/ANDYCDB/4ECF8621E3DA38EEE0531019640AA598/datafile/o1_mf_system_dk5wmv0s_.dbf
input datafile file number=00024 name=/home/oracle/app/oracle/oradata/ANDYCDB/4ECF8621E3DA38EEE0531019640AA598/datafile/o1_mf_undo_1_dk5wmv13_.dbf
input datafile file number=00023 name=/home/oracle/app/oracle/oradata/ANDYCDB/4ECF8621E3DA38EEE0531019640AA598/datafile/o1_mf_users_dk5wmv12_.dbf
channel ORA_DISK_1: starting piece 1 at 10-MAY-17
channel ORA_DISK_1: finished piece 1 at 10-MAY-17
piece handle=/home/oracle/rmanback/db_ANDYCDB_0fs3u6tn_1_1 tag=TAG20170510T234559 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:45
Finished backup at 10-MAY-17

Oracle 12c 多租户 CDB 与 PDB 备份