mardi 23 août 2022

RMAN / CommVault : DB, PDB, Schema, Tablespace or Table PIT Restoration ( NoCDB or CDB )

1.   Summary

RMAN Restore with the CommVault Media Manager.

 Components

Component Version Comment

AIX AIX 7.2 OS

Oracle 19C : 12C R2 12.2.0.3
12CR1 : 12.1.0.2
11GR2 : 11.2.0.4 RDBMS

Oracle/RMAN 19C – 12C – 11G Backup & Restore Utility

CommVault 11.20.22 Backup & Restore Media manager
CommVault Agent iDataAgent64 Data Agent AIX for Oracle

Notes :
a) in the following scripts, "resetlogs" command will be commented out as it is better to run it not connected to RMAN Catalog.
b) see next post for "boosting" CommVault RMAN Restore performance.

PITR Restore Types

Chapter

Restore Level

Type

Arcmode

PDB

2.1)

DB

Out-of-place

O

N

2.2)

DB

Out-of-place

N

N

3)

Archivelogs

In-Place

O

N

4)

Table

In-Place

O

O

5.1)

Tablespace

In-Place

O

N

5.2)

Tablespace

In-Place

O

O

6.1)

PDB

In-Place

O

O

6.2)

PDB

Out-of-Place

O

O

7.1)

CDB

Out-of-place

N

O

7.2)

CDB

Out-of-place

O

O

8.1)

Schéma

Out-of-place

O

N

8.2)

Schéma

Out-of-place

O

O

8.3)

Schéma

Out-of-place

N

N

8.4)

Schéma

Out-of-place

N

O

2.   Database PITR – Out of place ( NoCDB )

DB Name = "DBNAME" 

 2.1. DB PITR - Out of place - Archivelog Mode - No CDB

 Get DBID from RMAN Catalog ( LDAP Entry IRC_PRO )

 $ sqlplus IRC/<psw>@IRC_PRO

SELECT db_key, dbid, name FROM rc_database WHERE name = 'DBNAME'

 Then restore Database  

$ cat DBNAME.Rman.DBPITR.scr

connect target /
connect catalog IRC/<irc_psw>@IRC_PRO
set parallelmediarestore  OFF;

run {
startup nomount;
}

set dbid=1938511762 ;
run {
SET CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE 'sbt_tape' TO '%F';
  restore spfile from autobackup maxdays 5;
}

shutdown immediate ;
startup nomount ;

run {
SET CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE 'sbt_tape' TO '%F';
restore controlfile from autobackup maxdays 5 ; }
alter database mount ;
run {
allocate channel ch1 type 'sbt_tape';
allocate channel ch2 type 'sbt_tape';
allocate channel ch3 type 'sbt_tape';
allocate channel ch4 type 'sbt_tape';
SET UNTIL TIME "TO_DATE('20-05-2021 12:00:00','DD-MM-YYYY HH24:MI:SS')" ;
restore database ;
RECOVER DATABASE ;

# ALTER DATABASE OPEN RESETLOGS ;
}
 

Don’t forget to create TEMP Tablespace.

CREATE TEMPORARY TABLESPACE temp_1 tempfile '/<file>/temp_1_02.dbf' size 2048M EXTENT MANAGEMENT LOCAL UNIFORM SIZE 1M ;

alter database default temporary tablespace temp_1 ;

2.2. DB PITR - Out of place - No Archivelog Mode - No CDB

Get DBID from RMAN Catalog


$ sqlplus IRC/<psw>@IRC_PRO
SELECT db_key, dbid, name FROM rc_database WHERE name = 'DBNAME'

 Script

 /work/oracle/pprbi/rman $ cat restore_DB_NoARC_CMV_PITR.scr


connect target /
connect catalog IRC/<psw>@IRC_PRO

set parallelmediarestore  OFF;

run {
startup nomount;
}

set dbid=178875654 ;

run {
SET CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE 'sbt_tape' TO '%F';
  restore spfile from autobackup maxdays 15 ;
}

shutdown immediate ;
startup nomount ;

run {
SET CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE 'sbt_tape' TO '%F';
restore controlfile from autobackup maxdays 15 ; }
 
alter database mount ;
 
run {

allocate channel ch1 type 'sbt_tape';
allocate channel ch2 type 'sbt_tape';
allocate channel ch3 type 'sbt_tape';
allocate channel ch4 type 'sbt_tape';
SET UNTIL TIME "TO_DATE('16-06-2021 12:00:00','DD-MM-YYYY HH24:MI:SS')" ;
# By default, RMAN does not restore read-only files when you issue the RESTORE DATABASE command.
  RESTORE DATABASE CHECK READONLY;
# Suppresses the application of redo logs during recovery. Only incremental backups are applied.
  RECOVER DATABASE NOREDO;
#  ALTER DATABASE OPEN RESETLOGS ;

}

Open Resetlogs may fail, if so :


Starting recover at OCT 11 2021 21:46:56
Finished recover at OCT 11 2021 21:47:13
released channel: ch1
released channel: ch2
released channel: ch3
released channel: ch4
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of sql statement command at 10/11/2021 21:47:13
ORA-01152: file 1 was not restored from a sufficiently old backup
ORA-01110: data file 1: '/data/dbname/system_01.dbf'

Recovery Manager complete.

è  simulate « Incomplete Recovery »


