Boa tarde,
Às vezes, mesmo com backup online via RMAN, alguns clientes solicitam um backup offline de alguns bancos de dados.
Abaixo temos um script shell de backup, bem simples que copia todos os arquivos de banco para uma uma máquina remota usando SCP. (Lembre-se de criar autenticação via chave ssh entre as máquinas para não pedir senha no scp).
######################################################################
#!/bin/bash
# Author : Rodrigo Mufalani (rodrigo@mufalani.com)
# Date : Jan 15th, 2011
# From : Mufalani S/A
# To :
# Purpose : Cold backup
######################################################################
# Note : Remember to set your env variables accordingly. !!!This script down the database!!!
######################################################################
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/9.2.0
export PATH=$ORACLE_HOME/bin:$PATH
export ORACLE_SID=orcl
export ORACLE_TERM=vt100
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH
export NLS_LANG=AMERICAN_AMERICA.WE8ISO8859P1
export PATH=$PATH:$ORACLE_HOME/bin
umask 022
sqlplus -s “/as sysdba” <<EOF
set trimspool on
set pages 0
set lin 1000
set feedback off
spool scp.sh
select
‘scp ‘||name||’ oracle@bkp_host:/home/oracle/cold/’
from
v$datafile df
union
select
‘scp ‘||name||’ oracle@bkp_host:/home/oracle/cold/’
from
v$tempfile tf
union
select
‘scp ‘||member||’ oracle@bkp_host:/home/oracle/cold/’
from
v$logfile lf
union
select
‘scp ‘||name||’ oracle@bkp_host:/home/oracle/cold/’
from
v$controlfile cf;
spool off;
shutdown immediate;
! sh scp.sh
startup
EOF
######################################################################
# *** END SCRIPT ***
######################################################################
Att,
Rodrigo Mufalani
Obs.: Shell script é uma linguagem muito flexível e poderosa, podemos por exemplo incluir rotinas de controle para não executar um segundo backup se o mesmo estiver em execução envio de e-mail ao final da rotina e etc.