Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Backup OpenBase HOSPUB
#!/bin/bash
#
# Nao esquecer de colocar na cron do root as linhas abaixo:
# #!/bin/bash
# TERM=linux
##### Area das variaveis ################################################
# Declaro a varialvel EXEC com o nome dos executaveis
EXEC="SIADM SIADT SIALM SICEC SIFAR SIFIN SIGAE SIGHO SIGUE SIINF SIMAT SINAT SINUT SISRH SSAME HOSPUB ATIVA"
# Declaro a variavel ESQUEMAS com o nome dos esquemas
ESQUEMAS=$(cd /home/hospub/ && ls *.e)
############################################################################
##### Area de funcoes #######################################################
# Funcao que faz todo o backup
BackupHospub ()
{
# Root invoca usuario hospub para descarregar o banco
su hospub -c "bddesc -bbdint -s33 -natua -S -l"
# Loop que descarrega os outros bancos de dados
for i in BDTABEL BDFIN01 BDPES00 BDCON01 BDCOP01 BDPRO01 BDTABFAR01 BDFAR01 BDTABMAT01 BDMAT01 BDTABNUT01 BDNUT01
do
su hospub -c "bddesc -b$i -s1 -na -S -l"
done
# Loop que faz a copia dos executaveis e esquemas
for i in $(echo "$EXEC $ESQUEMAS")
do
su hospub -c "cp -fv ~/$i ."
done
# Compacta os arquivos descarregados (Somente os descarreados e nao os backups
# anteriores) renomeando com data e hora.
tar zcvf backuphospub-$(date +%Y%h%d-%Hh-%Mm).tar.gz *_S* $EXEC $ESQUEMAS
# Dar permissão total no arquivo
chmod 777 backuphospub*
# Remove o lixo
rm -f *_S* $(echo "$EXEC $ESQUEMAS")
}
##### Fim da area de funcoes #################################################
##### Inicio do programa ######################################################
# Vou para a pasta de backup do hospub
cd /home/hospub/backup
# Chamo a funcao de backup
BackupHospub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.