SQL> select count(*),status,checkpoint_change#,fuzzy from v$datafile_header  group by status,checkpoint_change#,fuzzy ;

  COUNT(*) STATUS  CHECKPOINT_CHANGE# FUZ
---------- ------- ------------------ ---
       217 ONLINE         55762472853 NO

SQL> Recover database using backup controlfile until cancel ;
ORA-00279: change 55762472853 generated at 10/02/2021 21:18:16 needed for thread 1
ORA-00289: suggestion : /work/oracle/dbname/noarc/DBNAME1_44334_973023343.arc
ORA-00280: change 55762472853 for thread 1 is in sequence #44334

Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
CANCEL

Media recovery cancelled.

SQL> Alter database open resetlogs ;
Database altered.

3. Archivelogs Restore


/work/oracle/db_name/rman/scr $ cat rma_restore_archlog.scr

connect target /
connect catalog IRC/<mdp>@IRC_PRO

run {
allocate channel ch1 type 'sbt_tape';
allocate channel ch2 type 'sbt_tape';
allocate channel ch3 type 'sbt_tape';
allocate channel ch4 type 'sbt_tape';

restore archivelog from sequence = 39456 until sequence = 39463 thread 1 ;

}

4. Table PITR in a PDB – Archivelog Mode

Table name = SCHEMA.TRP_INSC_DOC@PDBNAME

and change table name -- In place Restore.


$ cat rman_rtrpit_ta_online_cmv_cat_PDB.CDBNAME.scr

connect target /
connect catalog IRC/<irc_psw>@IRC_PRO

run {

RECOVER TABLE SCHEMA.TRP_INSC_DOC OF PLUGGABLE DATABASE PDBNAME
  UNTIL TIME "TO_DATE('08-APR-2021 20:00', 'DD-MON-YYYY HH24:MI')"
  AUXILIARY DESTINATION '/WORK_EXP_TMP/oracle/tspitr'
  REMAP TABLE 'SCHEMA'.'TRP_INSC_DOC':'TRP_INSC_DOC_210408';

} 

Run script connected as Target CDBNAME.

5.  Tablespace PITR – Archivelog Mode

5.1. TS PITR - In place - Archivelog Mode - No CDB

Tablespace = BAL_DAT

Prerequisite 1

Get Tablespace list from Schema

select distinct tablespace_name from dba_segments where owner = 'BAL'

Prerequisite 2 : prepare init file and check for self-contained TS


$ cd $ORACLE_HOME/rdbms/admin

DBNAME sr-orappr-1: /oracle/12CDB/rdbms/admin $ cat params_auxinst.ora
_DISK_SECTOR_SIZE_OVERRIDE=TRUE

$ mkdir /work/oracle/dbname/rman/tspitr

DBNAME sr-orappr-1: /oracle $ sqlplus / as sysdba

SQL*Plus: Release 12.1.0.2.0 Production on Mon Mar 29 16:01:06 2021
Copyright (c) 1982, 2014, Oracle.  All rights reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

SQL> execute dbms_tts.transport_set_check('BAL_DAT',TRUE,TRUE);
PL/SQL procedure successfully completed.

SQL> select * from transport_set_violations;
no rows selected

 Script 

$ cat rman_rtrpit_ts_online_cmv_cat_DBNAME.scr

connect target /

connect catalog IRC/<mdp>@IRC_PRO

run {

# 10g+ fully automated TSPITR

recover tablespace BAL_DAT until time "to_date('Apr 07 2021 15:00:00','MON DD YYYY HH24:MI:SS')"

auxiliary destination '/WORK_EXP_TMP/oracle/tspitr'

UNDO TABLESPACE "UNDO", "XDB" ;

}

Note AIX Problem


channel ORA_AUX_SBT_TAPE_4: ORA-19870: error while restoring backup piece db_F_DBNAME_s15940_Ui409e339_1_1_20210919
ORA-19504: failed to create file "/data/dbname/bal_dat.dbf"
ORA-27041: unable to open file
IBM AIX RISC System/6000 Error: 22: Invalid argument

Additional information: 4
RMAN-06956: create datafile failed; retry after removing /data/dbname/bal_dat.dbf from OS

It is necessary to remove the file and run RMAN again !

DBNAME /work/oracle/dbname/diag/rdbms/dbname/DBNAME/trace $ vi alert_DBNAME.log

DBNAME /work/oracle/dbname/diag/rdbms/dbname/DBNAME/trace $ rm /data/dbname/bal_dat.dbf

Post-Restore

$ sqlplus / as sysdba

Connected to:

Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production

With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

SQL> alter tablespace BAL_DAT online ;

Tablespace altered. 

5.2. TS PITR - In place - Archivelog Mode - CDB

Tablespace = APP_DAT@PDBNAME

Prerequisite 1

Get Tablespace list from Schema

SQL> select distinct tablespace_name from dba_segments where owner = 'GSU' ;

TABLESPACE_NAME

--------------------------------------------------------------------------

APP_DAT

Prerequisite 2 : prepare init file and check for self-contained TS


$ cd $ORACLE_HOME/rdbms/admin

PDB_NAME : /oracle/19CDB/rdbms/admin $ cat params_auxinst.ora
_DISK_SECTOR_SIZE_OVERRIDE=TRUE
 
PDB_NAME : /oracle/19CDB/rdbms/admin $ sqlplus SYS/$psw@PDBNAME AS SYSDBA
SQL*Plus: Release 19.0.0.0.0 - Production on Fri Oct 8 14:36:15 2021
Version 19.10.0.0.0
Copyright (c) 1982, 2020, Oracle.  All rights reserved.
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.10.0.0.0

