Páginas

sexta-feira, 18 de outubro de 2013

[ORACLE] - Backup do Rman para Linux

Script para efetuar backup do Rman no Linux:

#!/bin/bash

export ORACLE_SID=orateste
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1
export DTHMS=$(date +"%Y%m%d%H%M%S")
export ORACLE_BACKUP=/backup/bkp_rman

#
# Dir backup
destino=$ORACLE_BACKUP

# Variavel para contar o numero de backups
contador=`cat $destino/contador`

#Quantidade de dias para manter
qtde=3
incluir=$(($contador+1))
excluir=$(($contador-$qtde))

# Incrementa Variavel do Contador
/bin/echo $incluir > $destino/contador

# Cria o novo diretorio
arquivoincluir=$DTHMS"_"$incluir
/bin/mkdir -p $destino/$arquivoincluir

#
# Script RMAN
#
echo run { > $destino/backup_RMAN.rman
echo CONFIGURE RETENTION POLICY TO REDUNDANCY 1';' >> $destino/backup_RMAN.rman
echo CONFIGURE CONTROLFILE AUTOBACKUP ON';' >> $destino/backup_RMAN.rman
echo CONFIGURE BACKUP OPTIMIZATION ON';' >> $destino/backup_RMAN.rman
echo CONFIGURE ARCHIVELOG DELETION POLICY TO BACKED UP 1 TIMES TO DISK';' >> $destino/backup_RMAN.rman
echo CONFIGURE DEVICE TYPE DISK BACKUP TYPE TO COMPRESSED BACKUPSET PARALLELISM 1';' >> $destino/backup_RMAN.rman
echo CONFIGURE CHANNEL DEVICE TYPE DISK MAXPIECESIZE 4400M';'  >> $destino/backup_RMAN.rman
echo SET CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO "'""$ORACLE_BACKUP/$arquivoincluir/AUTO_%F.cf_spf""'"';' >> $destino/backup_RMAN.rman
echo backup format "'""$ORACLE_BACKUP/$arquivoincluir/db_%d_%s_%p.bus""'" database';'  >> $destino/backup_RMAN.rman
echo backup format "'""$ORACLE_BACKUP/$arquivoincluir/al_%d_%s_%p.bus""'" archivelog all delete all input';' >> $destino/backup_RMAN.rman
echo sql '"'"alter database backup controlfile to trace as ''$ORACLE_BACKUP/$arquivoincluir/TXT_"$ORACLE_SID"_CF.ctl''"'"'';'  >> $destino/backup_RMAN.rman
echo sql '"'"create pfile=''$ORACLE_BACKUP/$arquivoincluir/TXT_"$ORACLE_SID"_PF.ora'' from spfile"'"'';'  >> $destino/backup_RMAN.rman
echo }  >> $destino/backup_RMAN.rman
echo run {  >> $destino/backup_RMAN.rman
echo crosscheck archivelog all';' >> $destino/backup_RMAN.rman
echo crosscheck backup';' >> $destino/backup_RMAN.rman
echo delete noprompt expired backup';' >> $destino/backup_RMAN.rman
echo delete noprompt obsolete';'  >> $destino/backup_RMAN.rman
echo } >> $destino/backup_RMAN.rman
#
$ORACLE_HOME/bin/rman target / nocatalog @$destino/backup_RMAN.rman > $ORACLE_BACKUP/$arquivoincluir/BACKUP_LOG_"$ORACLE_SID"_$arquivoincluir.log

# Exclui o diretorio de backup antigo
cd $destino
arquivoexcluir=*_$excluir
rm -rf $arquivoexcluir

Nenhum comentário:

Postar um comentário