Practice 13: Backup and Recovery in CDB and Pdbs
Practice 13: Backup and Recovery in CDB and Pdbs
Practice Overview
In this practice you will use RMAN to do the following:
• Take backup of the whole CDB
• Take backup of the whole PDB
• Take partial backup of a PDB
• Implement recovery procedure form SYSTEM datafile loss
• Implement recovery procedure form non-SYSTEM datafile loss
• Use the Data Recovery Advisor commands
Practice Assumptions
• CDB1 (in srv1) database is up and running.
In this section of the practice, you will perform a whole CDB backup of CDB1.
1. To reduce the backup file size, drop PDB3 including its datafiles.
Only PDB2 remains in CDB1 as a user-created PDB.
sqlplus / as sysdba
ALTER PLUGGABLE DATABASE pdb3 CLOSE IMMEDIATE;
DROP PLUGGABLE DATABASE pdb3 INCLUDING DATAFILES;
SELECT VALUE/1024/1024 MB
FROM V$PARAMETER WHERE NAME='db_recovery_file_dest_size';
3. Run RMAN and connect as target to CDB1 and make the configurations as shown below.
rman target /
CONFIGURE DEFAULT DEVICE TYPE TO disk;
CONFIGURE CONTROLFILE AUTOBACKUP ON;
4. Take backup of all the datafiles of the database (the root and all its PDBs), control files, SPFILE file,
and the archived redo log files.
This is an online backup and it requires the database to operate in archivelog mode. You already
enabled the archivelog mode in CDB1 earlier in the course.
Command execution will take a few minutes. In my case, it took slightly less than 10 minutes.
If you face the following error because the size of the FRA is nearly full:
ORA-19804: cannot reclaim ** bytes disk space from ** bytes limit
Consider deleting the archive log file using the following command:
delete archivelog all completed before 'sysdate-1';
6. Check out from the OS shell the size of the backupset files that were generated by RMAN.
# du -sh /u01/app/oracle/fra/CDB1/CDB1/backupset/
In this section of the practice, you will perform a whole and a partial PDB backup of PDB2.
10. From OS shell, check out the size of the backupset files that were generated by RMAN.
The bacupkset files will be generated in the following directory structure. You can get it from the
RMAN output.
/u01/app/oracle/fra/CDB1/CDB1/<PDB GUID>/backupset/<date>/
11. Login to RMAN again and take a backup of the tablespace users in PDB2 (partial backup).
rman target /
BACKUP TABLESPACE pdb2:users;
LIST BACKUP OF TABLESPACE pdb2:users;
Recovery procedures in CDB database is pretty much similar to them in non-CDB database. Covering all
the recovery scenarios is beyond the scope of this practice. But as an example of demonstrating a
recovery procedure in a CDB database, in this section of the practice, you will perform the recovery
procedure a SYSTEM datafile in PDB2.
If the PDB was opened when the file is lost, you need to shutdown CDB and mount it before you proceed
with the recovery procedure. The recovery procedure is similar to the traditional recovery procedure from
losing a SYSTEM datafile in the non-CDB database.
13. Delete the datafile file returned from the previous command.
host rm /u01/app/oracle/oradata/CDB1/<PDB GUID>/datafile/***.dbf
14. Execute the following DESCRIBE command. It should return error complaining that the SYSTEM
datafile cannot be opened.
DESC DBA_DATA_FILES
15. Run RMAN and connect to CDB1 and proceed with the traditional procedure to restore the missing
SYSTEM data file.
-- mount the CDB
rman target /
SHUTDOWN ABORT
STARTUP MOUNT
In this section of the practice, you will perform the recovery procedure a non-essential (non-SYSTEM)
datafile in CDB1.
In this procedure, you will use the Data Recovery Advisor commands to discover, restore and recover the
failure.
18. Delete the datafile file returned from the previous command.
host rm /u01/app/oracle/oradata/CDB1/datafile/***.dbf
19. Run RMAN and connect to CDB1 as target. Discover the failure.
If the command does not report any failure, wait for a few seconds and try again.
If the error is still not discovered, use the VALIDATE DATAFILE command.
rman target /
LIST FAILURE;
LIST FAILURE DETAIL;
20. Obtain the recommendation from the Data Recovery Advisor to remedy the issue.
ADVISE FAILURE;
Note: in real life scenario, it is always advisable to take backup of the entire CDB after such a recovery
procedure is implemented. You skip this step over here to save the disk space.
Note: do not delete the backupset files at this stage. You will still use them in the next practice.
In this section of the practice, you will perform a procedure to enable the local admin user of PDB2 to take
backup and restore its PDB.
23. In sqlplus, login to the root then switch the current container to PDB2.
sqlplus / as sysdba
ALTER SESSION SET CONTAINER=PDB2;
24. Grant SYSDBA privilege (or SYSBACKUP) to the local admin user of PDB2.
This grant will be applicable only in the current container (PDB2), not the CDB.
GRANT SYSDBA TO PDB2ADMIN;
25. Run RMAN and login as target to PDB2 using the local admin user.
rman target "pdb2admin@pdb2"
28. Issue the following command. Type NO when it prompts for deletion.
Notice that among the files that will be deleted by the command the backups the were taken by SYS.
This is technically fine because it only deletes backup of PDB2.
DELETE BACKUPSET;
29. Issue the following command to delete only the backup files created by PDB2ADMIN user. Select YES
when it prompts for deletion.
DELETE BACKUPSET TAG 'BYLOCAL';
Note: An alternative way to manage the backup and recovery in a CDB is to create a common user who
has the privilege only to backup and restore the CDB and the PDBs. Here is the code to implement that:
CREATE USER C##BACKUP IDENTIFIED BY ORACLE CONTAINER=ALL;
GRANT SYSBACKUP TO C##BACKUP;
RMAN TARGET '"C##BACKUP AS SYSBACKUP"'
Summary
• There is not much difference between using RMAN to take backups in a CDB database and a
non-CDB database. The recovery procedure is also nearly the same.
• The Data Recovery Advisor provides an easy approach to discover and restore from datafiles
loss.
• You can grant a local user the privilege to take backup of his own PDB.