SQL> execute dbms_tts.transport_set_check('APP_DAT');
PL/SQL procedure successfully completed.

SQL> select * from transport_set_violations;
no rows selected
SQL>

Run script connected as Target CDBNAME.

$ cat rman_rtrpit_ts_online_cmv_cat_PDBNAME.scr

connect target /

connect catalog IRC/<catalog_psw>@IRC_PRO

run {

recover tablespace PDBNAME:APP_DAT until time "to_date('Oct 07 2021 17:00:00','MON DD YYYY HH24:MI:SS')"

auxiliary destination '/WORK_EXP_TMP/oracle/tspitr' ;

}

Post-Restore

PDB_NAME : /work/oracle/pdb_name/rman/scr $ sqlplus system/$psw@PDBNAME

Connected to:

Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production

Version 19.10.0.0.0

SQL> alter tablespace APP_DAT ONLINE ;

Tablespace altered.

SQL>

5.3. Manage side effects on Standby

Manage Standby Database

Effect of PITR on Dataguard Environment (Standby MRP Crashed with ORA-39873) (Doc ID 1591492.1)

Effect of Tablespace point in time recovery in Data guard Environment (Standby MRP Crashed) (Doc ID 2229201.1)

/oracle $ oerr ora 19729

19729, 00000, "File %s is not the initial version of the plugged in datafile"

// *Cause:   The file is not the initial version of the plugged in datafile.

Ex :

Errors in file /work/oracle/dbname/diag/rdbms/dbname/CPR2S/trace/CPR2S_pr00_20775170.trc:

ORA-19729: File 89 is not the initial version of the plugged in datafile

ORA-01110: data file 89: '/data/prods/gma_dat.dbf'

Backup/Restore Tablespace on Standby DB using disk backup.

On Primary

SQL> select file#,name from v$datafile where ts#=(select ts# from v$tablespace where name='BAL_DAT') ;

     FILE# NAME

         6 /data/dbname/bal_dat.dbf

$ rman target /

RMAN> backup datafile 6 format '/WORK_EXP_TMP/oracle/tspitr/DBNAME/%U';

RMAN> backup current controlfile for standby format '/WORK_EXP_TMP/oracle/tspitr/DBNAME/%U';

On Standby


$ sqlplus / as sysdba

SQL> shut immediate
ORA-01109: database not open

SQL> startup nomount

/oracle $ rman target /

RMAN> restore standby controlfile from '/WORK_EXP_TMP/oracle/tspitr/DBNAME/hmvr42gv_1_1' ;

RMAN> alter database mount;

$ sqlplus / as sysdba

SQL> alter database recover managed standby database cancel;
Database altered.

/oracle $ rman target /

RMAN> run {
restore datafile 6;
}

$ sqlplus / as sysdba

SQL> select file#,error from v$datafile_header where length(error)>=1;
no rows selected

SQL> alter database recover managed standby database disconnect;
Database altered.


6. PDB PITR – Arch Mode

6.1. PDB PITR - In place - Archivelog Mode - CDB 

PDB Name = AUC

 Connected to the CDB 

$ cat rman_rtrpit_pdb_online_cmv_cat_AUC.scr

connect target /

connect catalog IRC/<irc_psw>@IRC_PRO

run {

  ALTER PLUGGABLE DATABASE AUC CLOSE;

  SET UNTIL TIME "TO_DATE('13-APR-2021 14:00:00','DD-MON-YYYY HH24:MI:SS')" ;

  RESTORE PLUGGABLE DATABASE AUC ;

  RECOVER PLUGGABLE DATABASE AUC auxiliary destination '/WORK_EXP_TMP/oracle/tspitr' ;

  ALTER PLUGGABLE DATABASE AUC OPEN RESETLOGS;

}

Manage Standby Database

Following the restore, the Standby PDB is ahead of the Primary PDB.

Effect of PITR on Dataguard Environment (Standby MRP Crashed with ORA-39873) (Doc ID 1591492.1)

First, we got to find the SCN of the Restore

2021-10-01T15:27:12.953597+02:00

ARC1 (PID:17564090): Archived Log entry 5286 added for T-1.S-5353 ID 0x3f4ebd53 LAD:1

2021-10-01T15:55:10.076633+02:00

(11):Recovery of pluggable database PDBNAME aborted due to pluggable database open resetlog marker.

(11):To continue recovery, restore all data files for this PDB to checkpoint SCN lower than 55743980577, or timestamp before 10/01/2021 14:30:00, and restart recovery

PR00 (PID:27132332): MRP0: Detected orphaned datafiles!

PR00 (PID:27132332): Recovery will possibly be retried after pluggable database flashback...

2021-10-01T15:55:10.089025+02:00

Errors in file /work/oracle/cbd_stdby_name/diag/rdbms/cbd_stdby_name/CDB_STANDBY_NAME/trace/CDB_STANDBY_NAME_pr00_27132332.trc:

ORA-39874: Pluggable Database PDBNAME recovery halted

ORA-39873: Restore all data files to a checkpoint SCN lower than 55743980577.

PR00 (PID:27132332): Managed Standby Recovery not using Real Time Apply

Recovery interrupted!

Recovery stopped due to failure in applying recovery marker (opcode 17.46).

