How to Use RMAN Scripts
This topic contains the following RMAN scripts to target CDB with\without catalog:
- Backup of Container Database (CDB) or non-container database
- Note: If you backup the complete CDB, Pluggable databases are also backed up.
- RMAN Script
- RMAN> run {
- allocate channel dev1 device type sbt_tape;
- backup database plus archivelog;
- release channel dev1;
- }
- Root backup of CDB
- Note: If you backup the root CDB, Pluggable databases are not backed up.
- RMAN Script
- RMAN> run {
- allocate channel dev1 device type sbt_tape;
- backup database root;
- release channel dev1;
- }
- Pluggable Database (PDB) Backup: You can backup the PDB using root (CDB) or PDB.
- Using root (CDB): You can backup multiple PDBs using single command of RMAN script mentioned below.
- RMAN Script
- RMAN> run {
- allocate channel dev1 device type sbt_tape;
- backup pluggable database pdb1, pdb2;
- release channel dev1;
- }
- Using root (PDB): You need to connect to PDB and can backup only one PDB using the RMAN script mentioned below.
- RMAN Script
- rman target=username@PDB1
- RMAN> run {
- allocate channel dev1 device type sbt_tape;
- backup database;
- release channel dev1;
- }
- To backup one or more tablespaces of CDB only
- RMAN Script
- RMAN> run {
- allocate channel dev1 device type sbt_tape;
- backup tablespaces tbs1, tbs2;
- release channel dev1;
- }
- To backup one or more tablespaces of PDB or tablespaces from CDB and PDB: You cannot directly backup the PDB tablespaces when the tablespace name is part of CDB. However, you can provide the datafile IDs of the tablespace names. Connect to CDB and PDB seperately from SQL plus and run the following command for datafile IDs:
- SQL> select file_id,tablespace_name from dba_data_files;
- RMAN Script
- RMAN> run {
- allocate channel dev1 device type sbt_tape;
- backup datafile datafile id1, datafile id2;
- release channel dev1;
- }
- To perform complete restore of CDB, PDB and root: You should have SYSBACKUP or SYSDBA privilege to restore any of the databases. Restoring Container Database (CDB) is similar to non-container database restore.
- Note: CDB database restore will restore all the pluggable databases.
- RMAN Script
- RMAN> run {
- STARTUP MOUNT;
- RESTORE DATABASE;;
- RECOVER DATABASE;
- ALTER DATABASE OPEN;
- }
- To restore ROOT database only
- RMAN Script
- RMAN> run {
- STARTUP MOUNT;
- RESTORE DATABASE ROOT;
- RECOVER DATABASE ROOT;
- ALTER DATABASE OPEN;
- }
- To restore pluggable databases from root: You can restore and recover multiple PDB’s from root using the following script:
- RMAN Script
- RMAN> run {
- RESTORE PLUGGABLE DATABASE PDB1, PDB2;
- RECOVER PLUGGABLE DATABASE PDB1, PDB2;
- ALTER PLUGGABLE DATABASE PDB1, PDB2 OPEN;
- }
- To restore pluggable database after connecting to PDB: You can restore and recover only one PDB using the following script:
- RMAN Script
- rman target=username@PDB1
- RMAN> run{
- RESTORE DATABASE;
- RECOVER DATABASE;
- }
- To restore one or more tablespaces of CDB only
- RMAN Script
- RMAN> run{
- allocate channel dev1 device type sbt_tape;
- restore tablespaces tbs1, tbs2;
- release channel dev1;
- }
- To restore one or more tablespaces of PDB or tablespaces from CDB and PDB together
- RMAN Script
- RMAN> run{
- allocate channel dev1 device type sbt_tape;
- backup datafile datafile id1, datafile id2;
- release channel dev1;
- }
- To perform point-in-time recovery: The same steps are applicable for performing a point-in-time recovery of the CDB or PDB and normal database.
- Note: If you perform point-in-time recovery on the CDB, the associated PDBs are also affected.
- RMAN Script
- SET UNTIL TIME "TO_DATE(’01-Jan-2014 01:00:00’,’DD-MON-YYYY HH24:MI:SS’)";
- SET UNTIL SCN 1999945; # alternatively, specify SCN
- SET UNTIL SEQUENCE 100; # alternatively, specify log seq