Temos no RMAN uma opção interessante de catalogar certos tipos de arquivos, para que o mesmo tenha ciência da existência desses arquivos e suas localizações, permitindo assim que possa os utilizar em algum caso de restauração ou solicitação de informações (via LIST, por exemplo). Os 4 tipos de artefatos aceitos para essa operação são: CONTROLFILECOPY, DATAFILECOPY, BACKUPPIECE e ARCHIVELOG. Algumas situações que podem necessitar do catalog seria alteração do local onde os arquivos ficam (seja file system ou DiskGroup), alteração do archiving destination, backups que não estão mais na retenção do RMAN, ou arquivos de backup gerados por terceiros e que devem ser usados por nós para restauração. Neste artigo vamos explorar algumas opções do Catalog.
Realizando alguns backups no ambiente:
[oracle@oel8 ~]$ rman target /
Recovery Manager: Release 18.0.0.0.0 - Production on Tue Jun 8 04:40:56 2021
Version 18.13.0.0.0
Copyright (c) 1982, 2018, Oracle and/or its affiliates. All rights reserved.
connected to target database: RMANDB (DBID=3825250984)
RMAN> CONFIGURE CONTROLFILE AUTOBACKUP OFF;
using target database control file instead of recovery catalog
new RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP OFF;
new RMAN configuration parameters are successfully stored
RMAN> BACKUP AS BACKUPSET TABLESPACE users TAG 'USERS_BS';
Starting backup at 2021-06-08:04:41:07
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=103 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00007 name=/oracle/dados/RMANDB/datafile/o1_mf_users_h8nyrkn7_.dbf
channel ORA_DISK_1: starting piece 1 at 2021-06-08:04:41:07
channel ORA_DISK_1: finished piece 1 at 2021-06-08:04:41:10
piece handle=/oracle/fra/RMANDB/backupset/2021_06_08/o1_mf_nnndf_USERS_BS_jcy7rmz4_.bkp tag=USERS_BS comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
Finished backup at 2021-06-08:04:41:10
RMAN> BACKUP AS COPY TABLESPACE users TAG 'USERS_DF';
Starting backup at 2021-06-08:04:41:18
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
input datafile file number=00007 name=/oracle/dados/RMANDB/datafile/o1_mf_users_h8nyrkn7_.dbf
output file name=/oracle/fra/RMANDB/datafile/o1_mf_users_jcy7ryy0_.dbf tag=USERS_DF RECID=44 STAMP=1074660079
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 2021-06-08:04:41:19
RMAN> BACKUP AS BACKUPSET ARCHIVELOG ALL TAG 'ARC_BS';
Starting backup at 2021-06-08:04:41:26
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=68 RECID=75 STAMP=1069389781
input archived log thread=1 sequence=69 RECID=77 STAMP=1069390191
input archived log thread=1 sequence=70 RECID=78 STAMP=1069391841
input archived log thread=1 sequence=71 RECID=79 STAMP=1069392032
input archived log thread=1 sequence=72 RECID=80 STAMP=1069392053
input archived log thread=1 sequence=73 RECID=83 STAMP=1069392224
input archived log thread=1 sequence=74 RECID=84 STAMP=1069392226
input archived log thread=1 sequence=75 RECID=85 STAMP=1069430460
input archived log thread=1 sequence=76 RECID=86 STAMP=1069567218
input archived log thread=1 sequence=77 RECID=87 STAMP=1069581356
input archived log thread=1 sequence=78 RECID=88 STAMP=1070953640
input archived log thread=1 sequence=79 RECID=89 STAMP=1070992854
input archived log thread=1 sequence=80 RECID=90 STAMP=1071054025
input archived log thread=1 sequence=81 RECID=91 STAMP=1071075652
input archived log thread=1 sequence=82 RECID=92 STAMP=1071117108
input archived log thread=1 sequence=83 RECID=93 STAMP=1071140420
input archived log thread=1 sequence=84 RECID=94 STAMP=1071180017
input archived log thread=1 sequence=85 RECID=95 STAMP=1071190844
input archived log thread=1 sequence=86 RECID=96 STAMP=1071205211
input archived log thread=1 sequence=87 RECID=97 STAMP=1071205218
input archived log thread=1 sequence=88 RECID=98 STAMP=1071219611
input archived log thread=1 sequence=89 RECID=99 STAMP=1071376111
input archived log thread=1 sequence=90 RECID=100 STAMP=1071381640
input archived log thread=1 sequence=91 RECID=101 STAMP=1071396592
input archived log thread=1 sequence=92 RECID=102 STAMP=1071411059
input archived log thread=1 sequence=93 RECID=103 STAMP=1071552261
input archived log thread=1 sequence=94 RECID=104 STAMP=1071553535
input archived log thread=1 sequence=95 RECID=105 STAMP=1071553599
input archived log thread=1 sequence=96 RECID=106 STAMP=1071553824
input archived log thread=1 sequence=97 RECID=107 STAMP=1071554229
input archived log thread=1 sequence=98 RECID=108 STAMP=1071590436
input archived log thread=1 sequence=99 RECID=109 STAMP=1071636084
input archived log thread=1 sequence=100 RECID=110 STAMP=1071811216
input archived log thread=1 sequence=101 RECID=111 STAMP=1073371215
input archived log thread=1 sequence=102 RECID=112 STAMP=1073372104
input archived log thread=1 sequence=103 RECID=113 STAMP=1073374794
input archived log thread=1 sequence=104 RECID=114 STAMP=1073404855
input archived log thread=1 sequence=105 RECID=115 STAMP=1074660088
channel ORA_DISK_1: starting piece 1 at 2021-06-08:04:41:30
channel ORA_DISK_1: finished piece 1 at 2021-06-08:04:42:45
piece handle=/oracle/fra/RMANDB/backupset/2021_06_08/o1_mf_annnn_ARC_BS_jcy7sbrx_.bkp tag=ARC_BS comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:15
Finished backup at 2021-06-08:04:42:45
RMAN> CONFIGURE CONTROLFILE AUTOBACKUP ON;
old RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP OFF;
new RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP ON;
new RMAN configuration parameters are successfully stored
Definindo um diretório alternativo onde moverei os arquivos de backup:
[oracle@oel8 BACKUP]$ pwd
/oracle/BACKUP
Recuperando os backuppieces gerados para movê-los de diretório:
RMAN> LIST BACKUPSET TAG 'USERS_BS';
using target database control file instead of recovery catalog
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
329 Full 13.25M DISK 00:00:01 2021-06-08:04:41:08
BP Key: 355 Status: AVAILABLE Compressed: NO Tag: USERS_BS
Piece Name: /oracle/fra/RMANDB/backupset/2021_06_08/o1_mf_nnndf_USERS_BS_jcy7rmz4_.bkp
List of Datafiles in backup set 329
File LV Type Ckp SCN Ckp Time Abs Fuz SCN Sparse Name
---- -- ---- ---------- ------------------- ----------- ------ ----
7 Full 2747657 2021-06-08:04:41:07 NO /oracle/dados/RMANDB/datafile/o1_mf_users_h8nyrkn7_.dbf
RMAN> LIST BACKUPSET TAG 'ARC_BS';
List of Backup Sets
===================
BS Key Size Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ -------------------
330 1.02G DISK 00:00:21 2021-06-08:04:41:51
BP Key: 356 Status: AVAILABLE Compressed: NO Tag: ARC_BS
Piece Name: /oracle/fra/RMANDB/backupset/2021_06_08/o1_mf_annnn_ARC_BS_jcy7sbrx_.bkp
List of Archived Logs in backup set 330
Thrd Seq Low SCN Low Time Next SCN Next Time
---- ------- ---------- ------------------- ---------- ---------
1 68 2255756 2021-03-28:10:39:58 2262113 2021-04-09:04:43:00
1 69 2262113 2021-04-09:04:43:00 2262505 2021-04-09:04:49:50
1 70 2262505 2021-04-09:04:49:50 2265296 2021-04-09:05:17:21
1 71 2265296 2021-04-09:05:17:21 2265473 2021-04-09:05:20:32
1 72 2265473 2021-04-09:05:20:32 2265531 2021-04-09:05:20:53
1 73 2265531 2021-04-09:05:20:53 2265643 2021-04-09:05:23:29
1 74 2265643 2021-04-09:05:23:29 2265663 2021-04-09:05:23:44
1 75 2265663 2021-04-09:05:23:44 2290054 2021-04-09:16:01:00
1 76 2290054 2021-04-09:16:01:00 2314554 2021-04-11:06:00:15
1 77 2314554 2021-04-11:06:00:15 2328698 2021-04-11:09:55:53
1 78 2328698 2021-04-11:09:55:53 2332924 2021-04-27:07:07:17
1 79 2332924 2021-04-27:07:07:17 2358174 2021-04-27:18:00:52
1 80 2358174 2021-04-27:18:00:52 2381091 2021-04-28:11:00:22
1 81 2381091 2021-04-28:11:00:22 2394102 2021-04-28:17:00:49
1 82 2394102 2021-04-28:17:00:49 2500292 2021-04-29:04:31:47
1 83 2500292 2021-04-29:04:31:47 2519661 2021-04-29:11:00:18
1 84 2519661 2021-04-29:11:00:18 2546021 2021-04-29:22:00:14
1 85 2546021 2021-04-29:22:00:14 2559326 2021-04-30:01:00:41
1 86 2559326 2021-04-30:01:00:41 2570072 2021-04-30:05:00:08
1 87 2570072 2021-04-30:05:00:08 2570544 2021-04-30:05:00:15
1 88 2570544 2021-04-30:05:00:15 2580734 2021-04-30:09:00:09
1 89 2580734 2021-04-30:09:00:09 2607950 2021-05-01:04:28:27
1 90 2607950 2021-05-01:04:28:27 2620519 2021-05-01:06:00:37
1 91 2620519 2021-05-01:06:00:37 2634806 2021-05-01:10:09:50
1 92 2634806 2021-05-01:10:09:50 2648651 2021-05-01:14:10:57
1 93 2648651 2021-05-01:14:10:57 2655511 2021-05-03:05:24:19
1 94 2655511 2021-05-03:05:24:19 2656517 2021-05-03:05:45:34
1 95 2656517 2021-05-03:05:45:34 2656617 2021-05-03:05:46:39
1 96 2656617 2021-05-03:05:46:39 2656827 2021-05-03:05:50:24
1 97 2656827 2021-05-03:05:50:24 2657118 2021-05-03:05:57:09
1 98 2657118 2021-05-03:05:57:09 2679421 2021-05-03:16:00:34
1 99 2679421 2021-05-03:16:00:34 2688357 2021-05-04:04:41:23
1 100 2688357 2021-05-04:04:41:23 2696947 2021-05-06:05:20:14
1 101 2696947 2021-05-06:05:20:14 2708591 2021-05-24:06:40:11
1 102 2708591 2021-05-24:06:40:11 2716825 2021-05-24:06:55:02
1 103 2716825 2021-05-24:06:55:02 2718910 2021-05-24:07:39:52
1 104 2718910 2021-05-24:07:39:52 2740096 2021-05-24:16:00:54
1 105 2740096 2021-05-24:16:00:54 2747712 2021-06-08:04:41:26
RMAN> HOST 'mv /oracle/fra/RMANDB/backupset/2021_06_08/o1_mf_nnndf_USERS_BS_jcy7rmz4_.bkp /oracle/BACKUP/o1_mf_nnndf_USERS_BS_jcy7rmz4_.bkp';
host command complete
RMAN> HOST 'mv /oracle/fra/RMANDB/backupset/2021_06_08/o1_mf_annnn_ARC_BS_jcy7sbrx_.bkp /oracle/BACKUP/o1_mf_annnn_ARC_BS_jcy7sbrx_.bkp';
host command complete
Fazendo o mesmo processo com o backup as image copy:
RMAN> LIST COPY TAG 'USERS_DF';
specification does not match any control file copy in the repository
List of Datafile Copies
=======================
Key File S Completion Time Ckp SCN Ckp Time Sparse
------- ---- - ------------------- ---------- ------------------- ------
44 7 A 2021-06-08:04:41:19 2747684 2021-06-08:04:41:18 NO
Name: /oracle/fra/RMANDB/datafile/o1_mf_users_jcy7ryy0_.dbf
Tag: USERS_DF
RMAN> HOST 'mv /oracle/fra/RMANDB/datafile/o1_mf_users_jcy7ryy0_.dbf /oracle/BACKUP/o1_mf_users_jcy7ryy0_.dbf';
host command complete
Checando o conteúdo do novo diretório:
[oracle@oel8 BACKUP]$ pwd
/oracle/BACKUP
[oracle@oel8 BACKUP]$ ll
total 1103440
-rw-r-----. 1 oracle oinstall 1098969600 Jun 8 04:41 o1_mf_annnn_ARC_BS_jcy7sbrx_.bkp
-rw-r-----. 1 oracle oinstall 13901824 Jun 8 04:41 o1_mf_nnndf_USERS_BS_jcy7rmz4_.bkp
-rw-r-----. 1 oracle oinstall 17047552 Jun 8 04:41 o1_mf_users_jcy7ryy0_.dbf
Realizando o Catalog de um backuppiece:
RMAN> CATALOG BACKUPPIECE '/oracle/BACKUP/o1_mf_nnndf_USERS_BS_jcy7rmz4_.bkp';
using target database control file instead of recovery catalog
cataloged backup piece
backup piece handle=/oracle/BACKUP/o1_mf_nnndf_USERS_BS_jcy7rmz4_.bkp RECID=357 STAMP=1074661035
Catalogando um Datafile Copy:
RMAN> CATALOG DATAFILECOPY '/oracle/BACKUP/o1_mf_users_jcy7ryy0_.dbf';
using target database control file instead of recovery catalog
cataloged datafile copy
datafile copy file name=/oracle/BACKUP/o1_mf_users_jcy7ryy0_.dbf RECID=45 STAMP=1074661118
Caso tenhamos um grande número de arquivos para serem catalogados, podemos realizar o processo considerando o diretório, conforme exemplo abaixo. Como 2 arquivos já haviam sido catalogados, o RMAN só pede autorização do terceiro. Caso não deseje que o RMAN fique confirmando os arquivos a serem catalogados, basta adicionar a opção NOPROMPT no comando:
RMAN> CATALOG START WITH '/oracle/BACKUP/';
searching for all files that match the pattern /oracle/BACKUP/
List of Files Unknown to the Database
=====================================
File Name: /oracle/BACKUP/o1_mf_annnn_ARC_BS_jcy7sbrx_.bkp
Do you really want to catalog the above files (enter YES or NO)? Y
cataloging files...
cataloging done
List of Cataloged Files
=======================
File Name: /oracle/BACKUP/o1_mf_annnn_ARC_BS_jcy7sbrx_.bkp
Agora copiar um dos backuppieces para dentro da FRA:
[oracle@oel8 BACKUP]$ ll
total 1103440
-rw-r-----. 1 oracle oinstall 1098969600 Jun 8 04:41 o1_mf_annnn_ARC_BS_jcy7sbrx_.bkp
-rw-r-----. 1 oracle oinstall 13901824 Jun 8 04:41 o1_mf_nnndf_USERS_BS_jcy7rmz4_.bkp
-rw-r-----. 1 oracle oinstall 17047552 Jun 8 04:41 o1_mf_users_jcy7ryy0_.dbf
[oracle@oel8 BACKUP]$ cp o1_mf_nnndf_USERS_BS_jcy7rmz4_.bkp /oracle/fra/RMANDB/
archivelog/ autobackup/ backupset/ controlfile/ datafile/ onlinelog/
[oracle@oel8 BACKUP]$ cp o1_mf_nnndf_USERS_BS_jcy7rmz4_.bkp /oracle/fra/RMANDB/o1_mf_nnndf_USERS_BS_jcy7rmz4_.bkp
[oracle@oel8 BACKUP]$
No momento do catalog, podemos pedir ao RMAN que realize o processo direto na FRA:
RMAN> CATALOG RECOVERY AREA;
using target database control file instead of recovery catalog
searching for all files in the recovery area
List of Files Unknown to the Database
=====================================
File Name: /oracle/fra/RMANDB/o1_mf_nnndf_USERS_BS_jcy7rmz4_.bkp
Do you really want to catalog the above files (enter YES or NO)? y
cataloging files...
cataloging done
List of Cataloged Files
=======================
File Name: /oracle/fra/RMANDB/o1_mf_nnndf_USERS_BS_jcy7rmz4_.bkp
Para finalizar, realizo uma cópia manual do archive (sequence 107) para nosso diretório alternativo e tento realizar o catalog ARCHIVELOG:
[oracle@oel8 archives]$ pwd
/oracle/archives
[oracle@oel8 archives]$ cp 1_107_1036964654.dbf /oracle/BACKUP/1_107_1036964654.dbf
[oracle@oel8 archives]$ rman target /
Recovery Manager: Release 18.0.0.0.0 - Production on Tue Jun 8 05:14:33 2021
Version 18.13.0.0.0
Copyright (c) 1982, 2018, Oracle and/or its affiliates. All rights reserved.
connected to target database: RMANDB (DBID=3825250984)
RMAN> CATALOG ARCHIVELOG '/oracle/BACKUP/1_107_1036964654.dbf';
using target database control file instead of recovery catalog
cataloged archived log
archived log file name=/oracle/BACKUP/1_107_1036964654.dbf RECID=118 STAMP=1074662083
Obs: Este procedimento foi criado pelo senhor Ahmed Baraka (www.ahmedbaraka.com) e foi apenas reproduzido por mim em um laboratório pessoal para fins de aprendizado.