Datafiles are recovered to a consistent state at change 55744062157 but controlfile could be ahead of datafiles.

Stopping change tracking

2021-10-01T15:55:10.298900+02:00

Errors in file /work/oracle/cbd_stdby_name/diag/rdbms/cbd_stdby_name/CDB_STANDBY_NAME/trace/CDB_STANDBY_NAME_pr00_27132332.trc:

ORA-39874: Pluggable Database PDBNAME recovery halted

ORA-39873: Restore all data files to a checkpoint SCN lower than 55743980577.

2021-10-01T15:55:30.409604+02:00

MRP0 (PID:34406802): Recovery coordinator encountered one or more errors during automatic flashback on standby

2021-10-01T15:55:30.416962+02:00

Background Media Recovery process shutdown (CDB_STANDBY_NAME)

Then, restore the PDB on Standby CDB : 


$ cat rest_PDB_STB.scr

connect target /
connect catalog IRC/<irc_psw>@IRC_PRO

run {
allocate channel ch1 type 'sbt_tape';
allocate channel ch2 type 'sbt_tape';
allocate channel ch3 type 'sbt_tape';
allocate channel ch4 type 'sbt_tape';

restore pluggable database PDBNAME until scn 55743980577 ;
}

Restart Apply

$ sqlplus / as sysdba

Connected to:

Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production

Version 19.10.0.0.0

SQL> alter database recover managed standby database disconnect;

Database altered. 

6.2. TS PITR - Out of place - Archivelog Mode - CDB

PDB Name = GOS

Restore SPFILE on Recovery Server

connect target /

connect catalog IRC/<psw>@IRC_PRO

set parallelmediarestore  OFF;

run {

startup nomount;

}

set dbid=4134306046 ;

run {

SET CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE 'sbt_tape' TO '%F';

  restore spfile for db_unique_name PROXT

  from autobackup maxdays 5 ;

}

shutdown immediate ; 

 Controlfile

connect target /

connect catalog IRC/<psw>@IRC_PRO

set parallelmediarestore  OFF;

startup nomount ;

run {

SET UNTIL TIME "TO_DATE('28-SEP-2021 14:00:00','DD-MON-YYYY HH24:MI:SS')" ;

SET CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE 'sbt_tape' TO '%F';

restore controlfile from autobackup maxdays 15 ; }

alter database mount ; 

 On Source DB, get Tablespaces list to be excluded from Restore

select ''||pdb_name||':'||tablespace_name||' ' from cdb_tablespaces a , cdb_pdbs b where a.con_id = b.con_id

and pdb_name != 'GOS'

Run Restore not connected to RCAT as we don't want to register a newly created Instance of the Restored Database.

connect target /

#connect catalog IRC/<psw>@IRC_PRO
 
set parallelmediarestore  OFF;
 
run {
SET UNTIL TIME "TO_DATE('28-SEP-2021 14:00:00','DD-MON-YYYY HH24:MI:SS')" ;
 
restore database root database "PDB$SEED" database GOS
skip forever tablespace IRC:SYSTEM ,
IRC:SYSAUX , IRC:TEMP , IRC:IRC_DAT , PDB02:SYSTEM , PDB02:SYSAUX , PDB02:TEMP ,
PDB02:USERS , PDB02:TS02 ;
 
recover database 
skip forever tablespace IRC:SYSTEM ,
IRC:SYSAUX , IRC:TEMP , IRC:IRC_DAT , PDB02:SYSTEM , PDB02:SYSAUX , PDB02:TEMP ,
PDB02:USERS , PDB02:TS02 ;
 
# alter database open resetlogs ;

}

 

7.  CDB PITR – Arch|NoArch Mode

CDB = "CDBNAME"

7.1. CDB PITR - Out of place - No Archivelog Mode - CDB

With Tablespaces Exclusion. 


$ cat CDBNAME.Rman.Closed.Bup.Restore.scr
connect target /
connect catalog IRC/<irc_psw>@IRC_PRO
 
run {
startup nomount;
}

set dbid=2991130853 ;
run {
SET CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE 'sbt_tape' TO '%F';
  restore spfile from autobackup maxdays 15 ;
}
 
shutdown immediate ;
startup nomount ;
 
run {
 
SET UNTIL TIME "TO_DATE('12-APR-2021 14:00:00','DD-MON-YYYY HH24:MI:SS')" ;
SET CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE 'sbt_tape' TO '%F';
restore controlfile from autobackup maxdays 15 ; }
 
alter database mount ;
 
run {
 
allocate channel ch1 type 'sbt_tape';
allocate channel ch2 type 'sbt_tape';
allocate channel ch3 type 'sbt_tape';
allocate channel ch4 type 'sbt_tape';
 
SET UNTIL TIME "TO_DATE('12-APR-2021 14:00:00','DD-MON-YYYY HH24:MI:SS')" ;
 
# By default, RMAN does not restore read-only files when you issue the RESTORE DATABASE command.
  RESTORE DATABASE SKIP FOREVER TABLESPACE PDBNAME01:TS01_DAT,PDBNAME01:TS02_DAT,PDBNAME01:TS03_DAT
  CHECK READONLY;
 
# Suppresses the application of redo logs during recovery. Only incremental backups are applied.
 # RECOVER DATABASE NOREDO;
 
  RECOVER DATABASE SKIP FOREVER TABLESPACE PDBNAME01:TS01_DAT,PDBNAME01:TS02_DAT,PDBNAME01:TS03_DAT;
 
#  ALTER DATABASE OPEN RESETLOGS ;

}

