0% found this document useful (0 votes)
178 views

Practice 13: Backup and Recovery in CDB and Pdbs

This document describes performing various backup and recovery operations in a multitenant container database (CDB) and pluggable databases (PDBs) using RMAN: - It discusses taking full and partial backups of the whole CDB, individual PDBs, and PDB tablespaces. - It provides examples for recovering from the loss of a SYSTEM datafile in a PDB and a non-SYSTEM datafile in the CDB using RMAN and the Data Recovery Advisor. - It demonstrates enabling a PDB administrator to backup and restore their PDB.

Uploaded by

Julio Abreu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
178 views

Practice 13: Backup and Recovery in CDB and Pdbs

This document describes performing various backup and recovery operations in a multitenant container database (CDB) and pluggable databases (PDBs) using RMAN: - It discusses taking full and partial backups of the whole CDB, individual PDBs, and PDB tablespaces. - It provides examples for recovering from the loss of a SYSTEM datafile in a PDB and a non-SYSTEM datafile in the CDB using RMAN and the Data Recovery Advisor. - It demonstrates enabling a PDB administrator to backup and restore their PDB.

Uploaded by

Julio Abreu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Practice 13 Backup and Recovery in CDB and PDBs Pa ge |1

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.

Oracle 12c Multitenant Architecture Administration, a course by Ahmed Baraka


Practice 13 Backup and Recovery in CDB and PDBs Pa ge |2

Performing RMAN Backups


A. Performing RMAN Whole CDB Backup

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;

2. Check out the values of the parameters DB_RECOVERY_FILE_DEST and


DB_RECOVERY_FILE_DEST_SIZE.
Take a note of the destination and make sure the size is enough to accommodate the backup files.
SHOW PARAMETER DB_RECOVERY_FILE_DEST

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';

BACKUP DATABASE PLUS ARCHIVELOG;

5. List the backupset files generated by RMAN.


LIST BACKUP ;

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/

Oracle 12c Multitenant Architecture Administration, a course by Ahmed Baraka


Practice 13 Backup and Recovery in CDB and PDBs Pa ge |3

7. From OS shell, check out the files generated by the RMAN.


The files will be created under a directory of the current date.
You should see three backupset files. They are backup files of the database, archive redo log files,
control files and SPFILE.
# ls -alh /u01/app/oracle/fra/CDB1/CDB1/backupset/<date>/

Oracle 12c Multitenant Architecture Administration, a course by Ahmed Baraka


Practice 13 Backup and Recovery in CDB and PDBs Pa ge |4

B. Performing RMAN Whole and Partial PDB Backup

In this section of the practice, you will perform a whole and a partial PDB backup of PDB2.

8. Login to RMAN and take a whole PDB backup of PDB2.


rman target /
BACKUP PLUGGABLE DATABASE pdb2;

9. List the backupset files generated by RMAN as a backup to PDB2.


list backup of pluggable database 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>/

# du -sh /u01/app/oracle/fra/CDB1/CDB1/<PDB GUID>/<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;

Oracle 12c Multitenant Architecture Administration, a course by Ahmed Baraka


Practice 13 Backup and Recovery in CDB and PDBs Pa ge |5

C. Performing RMAN Recovery from SYSTEM PDB Datafile Loss

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.

12. Determine the datafile of the SYSTEM tablespace in PDB2.


sqlplus / as sysdba
ALTER SESSION SET CONTAINER=PDB2;
SELECT FILE_NAME FROM DBA_DATA_FILES WHERE TABLESPACE_NAME='SYSTEM';

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

-- execute the following commands:


RESTORE TABLESPACE pdb2:SYSTEM;
RECOVER TABLESPACE pdb2:SYSTEM;
-- OR the following commands:
RESTORE pluggable database pdb2;
RECOVER pluggable database pdb2;

RMAN> ALTER DATABASE OPEN;


RMAN> SELECT NAME, OPEN_MODE FROM V$PDBS WHERE NAME='PDB2';

16. Connect to PDB2 and execute the following DESCRIBE command.


sqlplus system/oracle@pdb2
DESC DBA_DATA_FILES

Oracle 12c Multitenant Architecture Administration, a course by Ahmed Baraka


Practice 13 Backup and Recovery in CDB and PDBs Pa ge |6

D. Performing RMAN Recovery from non-SYSTEM Root Datafile Loss

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.

17. Determine the datafile of the SYSAUX tablespace in CDB1.


sqlplus / as sysdba
SELECT FILE_NAME FROM DBA_DATA_FILES WHERE TABLESPACE_NAME='SYSAUX';

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;

21. Preview the suggested script to fix the issue.


REPAIR FAILURE PREVIEW;

22. Execute the script.


When it prompts for confirmation, type YES then press ENTER.
REPAIR 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.

Oracle 12c Multitenant Architecture Administration, a course by Ahmed Baraka


Practice 13 Backup and Recovery in CDB and PDBs Pa ge |7

E. Enabling a PDB Administrator to Backup and Restore its PDB

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.

This is needed in an environment where every PDB is managed by different administrator.

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"

26. Take a whole PDB backup of PDB2.


# issue one of the commands below. They have the same effect:
BACKUP PLUGGABLE DATABASE pdb2 TAG 'BYLOCAL';
BACKUP DATABASE TAG 'BYLOCAL';

27. List the backupset files.


Notice that this command does not only display the backupset taken by PDB2ADMIN, it also displays
the backupset of PDB2 taken by SYS (when it took backup of the entire CDB).
LIST BACKUPSET;

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"'

Oracle 12c Multitenant Architecture Administration, a course by Ahmed Baraka


Practice 13 Backup and Recovery in CDB and PDBs Pa ge |8

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.

Oracle 12c Multitenant Architecture Administration, a course by Ahmed Baraka

You might also like