Last active
September 4, 2016 17:51
-
-
Save rbarros/1f924bead783437841e8f37513f578a8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Identificação dos arquivos | |
IDENTIFICA=Backup | |
# Numero de dias do ciclo de backup | |
DIAS=7 | |
# E-mail do administrador | |
[email protected] | |
# Onde os arquivos de backup e logs ficarão armazenados | |
DIR_DESTINO=/var/backups | |
PATH_CONFIG=~/.saga | |
# Lista de arquivos a não serem backupeados | |
EXCLUDE=$PATH_CONFIG/exclude.list | |
# Arquivos temporário do script | |
TEMP=/tmp/.backup.$$ | |
# Arquivos de controle do GNU/Tar | |
INC=$PATH_CONFIG/incremental.conf | |
# Formato da data | |
DATA=$(date +%d-%m-%Y-%a) | |
# Arquivo com a lista de diretórios a serem backupeados | |
LISTA=$(cat $PATH_CONFIG/list.conf | grep ^\/ | sort | uniq) | |
# Arquivos gerado pelo script para controle de incremento | |
CONFIG=$PATH_CONFIG/backup.conf | |
VOLTA=0 | |
if [ ! -e $CONFIG ] ; then | |
touch $CONFIG | |
NUMERO=1 | |
else | |
cp -f $CONFIG $CONFIG.bak | |
LINHAS=$(cat $CONFIG | grep ^[0-9] | wc -l) | |
[ $LINHAS -eq $((DIAS+1)) ] && VOLTA=1 | |
FIRST=$(cat $CONFIG | grep ^[0-9]- | head -1) | |
LAST=$(cat $CONFIG | grep ^[0-9]- | tail -1) | |
OLD=$(echo $LAST | cut -f1 -d"-") | |
OLD=${OLD:-0} | |
BACKUP_OLD=$(echo $FIRST | cut -f1 -d"-") | |
FILE_OLD=$(echo $FIRST | cut -f- -d"-") | |
if [ $OLD -eq $DIAS ] ; then | |
NUMERO=1 | |
mv -f $INC $INC.bak | |
else | |
NUMERO=$((OLD+1)) | |
fi | |
fi | |
DESTINO=$DIR_DESTINO/$IDENTIFICA-$NUMERO-$DATA | |
SEND_MAIL () { | |
sendmail $ADMIN << FIMEMAIL | |
Subject: Backup CL $(date +%d-%m-%Y) | |
Backup realizado no arquivo: $DESTINO.tar.gz | |
FIMEMAIL | |
} | |
df -h > $DESTINO.log | |
tar --totals --ignore-failed-read --exclude-from=$EXCLUDE -zcvg $INC -f $DESTINO.tar.gz $LISTA >> $DESTINO.log 2>&1 | |
df -h >> $DESTINO.log | |
echo $NUMERO-$DATA >> $CONFIG | |
if [ $VOLTA -eq 1 ] ; then | |
rm -f $DIR_DESTINO/$IDENTIFICA-$FILE_OLD.tar.gz | |
rm -f $DIR_DESTINO/$IDENTIFICA-$FILE_OLD.log | |
sed 1d $CONFIG > $TEMP | |
mv -f $TEMP $CONFIG | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
sudo tar --listed-incremental=backup/www-public-arquivos.bkp \ | |
-czvf backup/www-public-arquivos.0.tar.gz \ | |
www/public/arquivos \ | |
--level=0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment