Pular para o conteúdo

Como fazer um backup consistente utilizando o Controlfile como repositório

Como fazer um backup consistente

Neste manual, será mostrado o passo à passo de como realizar backup consistente utilizando o Controlfile como repositório e posteriormente, em outro artigo, mostraremos como restaurar este backup.

Primeiramente, vamos criar um usuário chamado teste e uma tabela chamada teste_rman no Banco de dados para este novo usuário e também vamos popular esta tabela.

— Conectando com o usuário do Banco de Dados

# su - oracle

— Criando e exportando a variável ORACLE_SID

$ export ORACLE_SID=orcl

— Conectando no Banco de Dados

$ sqlplus / as sysdba

SQL*Plus: Release 12.1.0.2.0 Production on Sun Jul 12 16:20:55 2015
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 

— Criando um usuário chamado “teste” no Banco de Dados

SQL> create user teste identified by teste;

User created.

— Aplicando os grants ao novo usuário

SQL> grant connect to teste;

Grant succeeded.

SQL> grant resource to teste;

Grant succeeded.

SQL> grant create table to teste;

Grant succeeded.

— Concedendo espaço à tablespace para o novo usuário

SQL>  alter user teste quota unlimited on users;

User altered.

— Conectando no Banco de Dados com o novo usuário

SQL> conn teste/teste;

Connected.

— Verificando com qual usuário estamos logados

SQL> show user;

USER is "TESTE"

— Criando uma nova tablela

SQL> create table teste_rman (col1 varchar2(10), col2 varchar2(10));

Table created.

— Populando a nova tablela

SQL> insert into teste_rman (col1,col2) values ('reg_1a', 'reg_1b');

1 row created.

SQL> insert into teste_rman (col1,col2) values ('reg_2a', 'reg_2b');

1 row created.

SQL> insert into teste_rman (col1,col2) values ('reg_3a', 'reg_3b');

1 row created.

— Verificando os registros da nova tabela

SQL> select * from teste_rman;

COL1       COL2
---------- ----------
reg_1a     reg_1b
reg_2a     reg_2b
reg_3a     reg_3b

— Desconectando do Banco de Dados

SQL> exit

Disconnected from Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

$

Ainda com o usuário de Banco de Dados e com a variável ORACLE_SID carregada, vamos realizar o backup full do Banco de Dados.

— Conectando ao RMAN sem utilizar um catalogo

$ rman target /

Recovery Manager: Release 12.1.0.2.0 - Production on Sun Jul 12 21:54:08 2015
Copyright (c) 1982, 2014, Oracle and/or its affiliates.  All rights reserved.

connected to target database: ORCL (DBID=1411380092)

— Listando os backups já realizados neste banco via RMAN

RMAN> list backup;

using target database control file instead of recovery catalog

specification does not match any backup in the repository

Obs: Não há nenhum backup ainda

— Tentando realizar o restore

RMAN> backup database;

Starting backup at 12-JUL-15
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=28 device type=DISK

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of backup command at 07/12/2015 21:54:45
RMAN-06149: cannot BACKUP DATABASE in NOARCHIVELOG mode

Obs: O RMAN está informando que o Banco de Dados está em modo NOARCHIVELOG, ou seja, o RMAN não pode garantir a consistência do backup uma vez que o Banco está aberto e não tem os archivelogs para garantir o recover do Banco de Dados “pos-restore”

— Saindo do RMAN

RMAN> exit

Recovery Manager complete.

Porém, conforme já avisado, este primeiro backup será realizado com o Banco de Dados offline, ou seja, em um estado consistente.

— Conectando ao Banco de Dados

$ sqlplus / as sysdba

SQL*Plus: Release 12.1.0.2.0 Production on Sun Jul 12 22:18:56 2015
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

— Comando executado para verificar o Database log mode

SQL> archive log list;

Database log mode              No Archive Mode
Automatic archival             Disabled
Archive destination            USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     4
Current log sequence           6

Obs: Verificamos que o Banco de Dados está em modo NOARCHIVE, nestas condições, o RMAN não autoriza que o usuário faça backup com o Banco aberto.

— Desconectando do Banco de Dados

SQL> exit

Disconnected from Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

— Conectando ao RMAN sem utilizar um catalogo

$ rman target /

Recovery Manager: Release 12.1.0.2.0 - Production on Sun Jul 12 22:19:22 2015
Copyright (c) 1982, 2014, Oracle and/or its affiliates.  All rights reserved.

connected to target database: ORCL (DBID=1411380092)

— Fazendo o shutdown do Banco de Dados

RMAN> shutdown immediate;
using target database control file instead of recovery catalog

database closed
database dismounted

Oracle instance shut down

— Tentando fazer o backup

