Categorias
Backup/Restore Databases Infra

Script de backup online do Oracle com RMAN

Para configurar o backup online de um banco Oracle através do uso do RMAN, eu uso o script abaixo:

#!/bin/bash
#
# Script de backup incremental do banco de dados Oracle, conforme indicado em:
#    "Oracle Database 2 Day DBA"
#    "Oracle Database Backup and Recovery User's Guide"
# Acrescentei o backup do init.ora e o backup trace do controlfile.
#
# Por Abrantes Araújo Silva Filho
#
# ANTES DE EXECUTAR A ROTINA DE BACKUP, configure o RMAN com os seguintes
# parâmetros (dependentes da versão do database e se enterprise ou standard): 
# (atenção com os PATHs também!):
#
# Oracle 12c (12.1.0.1.0) Standard Edition One: 
#   - CONFIGURE RETENTION POLICY TO REDUNDANCY 1; 
#   - CONFIGURE BACKUP OPTIMIZATION ON; 
#   - CONFIGURE DEFAULT DEVICE TYPE TO DISK; 
#   - CONFIGURE CONTROLFILE AUTOBACKUP ON; 
#   - CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/u09/fast_recovery_area/ORACLE1/controlfile_autobackup/%F'; 
#   - CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; 
#   - CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; 
#   - CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; 
#   - CONFIGURE MAXSETSIZE TO UNLIMITED; 
#   - CONFIGURE ENCRYPTION FOR DATABASE OFF; 
#   - CONFIGURE ENCRYPTION ALGORITHM 'AES128'; 
#   - CONFIGURE COMPRESSION ALGORITHM 'BASIC' AS OF RELEASE 'DEFAULT' OPTIMIZE FOR LOAD TRUE; 
#   - CONFIGURE RMAN OUTPUT TO KEEP FOR 7 DAYS; 
#   - CONFIGURE ARCHIVELOG DELETION POLICY TO BACKED UP 2 TIMES TO DISK; 
#   - CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/u09/fast_recovery_area/ORACLE1/controlfile_snapshot/snapcf_oracle.f';
#
# Depois de tudo pronto, crie um crontab para o usuário oracle:
#
# Endereço de e-mail do log do crontab:
#    MAILTO=abrantesasf@gmail.com
#
#
# Roda o backup incremental diário, 19:00h.
#    00 19 * * * /home/oracle/bin/backup_oracle.sh
#
#
# Não altere este script se não souber o que está fazendo!

# Variáveis de ambiente
#######################
export ORACLE_HOME=/u01/app/oracle/product/12.1.0.1.0/db export ORACLE_SID=oracle1 export PATH=$ORACLE_HOME/bin:$PATH 

# Roda RMAN 
###########
rman <<EOF connect target / RUN {  ALLOCATE CHANNEL disco_de_backup DEVICE TYPE DISK;
RECOVER COPY OF DATABASE WITH TAG backup_incremental_diario UNTIL TIME "SYSDATE-3";
BACKUP INCREMENTAL LEVEL 1 FOR RECOVER OF COPY WITH TAG backup_incremental_diario DATABASE PLUS ARCHIVELOG;
CROSSCHECK BACKUP;  DELETE NOPROMPT OBSOLETE; } exit EOF

# Cria backup do init.ora e backup trace do controlfile: ######################################################## 
# Backup do init.ora antigo: 
if [ -a /u09/fast_recovery_area/ORACLE1/outros/initoracle1.ora.bak ] ; then
  rm /u09/fast_recovery_area/ORACLE1/outros/initoracle1.ora.bak
  mv /u09/fast_recovery_area/ORACLE1/outros/initoracle1.ora /u09/fast_recovery_area/ORACLE1/outros/initoracle1.ora.bak
else if [ -a /u09/fast_recovery_area/ORACLE1/outros/initoracle1.ora ] ; then
  mv /u09/fast_recovery_area/ORACLE1/outros/initoracle1.ora /u09/fast_recovery_area/ORACLE1/outros/initoracle1.ora.bak
  fi
 fi

# Backup do controlfile antigo:
if [ -a /u09/fast_recovery_area/ORACLE1/outros/control_file.txt.bak ] ; then
  rm /u09/fast_recovery_area/ORACLE1/outros/control_file.txt.bak
  mv /u09/fast_recovery_area/ORACLE1/outros/control_file.txt /u09/fast_recovery_area/ORACLE1/outros/control_file.txt.bak
 else  if [ -a /u09/fast_recovery_area/ORACLE1/outros/control_file.txt ] ; then
  mv /u09/fast_recovery_area/ORACLE1/outros/control_file.txt /u09/fast_recovery_area/ORACLE1/outros/control_file.txt.bak
  fi
 fi

# Backup do init.ora novo e do controlfile novo:
sqlplus /nolog << EOF
connect / as sysdba
create pfile='/u09/fast_recovery_area/ORACLE1/outros/initoracle1.ora' from spfile='/u01/app/oracle/product/12.1.0.1.0/db/dbs/spfileoracle1.ora';
alter database backup controlfile to trace as '/u09/fast_recovery_area/ORACLE1/outros/control_file.txt';
exit
EOF

Se desejar, baixe o script e salve em um diretório que esteja no PATH e agende o crontab.

Deixe uma resposta

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