Cómo extraer Archive Logs desde un Backup Piece

RMAN no es de mis herramientas favoritas en Oracle, quizás porque cada vez que nos vemos las caras es porque ha ocurrido algún desastre.

En esta ocasión necesitaba extraer Archive Logs para aplicarlos a una operación de RECOVER pero resulta que los archives estaban catalogados en una ubicación externa y fuera de mi alcance.

Cuando al fin logre catalogar los archivos de backup que contenían los Archive Logs era necesario colocarlos en una ubicación local para poder aplicarlos. Así que veamos como extraer los archivos necesarios.

Una vez catalogados los archivos de backup en nuestro repositorio de RMAN, podemos visualizar los Archives contenidos con el comando LIST BACKUP OF ARCHIVELOG ALL.

RMAN> list backup of archivelog all;

using target database control file instead of recovery catalog

List of Backup Sets
===================


BS Key  Size       Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
3       5.39M      DISK        00:00:01     05-JUN-16     
        BP Key: 3   Status: AVAILABLE  Compressed: NO  Tag: TAG20160605T002604
        Piece Name: /oradata/fra/ORCL/backupset/2016_06_05/o1_mf_annnn_TAG20160605T002604_co7khxd4_.bkp

  List of Archived Logs in backup set 3
  Thrd Seq     Low SCN    Low Time  Next SCN   Next Time
  ---- ------- ---------- --------- ---------- ---------
  1    3       958975     04-JUN-16 963042     04-JUN-16
  1    4       963042     04-JUN-16 964046     05-JUN-16
  1    5       964046     05-JUN-16 964052     05-JUN-16
  1    6       964052     05-JUN-16 964087     05-JUN-16
  1    7       964087     05-JUN-16 964090     05-JUN-16
  1    8       964090     05-JUN-16 964093     05-JUN-16
  1    9       964093     05-JUN-16 964097     05-JUN-16
  1    10      964097     05-JUN-16 964100     05-JUN-16
  1    11      964100     05-JUN-16 964103     05-JUN-16
  1    12      964103     05-JUN-16 964694     05-JUN-16

Explicación del comando: el comando utiliza el catalogo actual de RMAN, en este caso el Control File. Nos muestra características básicas del Backup Piece: su fecha de creación, el Tag asignado por RMAN y la ubicación física del archivo.

Luego de esto, muestra un listado de Archive Logs dentro de él, clasificados por THREAD (si es un Oracle Rac, debería mostrar thread diferente por instancia), el número de SEQUENCE, el número de SCN con el que inicia y el SCN con el que finalizo y las fechas asociadas a estos SCN.

Con esta información podemos extraer los Archive Logs de manera individual hacia una ubicación física específica.

El siguiente script nos ayudara a cumplir nuestro objetivo:

run
{
  set archivelog destination to '<path>';
  restore archivelog from logseq=# until logseq=# thread=#;
}

Donde cada # indica un numero de SEQUENCE y THREAD respectivamente. Y path indica la ubicación hacia donde queremos que se extraigan los Archive Logs.

En el ejemplo que veíamos utilice:

RMAN> run
2> {
3> set archivelog destination to '/oradata/orclArchives/';
4> restore archivelog from logseq=3 until logseq=11 thread=1;
5> }

executing command: SET ARCHIVELOG DESTINATION

Starting restore at 05-JUN-16
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=24 device type=DISK

channel ORA_DISK_1: starting archived log restore to user-specified destination
archived log destination=/oradata/orclArchives/
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=3
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=4
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=5
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=6
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=7
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=8
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=9
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=10
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=11
channel ORA_DISK_1: reading from backup piece /oradata/fra/ORCL/backupset/2016_06_05/o1_mf_annnn_TAG20160605T002604_co7khxd4_.bkp
channel ORA_DISK_1: piece handle=/oradata/fra/ORCL/backupset/2016_06_05/o1_mf_annnn_TAG20160605T002604_co7khxd4_.bkp tag=TAG20160605T002604
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:07
Finished restore at 05-JUN-16

También puedo extraer de manera individual, indicando solamente un SEQUENCE NUMBER:

RMAN> run
2> {
3> set archivelog destination to '/oradata/orclArchives/';
4> restore archivelog logseq 12;
5> }