RMAN> backup database;

Starting backup at 14-JUL-15

using target database control file instead of recovery catalog

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of backup command at 07/14/2015 01:49:29
RMAN-06403: could not obtain a fully authorized session
ORA-01034: ORACLE not available
ORA-27101: shared memory realm does not exist

Linux-x86_64 Error: 2: No such file or directory

Additional information: 3640
Additional information: 644371931

Obs: Não foi possível realizar o backup, pois o RMAN não identificou nenhuma estrutura de memória do Banco de Dados

— Inicializando o Banco de Dados em modo NOMOUNT

RMAN> startup nomount;

connected to target database (not started)

Oracle instance started

Total System Global Area     339738624 bytes
Fixed Size                     2924112 bytes
Variable Size                260047280 bytes
Database Buffers              71303168 bytes
Redo Buffers                   5464064 bytes

— Tentando fazer o backup

RMAN> backup database;

tarting backup at 12-JUL-15

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=22 device type=DISK

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of backup command at 07/12/2015 22:20:35
ORA-01507: database not mounted

Obs: O RMAN indicou que o Banco de Dados não está em modo MOUNT. Será no modo MOUNT, que ele ira fazer a leitura dos controlfiles, identificando assim, o os datafiles que serão copiados para dentro do backup, por isso, o banco deve estar no modo MOUNT.

— Alterando o modo do Banco de Dados de NOMOUNT para MOUNT

RMAN> alter database mount;

Statement processed

released channel: ORA_DISK_1

— Realizando o backup full do Banco de Dados

RMAN>  backup database;

Starting backup at 12-JUL-15
allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=22 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=00001 name=/u01/app/oracle/oradata/orcl/system01.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/orcl/sysaux01.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/orcl/undotbs01.dbf
input datafile file number=00006 name=/u01/app/oracle/oradata/orcl/users01.dbf

channel ORA_DISK_1: starting piece 1 at 12-JUL-15
channel ORA_DISK_1: finished piece 1 at 12-JUL-15

piece handle=/u01/app/oracle/fast_recovery_area/ORCL/backupset/2015_07_12/ o1_mf_nnndf_TAG20150712T222106_bt64n3nm_.bkp tag=TAG20150712T222106 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:02:25
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: starting piece 1 at 12-JUL-15
channel ORA_DISK_1: finished piece 1 at 12-JUL-15

piece handle=/u01/app/oracle/fast_recovery_area/ORCL/backupset/2015_07_12/o1_mf_ncsnf_TAG20150712T222106_bt64rrgf_.bkp tag=TAG20150712T222106 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03

Finished backup at 12-JUL-15

— Listando os backups que form realizados via RMAN

RMAN> list backup;

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

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
16      Full    1.20G      DISK        00:02:10     12-JUL-15

BP Key: 16   Status: AVAILABLE  Compressed: NO  Tag: TAG20150712T222106
Piece Name: /u01/app/oracle/fast_recovery_area/ORCL/backupset/2015_07_12/ o1_mf_nnndf_TAG20150712T222106_bt64n3nm_.bkp

  List of Datafiles in backup set 16

  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  1       Full 2138806    12-JUL-15 /u01/app/oracle/oradata/orcl/system01.dbf
  3       Full 2138806    12-JUL-15 /u01/app/oracle/oradata/orcl/sysaux01.dbf
  4       Full 2138806    12-JUL-15 /u01/app/oracle/oradata/orcl/undotbs01.dbf
  6       Full 2138806    12-JUL-15 /u01/app/oracle/oradata/orcl/users01.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
17      Full    9.64M      DISK        00:00:03     12-JUL-15
        BP Key: 17   Status: AVAILABLE  Compressed: NO  Tag: TAG20150712T222106

        Piece Name: /u01/app/oracle/fast_recovery_area/ORCL/backupset/2015_07_12/o1_mf_ncsnf_TAG20150712T222106_bt64rrgf_.bkp

  SPFILE Included: Modification time: 12-JUL-15

  SPFILE db_unique_name: ORCL

  Control File Included: Ckp SCN: 2138806      Ckp time: 12-JUL-15

— Alterando o modo do Banco de Dados de MOUNT para OPEN

RMAN> alter database open;

Statement processed

— Desconectando do RMAN

RMAN> exit

Recovery Manager complete.

Pronto, backup realizado com sucesso. No próximo artigo, será realizado o restore deste Banco de Dados.

Quão útil foi este post ?

Clique em uma estrela para classificar o post

nota média 5 / 5. Contagem de votos: 18

Sem votos ! Seja o primeiro a classificar !

Deixe um comentário

O seu endereço de e-mail não será publicado. Campos obrigatórios são marcados com *

plugins premium WordPress