Skip to content
Home » Oracle » How to Backup PDB Tablespace

How to Backup PDB Tablespace

Backup Tablespace Normally

Since tablespace is a logical set of data files, it's allowable to have same name tablespaces in different pluggable databases (PDB). Therefore, directly backing up a tablespace from a PDB cannot be done by the normal way.

[oracle@test ~]$ rman target /
...
connected to target database: ORCLCDB (DBID=3411734329)

RMAN> backup tablespace example;

Starting backup at 28-JAN-20
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=1725 device type=DISK
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of backup command at 01/28/2020 02:34:22
RMAN-20202: Tablespace not found in the recovery catalog
RMAN-06019: could not translate tablespace name "EXAMPLE"

As you can see, the backup failed. This is because the tablespace name cannot be found in the current container.

Solutions to Backup PDB Tablespace

There're several ways to backup a tablespace from a PDB.

  1. Prefix the PDB Name
  2. Set ORACLE_PDB_SID
  3. Connect to PDB Directly

We talk about them respectively below:

1. Prefix the PDB Name

We prefix the PDB name to the tablespace name.

RMAN> backup tablespace orclpdb:example;

Starting backup at 28-JAN-20
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=00013 name=/u01/app/oracle/oradata/ORCLCDB/ORCLPDB/example01.dbf
input datafile file number=00014 name=/u01/app/oracle/oradata/ORCLCDB/ORCLPDB/example02.dbf
input datafile file number=00015 name=/u01/app/oracle/oradata/ORCLCDB/ORCLPDB/example03.dbf
input datafile file number=00016 name=/u01/app/oracle/oradata/ORCLCDB/ORCLPDB/example04.dbf
channel ORA_DISK_1: starting piece 1 at 28-JAN-20
channel ORA_DISK_1: finished piece 1 at 28-JAN-20
piece handle=/u01/app/oracle/fast_recovery_area/ORCLCDB/AA736F65D66215CCE053992AA8C08959/backupset/2020_01_28/o1_mf_nnndf_TAG20200128T023458_j14t92co_.bkp tag=TAG20200128T023458 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
Finished backup at 28-JAN-20

Starting Control File and SPFILE Autobackup at 28-JAN-20
piece handle=/u01/app/oracle/fast_recovery_area/ORCLCDB/autobackup/2020_01_28/o1_mf_s_1062988501_j14t95nb_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 28-JAN-20

Although we connect to the container database, we have backed up 4 files from the PDB's tablespace.

For multiple tablespaces from different PDB, we should use comma (,) to delimit them. For example:

RMAN> backup tablespace erppdb:tbs1, crmpdb:tbs1;

2. Set ORACLE_PDB_SID

Since 18c and 19c, we can connect to PDB directly through OS authentication by setting ORACLE_PDB_SID, an environment variable recognized by Oracle database.

[oracle@test ~]$ export ORACLE_PDB_SID=ORCLPDB
[oracle@test ~]$ echo $ORACLE_PDB_SID
ORCLPDB
[oracle@test ~]$ rman target /
...
connected to target database: ORCLCDB:ORCLPDB (DBID=4210091183)

RMAN> backup tablespace example;

Starting backup at 28-JAN-20
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=588 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=00013 name=/u01/app/oracle/oradata/ORCLCDB/ORCLPDB/example01.dbf
input datafile file number=00014 name=/u01/app/oracle/oradata/ORCLCDB/ORCLPDB/example02.dbf
input datafile file number=00015 name=/u01/app/oracle/oradata/ORCLCDB/ORCLPDB/example03.dbf
input datafile file number=00016 name=/u01/app/oracle/oradata/ORCLCDB/ORCLPDB/example04.dbf
channel ORA_DISK_1: starting piece 1 at 28-JAN-20
channel ORA_DISK_1: finished piece 1 at 28-JAN-20
piece handle=/u01/app/oracle/fast_recovery_area/ORCLCDB/AA736F65D66215CCE053992AA8C08959/backupset/2020_01_28/o1_mf_nnndf_TAG20200128T024939_j14v4mg4_.bkp tag=TAG20200128T024939 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 28-JAN-20

This is extremely convenient for daily backup by shell scripts, no password is needed to enter.

3. Connect to PDB Directly

This time we don't use OS authentication to access the database, instead, we connect to the PDB via listener.

[oracle@test ~]$ rman target sys/password@orclpdb
...
connected to target database: ORCLCDB:ORCLPDB (DBID=4210091183)

RMAN> backup tablespace example;

Starting backup at 28-JAN-20
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=1725 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=00013 name=/u01/app/oracle/oradata/ORCLCDB/ORCLPDB/example01.dbf
input datafile file number=00014 name=/u01/app/oracle/oradata/ORCLCDB/ORCLPDB/example02.dbf
input datafile file number=00015 name=/u01/app/oracle/oradata/ORCLCDB/ORCLPDB/example03.dbf
input datafile file number=00016 name=/u01/app/oracle/oradata/ORCLCDB/ORCLPDB/example04.dbf
channel ORA_DISK_1: starting piece 1 at 28-JAN-20
channel ORA_DISK_1: finished piece 1 at 28-JAN-20
piece handle=/u01/app/oracle/fast_recovery_area/ORCLCDB/AA736F65D66215CCE053992AA8C08959/backupset/2020_01_28/o1_mf_nnndf_TAG20200128T024759_j14v1j1t_.bkp tag=TAG20200128T024759 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 28-JAN-20

Since we are in the PDB, so RMAN knows what data files should be backed up.

Leave a Reply

Your email address will not be published. Required fields are marked *