executing command: SET ARCHIVELOG DESTINATION

Starting restore at 05-JUN-16
using channel ORA_DISK_1

channel ORA_DISK_1: starting archived log restore to user-specified destination
archived log destination=/oradata/orclArchives/
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=12
channel ORA_DISK_1: reading from backup piece /oradata/fra/ORCL/backupset/2016_06_05/o1_mf_annnn_TAG20160605T002604_co7khxd4_.bkp
channel ORA_DISK_1: piece handle=/oradata/fra/ORCL/backupset/2016_06_05/o1_mf_annnn_TAG20160605T002604_co7khxd4_.bkp tag=TAG20160605T002604
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 05-JUN-16

Si examinamos la ubicación física configurada podremos observar los archivos individuales extraídos del backup piece.

[oracle@oel-pruebas orclArchives]$ ls -ltrh
total 6.7M
-rw-r-----. 1 oracle oinstall 1.6M Jun  5 01:11 1_13_913678177.dbf
-rw-r-----. 1 oracle oinstall 1.0K Jun  5 01:12 1_14_913678177.dbf
-rw-r-----. 1 oracle oinstall 2.0K Jun  5 01:12 1_15_913678177.dbf
-rw-r-----. 1 oracle oinstall 1.0K Jun  5 01:12 1_16_913678177.dbf
-rw-r-----. 1 oracle oinstall 8.5K Jun  5 01:15 1_17_913678177.dbf
-rw-r-----. 1 oracle oinstall 3.5K Jun  5 01:53 1_6_913678177.dbf
-rw-r-----. 1 oracle oinstall 1.5K Jun  5 01:53 1_7_913678177.dbf
-rw-r-----. 1 oracle oinstall 1.0K Jun  5 01:53 1_5_913678177.dbf
-rw-r-----. 1 oracle oinstall 1.0K Jun  5 01:53 1_8_913678177.dbf
-rw-r-----. 1 oracle oinstall 1.0K Jun  5 01:53 1_9_913678177.dbf
-rw-r-----. 1 oracle oinstall 1.0K Jun  5 01:53 1_10_913678177.dbf
-rw-r-----. 1 oracle oinstall 1.0K Jun  5 01:53 1_11_913678177.dbf
-rw-r-----. 1 oracle oinstall 1.0K Jun  5 01:53 1_12_913678177.dbf
-rw-r-----. 1 oracle oinstall 2.2M Jun  5 01:53 1_4_913678177.dbf
-rw-r-----. 1 oracle oinstall 2.9M Jun  5 01:53 1_3_913678177.dbf

También podemos utilizar una ubicación en un almacenamiento ASM, solo necesitamos colocar hacia que diskgroup vamos a extraer los Archives.

RMAN> run 
2> {
3> set archivelog destination to '+DATA';
4> restore archivelog from logseq=3 until logseq=12 thread=1;
5> }

executing command: SET ARCHIVELOG DESTINATION

Starting restore at 05-JUN-16
using channel ORA_DISK_1

channel ORA_DISK_1: starting archived log restore to user-specified destination
archived log destination=+DATA
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=3
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=4
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=5
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=6
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=7
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=8
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=9
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=10
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=11
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=12
channel ORA_DISK_1: reading from backup piece /oradata/fra/ORCL/backupset/2016_06_05/o1_mf_annnn_TAG20160605T002604_co7khxd4_.bkp
channel ORA_DISK_1: piece handle=/oradata/fra/ORCL/backupset/2016_06_05/o1_mf_annnn_TAG20160605T002604_co7khxd4_.bkp tag=TAG20160605T002604
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:07
Finished restore at 05-JUN-16

Automáticamente ASM coloca los Achive Logs donde corresponde.

Y básicamente es eso, aunque en mi caso me toco restaurar un gran rompecabezas de Archives con el que tarde al menos medio día en completar todas las SEQUENCES que me hacían falta para finalmente recuperar mi base de datos, este script me fue de mucha ayuda.

Cada vez descubro nuevos scripts y funcionalidades de RMAN que ya estoy pensando en escribir una sección  “RMAN for dummies”.

Espero les sea de utilidad…

Comments

Popular posts from this blog

Ejemplo práctico con SQL Tuning Advisor y SQL Access Advisor

Guía rápida de uso de Oracle ASMLib