Hirsch
(usa Ubuntu)
Enviado em 13/09/2018 - 09:55h
Olá pessoal,
Alguém teria como me ajudar, possuo um servidor de documentos no Ubuntu, tenho um script de backup diário, porém gostaria de programar esse script para realizar a 00h00 sozinho.
Alguém teria uma idéia?
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#!/bin/bash
## /opt/backup.sh
# Pegando a data formatada do backup
DATA_BACKUP=`date +%d%m%y`
# Pegando a hora de inicio do backup
HORA_INICIO=`date +%H:%M:%S`
################## inicio backup #########################
cd /home/backup
######### marca data e hora do inicio do backup ##########
mkdir backup_sped_$(date +%d%m%Y)
chmod -R 777 backup_sped_$(date +%d%m%Y)
############## backup base LDAP ######################
##/etc/init.d/slapd stop
slapcat -l backup_ldap_$(date +%d%m%Y).ldif
/etc/init.d/slapd start
mv *.ldif backup_sped_$(date +%d%m%Y)
######################################################
################## backup aplicacao ####################
/etc/init.d/tomcat stop
cd /usr/local/tomcat/webapps
cp -r sped /home/backup/backup_sped_$(date +%d%m%Y)
# backup de arquivos de performance do sped
cp /etc/postgresql/8.3/main/postgresql.conf /home/backup/backup_sped_$(date +%d%m%Y)
cp /usr/local/tomcat/conf/server.xml /home/backup/backup_sped_$(date +%d%m%Y)
#######################################################
############# backup do banco de dados ################
#/etc/init.d/tomcat stop
# faz o dump do banco de dados
su - postgres -c "pg_dump -E UTF8 spedDB > /home/backup/backup_sped_$(date +%d%m%Y)/backup_SPED_$(date +%d%m%Y).sql"
/etc/init.d/tomcat start
################# compactacao e remocao de arquivos desnecessarios #####################
cd /home/backup/backup_sped_$(date +%d%m%Y)
# hora do fim do dump do banco - neste ponto o sped volta a funcionar
# faz a compactacao do arquivo sql gerado do banco de dados
tar -cjf backup_banco_$(date +%d%m%Y).tar.bz2 backup_SPED_$(date +%d%m%Y).sql
# depois de compactado remove o arquivo original
rm backup_SPED_$(date +%d%m%Y).sql
#echo Fim_Primeira_Compactacao_`date +%H:%M:%S`
cd /home/backup/
# faz a compactacao de toda a pasta gerada durante o backup
tar -cjf backup_sped_$(date +%d%m%Y).tar.bz2 backup_sped_$(date +%d%m%Y)
#echo Fim_Segunda_Compactacao_`date +%H:%M:%S`
# remove a pasta dos arquivos originais
rm -rf backup_sped_$(date +%d%m%Y)
#echo Fim_do_Backup_`date +%H:%M:%S`
########################## copia o backup para a o backup remoto #############################
cd /home/backup
# copia para o diretorio do backup remoto
cp backup_sped_$(date +%d%m%Y).tar.bz2 /home/backup/sped
# hora do termino geral incluindo a copia para o backup remoto
HORA_TERMINO_COPIA=`date +%H:%M:%S`
###################### Apaga Backup com mais de 20 dias do backup local #######################################
find backup_sped_* -ctime +19 | xargs rm -rf
###################### Apaga Backup com mais de 02 dias do backup remoto ######################################
cd /home/backup/sped
find backup_sped_* -ctime +01 | xargs rm -rf
################### Efetua rotina do CDS para inicialização do SPED ###########################################
sleep 10
date -s '2013-01-01'
sleep 20
/etc/init.d/tomcat start
sleep 50
ntpdate ntp.1cta.eb.mil.br
#eof