7.2. CDB PITR - Out of place - Archivelog Mode - CDB

SP file 

connect target /
connect catalog IRC/<psw>@IRC_PRO
 
set parallelmediarestore  OFF;
 
run {
startup nomount;
}

set dbid=1395127278 ;

run {
SET CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE 'sbt_tape' TO '%F';
  restore spfile for db_unique_name PDB_NAME
  from autobackup maxdays 5 ;
}
 
shutdown immediate ;
 
Controlfile
 
connect target /
connect catalog IRC/<psw>@IRC_PRO
 
set parallelmediarestore  OFF;
 
startup nomount ;
 
run {
 
SET UNTIL TIME "TO_DATE('30-SEP-2021 14:00:00','DD-MON-YYYY HH24:MI:SS')" ;
SET CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE 'sbt_tape' TO '%F';
restore controlfile from autobackup maxdays 15 ; }
 
alter database mount ;
 
DB
 
connect target /
connect catalog IRC/<psw>@IRC_PRO
 
set parallelmediarestore  OFF;
 
startup nomount ;
 
run {
 
SET UNTIL TIME "TO_DATE('30-SEP-2021 14:00:00','DD-MON-YYYY HH24:MI:SS')" ;
 
restore database ;
 
RECOVER DATABASE ;
 
# ALTER DATABASE OPEN RESETLOGS ;
 
} 

8. Schema PITR

8.1. Schema PITR - Out of place - Archivelog Mode - No CDB

SCHEMA = "SCHEM01@DBNAME"

  • Get DBID from RMAN Catalog 

$ sqlplus IRC/<psw>@IRC_PRO 

SELECT db_key, dbid, name FROM rc_database WHERE name = 'DBNAME' ;

Get list then check for Self Contained Tablespaces on Source DB.

select distinct tablespace_name from dba_segments where owner = 'SCHEM01'

$ sqlplus / as sysdba

execute dbms_tts.transport_set_check('SCHEM01_DAT',TRUE,TRUE);

select * from transport_set_violations ;

Script 1 : restore SPFILE 


$ cat restore_DB_ARCmode_CMV_PITR.scr.01
connect target /
 
connect catalog IRC/<psw>@IRC_PRO
 
set parallelmediarestore  OFF;
 
run {
startup nomount;
}

set dbid=2681598979 ;

run {
SET CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE 'sbt_tape' TO '%F';
  restore spfile for db_unique_name PRDUN from autobackup maxdays 15 ;
}
 
shutdown immediate ;
 

If necessary, resize spfile memory.

Get TS to excluded to keep only schema related Tablespaces – keeping LOB TS du to following bug :

Bug 26828994 - Table Point In Time Recovery (TPITR) reports ORA-376 when Lob is in Different Tablespace (Doc ID 26828994.8)


select ''||tablespace_name||',' from dba_tablespaces a
where tablespace_name not in ('SCHEM01_DAT', 'SYSTEM' , 'SYSAUX', 'UNDO', 'XDB' , 'USERS' , 'TEMP', 'TEMP1' , 'ADB_DAT' )
and not exists ( select '1' from dba_lobs b where a.tablespace_name = b.tablespace_name )
order by 1

Script 2 : Restore

 
$ cat restore_DB_ARCmode_CMV_PITR.scr.02c
 
connect target /
 
connect catalog IRC/<catalog_psw>@IRC_PRO
 
set parallelmediarestore  OFF;
 
startup nomount ;
 
run {
SET CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE 'sbt_tape' TO '%F';
restore controlfile from autobackup maxdays 15 ; }
 
alter database mount ;
 
run {
 
allocate channel ch1 type 'sbt_tape';
allocate channel ch2 type 'sbt_tape';
allocate channel ch3 type 'sbt_tape';
allocate channel ch4 type 'sbt_tape';
 
SET UNTIL TIME "TO_DATE('22-09-2021 12:00:00','DD-MM-YYYY HH24:MI:SS')" ;
 
# keep LOB TS
# Bug 26828994 - Table Point In Time Recovery (TPITR) reports ORA-376 when Lob is in Different Tablespace (Doc ID 26828994.8)
 
restore database skip forever tablespace
TS01_DAT, TS02_DAT, TS03_DAT ;
 
RECOVER database skip forever tablespace
TS01_DAT, TS02_DAT, TS03_DAT ;
 
# ALTER DATABASE OPEN RESETLOGS ;
 
}
 

If OK, then export schema. 


expdp system/${psw} schemas=SCHEM01 DIRECTORY=BAT_DP_DIR DUMPFILE=expdp_SCHEM01_RF_PROD.dmp LOGFILE=expdp_SCHEM01_RF_PROD.log parallel=2 \
flashback_time="\"to_timestamp(to_char(sysdate, 'YYYY-MM-DD HH24:MI:SS'), 'YYYY-MM-DD HH24:MI:SS')\""

8.2. Schema PITR - Out of place - Archivelog Mode - CDB

SCHEMA = "UBI@PDB_NAME@CDBNAME" 

  • Get DBID from RMAN Catalog 

$ sqlplus IRC/<psw>@IRC_PRO

SELECT db_key, dbid, name FROM rc_database WHERE name = 'CDBNAME' ;

Get list then check for Self Contained Tablespaces on Source DB.

select distinct tablespace_name from dba_segments where owner = 'UBI' 

$ sqlplus / as sysdba

execute dbms_tts.transport_set_check('UBI_DAT',TRUE,TRUE);

select * from transport_set_violations ; 

Script 1 : restore SPFILE

$ cat PDB_NAME.Rman.DBPITR.scr.1
connect target /
connect catalog IRC/<psw>@IRC_PRO
 
set parallelmediarestore  OFF;
 
run {
startup nomount;
}
set dbid=1395127278 ;
run {
SET CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE 'sbt_tape' TO '%F';
  restore spfile for db_unique_name PDB_NAME
  from autobackup maxdays 5 ;
}
 
shutdown immediate ;
 

Get TS list to be excluded : 

 
$ sqlplus / as sysdba
 
set pages 5000
select ''||pdb_name||':'||tablespace_name||', ' from cdb_tablespaces a , cdb_pdbs b
where a.con_id = b.con_id
and ( pdb_name != 'PDB_NAME'
OR
( pdb_name = 'PDB_NAME' and tablespace_name not in ('UBI_DAT', 'SYSTEM' , 'SYSAUX', 'UNDO', 'XDB' , 'USERS', 'TEMP', 'TEMP1' ) )
)
order by 1 ;
 

Script 2 : restore PDB

 
$ cat  PDB_NAME.Rman.PDBPITR.scr.2
connect target /
 
connect catalog IRC/<catalog_psw>@IRC_PRO
 
set parallelmediarestore  OFF;
 
startup nomount ;
 
run {
SET CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE 'sbt_tape' TO '%F';
restore controlfile from autobackup maxdays 15 ; }
 
alter database mount ;
 
run {
 
allocate channel ch1 type 'sbt_tape';
allocate channel ch2 type 'sbt_tape';
allocate channel ch3 type 'sbt_tape';
allocate channel ch4 type 'sbt_tape';
 
SET UNTIL TIME "TO_DATE('19-10-2021 12:00:00','DD-MM-YYYY HH24:MI:SS')" ;
 
restore database skip forever tablespace
PDB_NAME02:TS01_DAT, PDB_NAME02:TS02_DAT, PDB_NAME02:TS03_DAT, PDB_NAME02:TS04_DAT, PDB_NAME:TS01_DAT, PDB_NAME:TS02_DAT ;
 
RECOVER database skip forever tablespace
PDB_NAME02:TS01_DAT, PDB_NAME02:TS02_DAT, PDB_NAME02:TS03_DAT, PDB_NAME02:TS04_DAT, PDB_NAME:TS01_DAT, PDB_NAME:TS02_DAT ;
 
ALTER DATABASE OPEN RESETLOGS ;
 
}
 

Run Restore. 

$ rman @PDB_NAME.Rman.PDBPITR.scr.2 |tee PDB_NAME.Rman.PDBPITR.log.2
 

 
archived log file name=/arch/pdb_name/PDB_NAME1_4297_1053080302.arc thread=1 sequence=4297
archived log file name=/arch/pdb_name/PDB_NAME1_4298_1053080302.arc thread=1 sequence=4298
media recovery complete, elapsed time: 00:01:55
Finished recover at OCT 19 2021 18:23:09
 
Statement processed
new incarnation of database registered in recovery catalog
starting full resync of recovery catalog
full resync complete
released channel: ch1
released channel: ch2
released channel: ch3
released channel: ch4
 
Recovery Manager complete.

Start dedicated Listener to get access to the restored PDB : 

 
$ lsnrctl start LSN_PDB_NAME
 
sqlplus / as sysdba
SQL> alter system set local_listener = 'PDB_NAME_RF' ;
 

Then run export : 

$ expdp system/${psw}@PDB_NAME_UBI_RF schemas=UBI DIRECTORY=BAT_DP_DIR DUMPFILE=expdp_UBI.dmp LOGFILE=expdp_UBI.log parallel=2 \
> flashback_time="\"to_timestamp(to_char(sysdate, 'YYYY-MM-DD HH24:MI:SS'), 'YYYY-MM-DD HH24:MI:SS')\""
 

8.3. Schema PITR - Out of place - No Archivelog Mode - No CDB

SCHEMA = "SCHEM01@DBNAME"

Get DBID from RMAN Catalog.
 
$ sqlplus IRC/<psw>@IRC_PRO
SELECT db_key, dbid, name FROM rc_database WHERE name = 'DBNAME' ;
 
Get Tablespaces List.
 
Ex. case where we have Partitions.
 
select distinct tablespace_name from dba_segments where owner = 'SCHEM01'
 union
select distinct tablespace_name from dba_tab_partitions where table_owner = 'SCHEM01'

Script 1 : restore SPFILE 


$ cat restore_DB_NOARCmode_CMV_PITR.scr.01
connect target /
 
connect catalog IRC/<catalog_psw>@IRC_PRO
 
set parallelmediarestore  OFF;
 
run {
startup nomount;
}
set dbid=1683006242 ;
run {
SET CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE 'sbt_tape' TO '%F';
  restore spfile from autobackup maxdays 15 ;
}
 
shutdown immediate ;

 Get TS list to be excluded : 


select ''||tablespace_name||',' from dba_tablespaces
where tablespace_name not in
('SCHEM01_DAT', 'SYSTEM' , 'SYSAUX', 'UNDO', 'XDB' , 'USERS' , ',TEMP', 'TEMP1' )
order by 1

