Efetuando um Restore/Recover após perda de um Datafile.
Posted by Emerson on 09:02 with 2 comments
Olá pessoal!
No post anterior mostramos como fazer backup do seu banco de dados em modo archivelog implementado num script.
Hoje iremos mostrar uma simulação de falha simples e utilizando o backup para fazer um restore com os arquivos de backup feitos anteriormente.
Simulação de Falha
Problema:
Supondo que houve uma "queda de Energia brusca as 4:00 da manhã", e o SO ao reiniciar o banco de dados informando que houve perda ou corrupção de um datafile.
1. Primeiro passo e verificar que você tenha um backup válido!
Com RMAN é possível fazer validação do seu backup, é uma das vantagens de usar ferramenta nativa.
RMAN> list backup summary;
List of Backups
===============
Key TY LV S Device Type Completion Time #Pieces #Copies Compressed Tag
------- -- -- - ----------- --------------- ------- ------- ---------- ---
39 B 0 A DISK 02-DEC-11 1 1 NO HOT_DB_BK_LEVEL0
40 B 0 A DISK 02-DEC-11 1 1 NO HOT_DB_BK_LEVEL0
41 B 0 A DISK 02-DEC-11 1 1 NO HOT_DB_BK_LEVEL0
42 B 0 A DISK 02-DEC-11 1 1 NO HOT_DB_BK_LEVEL0
43 B 0 A DISK 02-DEC-11 1 1 NO HOT_DB_BK_LEVEL0
44 B A A DISK 02-DEC-11 1 1 NO HOT_BKP_ARCHIVES
45 B A A DISK 02-DEC-11 1 1 NO HOT_BKP_ARCHIVES
46 B F A DISK 02-DEC-11 1 1 NO HOT_BKP_CONTROLFILE
Validando o backup através do RMAN:
RMAN> backup validate database archivelog all;
Starting backup at 02-DEC-11
using channel ORA_DISK_1
specification does not match any archived log in the repository
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=/u01/app/oracle/oradata/DB11G/system01.dbf
input datafile file number=00002 name=/u01/app/oracle/oradata/DB11G/sysaux01.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/DB11G/
USER01.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/DB11G/undotbs01.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/DB11G/users01.dbf
channel ORA_DISK_1: backup set complete, elapsed time: 00:02:06
List of Datafiles
=================
File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
1 OK 0 14499 90882 2140858
File Name: /u01/app/oracle/oradata/DB11G/system01.dbf
Block Type Blocks Failing Blocks Processed
---------- -------------- ----------------
Data 0 60583
Index 0 13131
Other 0 2667
File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
2 OK 0 20061 87082 2140874
File Name: /u01/app/oracle/oradata/DB11G/sysaux01.dbf
Block Type Blocks Failing Blocks Processed
---------- -------------- ----------------
Data 0 22200
Index 0 17847
Other 0 26932
File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
3 OK 0 1 58881 2140874
File Name: /u01/app/oracle/oradata/DB11G/undotbs01.dbf
Block Type Blocks Failing Blocks Processed
---------- -------------- ----------------
Data 0 0
Index 0 0
Other 0 58879
File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
4 OK 0 805 11040 1161539
File Name: /u01/app/oracle/oradata/DB11G/users01.dbf
Block Type Blocks Failing Blocks Processed
---------- -------------- ----------------
Data 0 9940
Index 0 2
Other 0 293
File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
5 OK 0 3713 72089 2062124
File Name: /u01/app/oracle/oradata/DB11G/
USER01.dbf
Block Type Blocks Failing Blocks Processed
---------- -------------- ----------------
Data 0 52337
Index 0 12486
Other 0 3552
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
including current SPFILE in backup set
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
List of Control File and SPFILE
===============================
File Type Status Blocks Failing Blocks Examined
------------ ------ -------------- ---------------
SPFILE OK 0 2
Control File OK 0 612
Finished backup at 02-DEC-11
RMAN>
Podemos observar que em STATUS todos encontram-se OK!
2. Determinar a localização e o nome de um arquivo de dados para renomear ou excluir, nesse caso vamos renomear.
[oracle@oralinux DB11G]$ pwd
/u01/app/oracle/oradata/DB11G
[oracle@oralinux DB11G]$ ls -lah
total 2,8G
drwxr-x--- 2 oracle oinstall 4,0K Nov 26 14:03 .
drwxr-x--- 3 oracle oinstall 4,0K Nov 21 19:42 ..
-rw-r----- 1 oracle oinstall 9,6M Dez 2 13:57 control01.ctl
-rw-r----- 1 oracle oinstall 51M Dez 2 13:57 redo01.log
-rw-r----- 1 oracle oinstall 51M Dez 2 13:43 redo02.log
-rw-r----- 1 oracle oinstall 51M Dez 2 13:43 redo03.log
-rw-r----- 1 oracle oinstall 681M Dez 2 13:57 sysaux01.dbf
-rw-r----- 1 oracle oinstall 711M Dez 2 13:57 system01.dbf
-rw-r----- 1 oracle oinstall 33M Dez 2 13:21 temp01.dbf
-rw-r----- 1 oracle oinstall 461M Dez 2 13:57 undotbs01.dbf
-rw-r----- 1 oracle oinstall 564M Dez 2 13:57 ?USER01.dbf
-rw-r----- 1 oracle oinstall 87M Dez 2 13:57 users01.dbf
[oracle@oralinux DB11G]$
3. Parar o banco de dados.
[oracle@oralinux scripts]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Fri Dec 2 13:55:42 2011
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL>
4. Renomear um arquivo de dados no nível do OS (simula a falha de mídia).
[oracle@oralinux DB11G]$ mv users01.dbf users01.bkp
5. Tentativa de iniciar o banco de dados.
Antes de simular uma falha de mídia, verifique se você está em um ambiente não-críticos banco de dados teste.
[oracle@oralinux DB11G]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Fri Dec 2 14:42:04 2011
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup
ORACLE instance started.
Total System Global Area 422670336 bytes
Fixed Size 1336960 bytes
Variable Size 322963840 bytes
Database Buffers 92274688 bytes
Redo Buffers 6094848 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 4 - see DBWR trace file
ORA-01110: data file 4: '/u01/app/oracle/oradata/DB11G/users01.dbf'
SQL>
6 - Conectar o banco de dados e colocar em Modo Mount.
[oracle@oralinux scripts]$ rman target /
Recovery Manager: Release 11.2.0.1.0 - Production on Fri Dec 2 15:39:30 2011
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
connected to target database (not started)
RMAN> startup mount;
Oracle instance started
database mounted
Total System Global Area 422670336 bytes
Fixed Size 1336960 bytes
Variable Size 322963840 bytes
Database Buffers 92274688 bytes
Redo Buffers 6094848 bytes
RMAN>
7 - Efetuando o restore
RMAN> restore database;
Starting restore at 02-DEC-11
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=18 device type=DISK
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/DB11G/users01.dbf
channel ORA_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/DB11G/
USER01.dbf
channel ORA_DISK_1: reading from backup piece /u03/rman/bkdb_47_1_768836470
channel ORA_DISK_1: piece handle=/u03/rman/bkdb_47_1_768836470 tag=HOT_DB_BK_LEVEL0
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:36
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/DB11G/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/DB11G/undotbs01.dbf
channel ORA_DISK_1: reading from backup piece /u03/rman/bkdb_45_1_768836470
channel ORA_DISK_1: piece handle=/u03/rman/bkdb_45_1_768836470 tag=HOT_DB_BK_LEVEL0
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:56
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to /u01/app/oracle/oradata/DB11G/system01.dbf
channel ORA_DISK_1: reading from backup piece /u03/rman/bkdb_46_1_768836470
channel ORA_DISK_1: piece handle=/u03/rman/bkdb_46_1_768836470 tag=HOT_DB_BK_LEVEL0
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:35
Finished restore at 02-DEC-11
8 - Efetuando o Recover
RMAN> recover database;
Starting recover at 02-DEC-11
using channel ORA_DISK_1
starting media recovery
media recovery complete, elapsed time: 00:00:04
Finished recover at 02-DEC-11
9 - Abrindo o Banco de Dados
RMAN> alter database open;
database opened
Pronto! O banco de dados encontra-se aberto e pronto para uso.
10 - Listando o Datafile recuperado no diretório:
[oracle@oralinux DB11G]$ ls -lah
total 2,8G
drwxr-x--- 2 oracle oinstall 4,0K Dez 2 15:41 .
drwxr-x--- 3 oracle oinstall 4,0K Nov 21 19:42 ..
-rw-r----- 1 oracle oinstall 9,6M Dez 2 16:11 control01.ctl
-rw-r----- 1 oracle oinstall 51M Dez 2 16:11 redo01.log
-rw-r----- 1 oracle oinstall 51M Dez 2 15:56 redo02.log
-rw-r----- 1 oracle oinstall 51M Dez 2 15:56 redo03.log
-rw-r----- 1 oracle oinstall 681M Dez 2 16:10 sysaux01.dbf
-rw-r----- 1 oracle oinstall 711M Dez 2 16:07 system01.dbf
-rw-r----- 1 oracle oinstall 33M Dez 2 16:00 temp01.dbf
-rw-r----- 1 oracle oinstall 461M Dez 2 16:10 undotbs01.dbf
-rw-r----- 1 oracle oinstall 564M Dez 2 15:56 ?USER01.dbf
-rw-r----- 1 oracle oinstall 87M Dez 2 13:57 users01.bkp
-rw-r----- 1 oracle oinstall 87M Dez 2 15:56 users01.dbf
[oracle@oralinux DB11G]$
Observem que após o restore o backup copiou novamente o datafile renomeado anteriormente.Possibilitando o banco de dados ser usado novamente em pouco tempo.
"Lembrando que Recover é quem garante o teu emprego!"
Como falei anteriormente o RMAN é uma ferramenta poderosíssima que nos permite fazer backup, restore, recover, standby,etc. Porém é necessário testar, validar e documentar seus backups!Os problemas externos as vezes são inevitáveis porém uma boa Estratégia de Backup não te deixará nunca na mão.
É isso pessoal!
Obrigado a todos!
Emerson
DBA Jr.
Categories: RMAN
Olá Emerson, muito bom o artigo, mas o ápice foi: "Lembrando que Recover é quem garante o teu emprego!"
ResponderExcluirLegal!!!! :)
Posso colocar essa frase no meu livro sobre BD, claro citando o autor ?
Att. O Peregrino
Valeu irmão.Claro que pode..Não lembro onde vi essa frase mas vou procurar.E te informo.
ResponderExcluirAbraços!!