Enviado em 27/06/2014 - 11:02h
Bom dia,
find diretorioorigem/ -name *.csv -mtime +$CSV_LIMIT | tar --files-from - -cvzpf /diretriodestino/arquivo.tar.gz
#var
SHELL=/bin/sh
PATH=/sbin:/usr/sbin:/usr/bin:/bin
DIR=/var/boreal/cdr
BKPFILE=cdr-$(date +%W).tar.gz
CSV_LIMIT=7 #7 dias
BKP_LIMIT=56 #8 SEMANAS
LOG=/usr/local/boreal/bin/bkp/bkp-CDR.log
echo "------------INCICIANDO BACKUP------------" >> $LOG
echo `date +%Y-%m-%d` >> $LOG
for TNX in $(cat /usr/local/boreal/bin/bkp/tnx.txt)
do
#clear
DES=`echo $TNX | cut -f2 -d:`
A=`echo $TNX | cut -f3 -d:`
#localiza arquivos e compacta
echo "---$DES -$A---" >> $LOG
echo "Localizando arquivos antigos e compactando de $DIR/$DES" >> $LOG
find "$DIR"/"$DES" -name *.csv -mtime +$CSV_LIMIT | tar --files-from - -cvzpf "$DIR"/"$DES"/"$BKPFILE"
echo "Excluindo os arquivos antigos" >> $LOG
sleep 2
echo "Localizando e excluindo aqruivos de backup com mais de $BKP_LIMIT dias" >> $LOG
find "$DIR"/"$DES" -name cdr* -mtime +$BKP_LIMIT >> $LOG
find "$DIR"/"$DES" -name cdr* -mtime +$BKP_LIMIT -exec rm -rf {} \;
sleep 2
echo "Apagando arquivos .csv com mais de $CSV_LIMIT dias" >> $LOG
find "$DIR"/"$DES" -name *.csv -mtime +$CSV_LIMIT >> $LOG
find "$DIR"/"$DES" -name *.csv -mtime +$CSV_LIMIT -exec rm -rf {} \;
done
echo "----------------FIM BACKUP---------------" >> $LOG