Script 2 : restore DB 


$ cat restore_DB_NOARCmode_CMV_PITR.scr.02
connect target /
 
connect catalog IRC/<catalog_psw>@IRC_PRO
 
set parallelmediarestore  OFF;
 
startup nomount ;
 
run {
SET UNTIL TIME "TO_DATE('07-10-2021 12:00:00','DD-MM-YYYY HH24:MI:SS')" ;
SET CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE 'sbt_tape' TO '%F';
restore controlfile from autobackup maxdays 15 ; }
 
alter database mount ;
 
run {
 
allocate channel ch1 type 'sbt_tape';
allocate channel ch2 type 'sbt_tape';
allocate channel ch3 type 'sbt_tape';
allocate channel ch4 type 'sbt_tape';
 
SET UNTIL TIME "TO_DATE('07-10-2021 12:00:00','DD-MM-YYYY HH24:MI:SS')" ;
 
# By default, RMAN does not restore read-only files when you issue the RESTORE DATABASE command.
RESTORE DATABASE
skip forever tablespace
TS01_DAT, TS02_DAT, TS03_DAT
CHECK READONLY;
 
# Suppresses the application of redo logs during recovery. Only incremental backups are applied.
RECOVER DATABASE
skip forever tablespace
TS01_DAT, TS02_DAT, TS03_DAT
NOREDO;
 
ALTER DATABASE OPEN RESETLOGS ;
 
}
 

Run Restore and open database : 

 
$ rman @restore_DB_NOARCmode_CMV_PITR.scr.02 |tee restore_DB_NOARCmode_CMV_PITR.log.02
 

Database Opening : 


$ sqlplus / as sysdba
SQL*Plus: Release 12.1.0.2.0 Production on Mon Oct 11 14:26:01 2021
Copyright (c) 1982, 2014, Oracle.  All rights reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
 
SQL> recover database ;
ORA-00283: recovery session canceled due to errors
ORA-01610: recovery using the BACKUP CONTROLFILE option must be done
 
 
SQL> recover database using BACKUP CONTROLFILE until cancel ;
ORA-00279: change 55762472853 generated at 10/02/2021 21:18:16 needed for
thread 1
ORA-00289: suggestion : /work/oracle/dbname/noarc/DBNAME1_44334_973023343.arc
ORA-00280: change 55762472853 for thread 1 is in sequence #44334
 
 
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
CANCEL
Media recovery cancelled.
 
SQL> ALTER DATABASE OPEN RESETLOGS ;
Database altered.
 
SQL>

And Export : 

$ expdp system/${psw} schemas=SCHEM01 DIRECTORY=BAT_DP_DIR DUMPFILE=expdp_SCHEM01_RF.dmp LOGFILE=expdp_SCHEM01_RF.log parallel=2 \

> flashback_time="\"to_timestamp(to_char(sysdate, 'YYYY-MM-DD HH24:MI:SS'), 'YYYY-MM-DD HH24:MI:SS')\""

8.4. Schema PITR - Out of place - No Archivelog Mode - CDB

SCHEMA = IBO_01@PDB_NAME , IBO_02@PDB_NAME , IBO_03@PDB_NAME

Get DBID from RMAN Catalog 

$ sqlplus IRC/<psw>@IRC_PRO
SELECT db_key, dbid, name FROM rc_database WHERE name = 'CDBNAME' ;
    DB_KEY       DBID NAME
---------- ---------- --------
   7699790 2991130853 CDBNAME

Get TS list : 

$ sqlplus system/$psw@PDB_NAME
 
SQL*Plus: Release 19.0.0.0.0 - Production on Fri Feb 11 10:32:24 2022
Version 19.10.0.0.0
Copyright (c) 1982, 2020, Oracle.  All rights reserved.
Last Successful login time: Fri Feb 11 2022 10:05:51 +01:00
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.10.0.0.0
 
SQL> select distinct tablespace_name from dba_segments where owner in ('IBO_01','IBO_02','IBO_03') ;
 
TABLESPACE_NAME
------------------------------
IBO_01_DAT
IBO_02_DAT
IBO_03_DAT
 

Script 1 : restore SPFILE 


$ cat restore_DB_NOARCmode_CMV_PITR.scr.01
connect target /
 
connect catalog IRC/<catalog_psw>@IRC_PRO
 
set parallelmediarestore  OFF;
 
run {
startup nomount;
}
set dbid=2991130853 ;
run {
SET CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE 'sbt_tape' TO '%F';
  restore spfile from autobackup maxdays 15 ;
}
 
shutdown immediate ;

Script 2 : Controlfile 

 
$ cat restore_DB_NOARCmode_CMV_PITR.scr.01b
connect target /
connect catalog IRC/<catalog_psw>@IRC_PRO
 
set parallelmediarestore  OFF;
 
startup nomount ;
 
run {
 
SET UNTIL TIME "TO_DATE('06-02-2022 12:00:00','DD-MM-YYYY HH24:MI:SS')" ;
 
SET CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE 'sbt_tape' TO '%F';
restore controlfile from autobackup maxdays 15 ; }
 
alter database mount ;
 

 Get TS list to be excluded, connecter to the CDB : 

set pages 5000 lines 150
select ''||pdb_name||':'||tablespace_name||' , ' from cdb_tablespaces a , cdb_pdbs b where a.con_id = b.con_id
and tablespace_name not in ('SCHEM01_DAT', 'SYSTEM' , 'SYSAUX', 'UNDO', 'XDB' , 'USERS' , 'TEMP', 'TEMP1' )
and pdb_name != 'PDB_NAME'
order by 1 ; 

Script 3 : DB Restore 

$ cat restore_DB_NOARCmode_CMV_PITR.scr.02
 
connect target /
connect catalog IRC/<catalog_psw>@IRC_PRO
 
set parallelmediarestore  OFF;
 
run {
 
SET UNTIL TIME "TO_DATE('06-02-2022 12:00:00','DD-MM-YYYY HH24:MI:SS')" ;
 
restore database root database "PDB$SEED" database PDB_NAME;
 
recover database skip forever tablespace
PDBNAME01:TS01_DAT , PDBNAME01:TS02_IDX , PDBNAME01:XDB
;
 
alter database open resetlogs ;
 
}
 

 Run Restore 

$ rman @restore_DB_NOARCmode_CMV_PITR.scr.02 |tee restore_DB_NOARCmode_CMV_PITR.log.02
 
$ sqlplus / as sysdba
SQL*Plus: Release 19.0.0.0.0 - Production on Fri Feb 11 15:39:39 2022
Version 19.10.0.0.0
Copyright (c) 1982, 2020, Oracle.  All rights reserved.
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.10.0.0.0
 
SQL>  SELECT name, open_mode FROM v$pdbs;
 
NAME         OPEN_MODE
----------
PDB$SEED     READ ONLY
PDBNAME01           MOUNTED
PDB_NAME            READ WRITE

 Start dedicated Listener to get access to the restored PDB : 

 
$ lsnrctl start LSN_PDB_NAME
 
sqlplus / as sysdba
SQL> alter system set local_listener = 'PDB_NAME_RF' ;
 

 Then run export : 

$ expdp system/${psw}@PDB_NAME_RF schemas= IBO_01,IBO_02,IBO_03 DIRECTORY=BAT_DP_DIR DUMPFILE=expdp_IBO_RF.dmp LOGFILE=expdp_IBO_RF.log parallel=2 \
flashback_time="\"to_timestamp(to_char(sysdate, 'YYYY-MM-DD HH24:MI:SS'), 'YYYY-MM-DD HH24:MI:SS')\""


Another Example in case we run into the error "RMAN-07551: data file 10 must be restored or preplugin recovery must be completed"

At Step : extract the TS list to SKIP 

for the Restore part :

set pages 5000 Lines 150
select ''||pdb_name||':'||tablespace_name||', ' from cdb_tablespaces a , cdb_pdbs b where a.con_id = b.con_id 
and tablespace_name not in ('IBO_01_DAT', 'IBO_02_DAT', 'IBO_03_DAT', 'SYSTEM' , 'SYSAUX', 'UNDO', 'XDB' , 'USERS' )
and tablespace_name not like '%TEMP%'
and pdb_name = 'PDB_NAME'
order by 1 ;


for the Recover part :

set pages 5000 Lines 150
select ''||pdb_name||':'||tablespace_name||', ' from cdb_tablespaces a , cdb_pdbs b where a.con_id = b.con_id 
and tablespace_name not in ('HRC_DAT', 'SYSTEM' , 'SYSAUX', 'UNDO', 'XDB' , 'USERS' )
and tablespace_name not like '%TEMP%'
and pdb_name = 'PDB_NAME'
union
select decode(tablespace_name,'UNDO',''||pdb_name||':"'||tablespace_name||'",',''||pdb_name||':'||tablespace_name||',')
from cdb_tablespaces a , cdb_pdbs b where a.con_id = b.con_id 
and tablespace_name not like '%TEMP%'
and pdb_name != 'PDB_NAME'
order by 1 ;


That gives Rman script like this :

connect target /
connect catalog IRC/<psw>@IRC_PRO

set parallelmediarestore  OFF;

run {

allocate channel ch1 type 'sbt_tape' ;
allocate channel ch2 type 'sbt_tape' ;
allocate channel ch3 type 'sbt_tape' ;
allocate channel ch4 type 'sbt_tape' ;
allocate channel ch5 type 'sbt_tape' ;
allocate channel ch6 type 'sbt_tape' ;
allocate channel ch7 type 'sbt_tape' ;
allocate channel ch8 type 'sbt_tape' ;
allocate channel ch9 type 'sbt_tape' ;
allocate channel ch10 type 'sbt_tape' ;
allocate channel ch11 type 'sbt_tape' ;
allocate channel ch12 type 'sbt_tape' ;

SET UNTIL TIME "TO_DATE('15-07-2024 12:00:00','DD-MM-YYYY HH24:MI:SS')" ;

restore database root database "PDB$SEED" database IQRHR
skip forever tablespace
PDB_NAME:TS_01, PDB_NAME:TS_02, < ... list of PDB_NAME:TS to exclude ...> ;

recover database
skip forever tablespace
PDB_NAME:TS_01, PDB_NAME:TS_02, < ... list of PDB_NAME:TS to exclude ...> ,
OTHER_PDB_02:TS_01, OTHER_PDB_02:TS_02, < ... list of OTHER_PDB_02:TS to exclude ...> ,
OTHER_PDB_03:TS_01, OTHER_PDB_03:TS_02, < ... list of OTHER_PDB_03:TS to exclude ...> 
;

# better not to do resetlogs when connected to catalog:
#alter database open resetlogs ;

}